-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a7ef15
commit 37a3504
Showing
37 changed files
with
900 additions
and
937 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,43 @@ | ||
export default class MainWindow { | ||
|
||
static _instance; | ||
static forceQuit = false; | ||
|
||
/** | ||
* | ||
* @param mainWindow {BrowserWindow} | ||
*/ | ||
static init(mainWindow) { | ||
if (this._instance) return | ||
this._instance = mainWindow | ||
mainWindow.on('close', (event) => { | ||
if (!this.forceQuit) { | ||
event.preventDefault(); | ||
if (mainWindow.isFullScreen()) { | ||
mainWindow.once('leave-full-screen', () => mainWindow.hide()) | ||
|
||
mainWindow.setFullScreen(false) | ||
} else { | ||
mainWindow.hide() | ||
} | ||
} | ||
}) | ||
} | ||
|
||
static show() { | ||
this._instance.isMinimized() ? this._instance.restore() : this._instance.show() | ||
} | ||
|
||
} | ||
export default class MainWindow { | ||
|
||
static _instance; | ||
static forceQuit = false; | ||
|
||
static getInstance(){ | ||
return this._instance | ||
} | ||
|
||
/** | ||
* | ||
* @param mainWindow {BrowserWindow} | ||
*/ | ||
static init(mainWindow) { | ||
if (this._instance) return | ||
this._instance = mainWindow | ||
mainWindow.on('close', (event) => { | ||
if (!this.forceQuit) { | ||
event.preventDefault(); | ||
if (mainWindow.isFullScreen()) { | ||
mainWindow.once('leave-full-screen', () => mainWindow.hide()) | ||
|
||
mainWindow.setFullScreen(false) | ||
} else { | ||
mainWindow.hide() | ||
} | ||
} | ||
}) | ||
|
||
mainWindow.on('maximize', () => { | ||
mainWindow.webContents.send('mainWindowMaximize') | ||
}) | ||
|
||
mainWindow.on('unmaximize', () => { | ||
mainWindow.webContents.send('mainWindowUnmaximize') | ||
}) | ||
} | ||
|
||
static show() { | ||
this._instance.isMinimized() ? this._instance.restore() : this._instance.show() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,54 @@ | ||
import { app, Tray, Menu, nativeImage } from 'electron' | ||
import { APP_NAME } from '@/shared/utils/constant' | ||
import { isMacOS, isWindows } from '@/main/utils/utils' | ||
import { t } from '@/main/utils/i18n' | ||
import Path from '@/main/utils/Path' | ||
import GetAppPath from '@/main/utils/GetAppPath' | ||
import MainWindow from '@/main/MainWindow' | ||
|
||
export default class TrayManage { | ||
static _instance | ||
|
||
static init() { | ||
if (this._instance) return | ||
let iconPath = this.getIconPath() | ||
let icon = nativeImage.createFromPath(iconPath).resize({ width: 18, height: 18 }) | ||
icon.setTemplateImage(true) | ||
let tray = new Tray(icon) | ||
const contextMenu = this.getContextMenu() | ||
tray.setToolTip(APP_NAME) | ||
tray.setContextMenu(contextMenu) | ||
if (isWindows) { | ||
tray.on('click', () => this.showMainWindow()) | ||
} | ||
this._instance = tray | ||
} | ||
|
||
static getContextMenu() { | ||
return Menu.buildFromTemplate([ | ||
{ | ||
label: t('Open'), | ||
click: () => this.showMainWindow() | ||
}, | ||
{ | ||
label: t('Exit'), | ||
click: () => app.quit() | ||
} | ||
]) | ||
} | ||
|
||
static showMainWindow() { | ||
MainWindow.show() | ||
} | ||
|
||
static updateContextMenu() { | ||
this._instance.setContextMenu(this.getContextMenu()) | ||
} | ||
|
||
static getIconPath() { | ||
if (isMacOS) { | ||
return Path.Join(GetAppPath.getStaticDir(), 'img/icons/icon-tray-Mac.png') | ||
} | ||
return Path.Join(GetAppPath.getStaticDir(), 'img/icons/icon-tray.png') | ||
} | ||
} | ||
import { app, Tray, Menu, nativeImage } from 'electron' | ||
import { APP_NAME } from '@/shared/utils/constant' | ||
import { isMacOS, isWindows } from '@/main/utils/utils' | ||
import { t } from '@/main/utils/i18n' | ||
import MainWindow from '@/main/MainWindow' | ||
import trayIcon from '@/../resources/img/icons/icon-tray.png?asset' | ||
import trayMacIcon from '@/../resources/img/icons/icon-tray-Mac.png?asset' | ||
|
||
export default class TrayManage { | ||
static _instance | ||
|
||
static init() { | ||
if (this._instance) return | ||
let iconPath = this.getIconPath() | ||
let icon = nativeImage.createFromPath(iconPath).resize({ width: 18, height: 18 }) | ||
icon.setTemplateImage(true) | ||
let tray = new Tray(icon) | ||
const contextMenu = this.getContextMenu() | ||
tray.setToolTip(APP_NAME) | ||
tray.setContextMenu(contextMenu) | ||
if (isWindows) { | ||
tray.on('click', () => this.showMainWindow()) | ||
} | ||
this._instance = tray | ||
} | ||
|
||
static getContextMenu() { | ||
return Menu.buildFromTemplate([ | ||
{ | ||
label: t('Open'), | ||
click: () => this.showMainWindow() | ||
}, | ||
{ | ||
label: t('Exit'), | ||
click: () => app.quit() | ||
} | ||
]) | ||
} | ||
|
||
static showMainWindow() { | ||
MainWindow.show() | ||
} | ||
|
||
static updateContextMenu() { | ||
this._instance.setContextMenu(this.getContextMenu()) | ||
} | ||
|
||
static getIconPath() { | ||
if (isMacOS) { | ||
return trayMacIcon | ||
} | ||
return trayIcon | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.