は、これは私がそれを行うだろうか簡単な例です。 mainWindow's
イベントを最小限に抑え、alwaysOnTop: true
で新しいBrowserWindow
を作成するために
待ち(電子クイックスタートで作成)。
ドキュメント:https://github.com/electron/electron/blob/master/docs/api/browser-window.md
index.htmlを
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Index</title>
</head>
<body>
Index
</body>
</html>
toolbar.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>toolbar</title>
</head>
<body>
toolbar
</body>
</html>
renderer.js
const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
const path = require('path');
const url = require('url');
let mainWindow = null;
let toolbarWindow = null;
const createWindow =() => {
// Create the browser window.
mainWindow = new BrowserWindow({
width: 800,
height: 600
});
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
}));
mainWindow.on('closed',() => {
mainWindow = null;
});
const onCloseMainWindow = (event) => {
toolbarWindow = new BrowserWindow({
width: 300,
x: 20,
y: 40,
height: 70,
resize: false,
type: 'toolbar',
alwaysOnTop: true
})
toolbarWindow.loadURL(url.format({
pathname: path.join(__dirname, 'toolbar.html'),
protocol: 'file:',
slashes: true
}));
toolbarWindow.on('minimize', (event) => {
if (mainWindow) {
mainWindow.show();
}
toolbarWindow.destroy();
});
};
mainWindow.on('minimize', onCloseMainWindow);
mainWindow.on('close', onCloseMainWindow);
};
app.on('ready', createWindow);
app.on('window-all-closed',() => {
if (process.platform !== 'darwin') {
app.quit();
}
})
app.on('activate',() => {
if (mainWindow === null) {
createWindow()
}
});
メインウィンドウが最小化されると、新しいBrowserWindowが作成されることがあります。あなたのツールバーの反応コンポーネントと 'alwaysOnTop'オプションを追加してください。 https://electron.atom.io/docs/api/browser-window/#winsetalwaysontopflag-level-relativelevel – Phil
編集:WindowsとLinuxでは 'type: 'toolbar''を使用できます – Phil