Compare commits

...

3 Commits

Author SHA1 Message Date
c4703eb5ba single 2022-09-02 13:46:28 +08:00
c8c60e693f 单例 2022-09-02 13:42:13 +08:00
f2aa5bdcf2 单例 2022-09-02 13:33:42 +08:00

17
main.js
View File

@ -331,6 +331,8 @@ let avatarCache = {};
let avatarPlaceholder = `${__dirname}/src/assets/images/user-fallback.png`; let avatarPlaceholder = `${__dirname}/src/assets/images/user-fallback.png`;
const icon = `${__dirname}/src/assets/images/dock.png`; const icon = `${__dirname}/src/assets/images/dock.png`;
async function getIcon(cookies, userid, src) { async function getIcon(cookies, userid, src) {
var cached = avatarCache[userid]; var cached = avatarCache[userid];
var icon; var icon;
@ -477,11 +479,20 @@ function createMenu() {
mainWindow.setMenu(menu); mainWindow.setMenu(menu);
} }
} }
// 实现单例,在启动第二个实例后,激活主窗口,然后退出第二个实例
const shouldQuit = app.makeSingleInstance(() => {
if (mainWindow) {
if (mainWindow.isMinimized()) mainWindow.restore()
mainWindow.focus()
}
})
shouldQuit && app.quit()
const createMainWindow = () => { const createMainWindow = () => {
var mainWindowState = windowStateKeeper({ var mainWindowState = windowStateKeeper({
defaultWidth: 745, defaultWidth: 1300,
defaultHeight: 450, defaultHeight: 700,
}); });
mainWindow = new BrowserWindow({ mainWindow = new BrowserWindow({
@ -703,7 +714,6 @@ const createMainWindow = () => {
mainWindow.webContents.setUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/603.3.8 (KHTML, like Gecko) Version/10.1.2 Safari/603.3.8'); mainWindow.webContents.setUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/603.3.8 (KHTML, like Gecko) Version/10.1.2 Safari/603.3.8');
createMenu(); createMenu();
}; };
app.setName(pkg.name); app.setName(pkg.name);
app.dock && app.dock.setIcon(icon); app.dock && app.dock.setIcon(icon);
@ -712,6 +722,7 @@ app.on('before-quit', () => {
// Fix issues #14 // Fix issues #14
forceQuit = true; forceQuit = true;
}); });
app.on('activate', e => { app.on('activate', e => {
if (!mainWindow.isVisible()) { if (!mainWindow.isVisible()) {
mainWindow.show(); mainWindow.show();