单例
This commit is contained in:
13
main.js
13
main.js
@@ -331,6 +331,8 @@ let avatarCache = {};
|
||||
let avatarPlaceholder = `${__dirname}/src/assets/images/user-fallback.png`;
|
||||
const icon = `${__dirname}/src/assets/images/dock.png`;
|
||||
|
||||
|
||||
|
||||
async function getIcon(cookies, userid, src) {
|
||||
var cached = avatarCache[userid];
|
||||
var icon;
|
||||
@@ -704,6 +706,16 @@ const createMainWindow = () => {
|
||||
createMenu();
|
||||
};
|
||||
|
||||
// 实现单例,在启动第二个实例后,激活主窗口,然后退出第二个实例
|
||||
const shouldQuit = app.makeSingleInstance(() => {
|
||||
if (mainWindow) {
|
||||
if (mainWindow.isMinimized()) mainWindow.restore()
|
||||
mainWindow.focus()
|
||||
}
|
||||
})
|
||||
|
||||
shouldQuit && app.quit()
|
||||
|
||||
app.setName(pkg.name);
|
||||
app.dock && app.dock.setIcon(icon);
|
||||
|
||||
@@ -712,6 +724,7 @@ app.on('before-quit', () => {
|
||||
// Fix issues #14
|
||||
forceQuit = true;
|
||||
});
|
||||
|
||||
app.on('activate', e => {
|
||||
if (!mainWindow.isVisible()) {
|
||||
mainWindow.show();
|
||||
|
||||
Reference in New Issue
Block a user