feat: review options tray and trayWindow
This commit is contained in:
1 parent
8ac82588c7
commit
bb0812349b
4 files changed
+19
-20
No files matched your search
@@ -1,8 +1,7 @@
|
||||
import { app, BrowserWindow, RenderProcessGoneDetails, BrowserWindowConstructorOptions } from 'electron'
|
||||
import Constants from './utils/Constants'
|
||||
import IPCs from './IPCs'
|
||||
import { createTray, setWindowAutoHide } from './tray.ts'
|
||||
import { moveToCurrentDesktop } from './desktop.ts'
|
||||
import { createTray, setWindowAutoHide, showWindow } from './tray.ts'
|
||||
|
||||
const options = {
|
||||
tray: true,
|
||||
@@ -13,8 +12,9 @@ const options = {
|
||||
menu: false,
|
||||
tooltip: 'Vutron App',
|
||||
margin: {x:0, y:0},
|
||||
width: Constants.IS_DEV_ENV ? 1500 : 1200,
|
||||
width: Constants.IS_DEV_ENV ? 800 : 600,
|
||||
height: 650,
|
||||
showAtStartup: false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ export const createMainWindow = async (): Promise<BrowserWindow> => {
|
||||
height: options.height,
|
||||
useContentSize: true,
|
||||
webPreferences: Constants.DEFAULT_WEB_PREFERENCES,
|
||||
frame: !options.trayWindow,
|
||||
frame: true
|
||||
}
|
||||
if (options.trayWindow){
|
||||
opt = {
|
||||
@@ -72,20 +72,20 @@ export const createMainWindow = async (): Promise<BrowserWindow> => {
|
||||
})
|
||||
|
||||
if (options.tray) {
|
||||
createTray(mainWindow, options.trayOptions);
|
||||
createTray(mainWindow, options.trayWindow, options.trayOptions);
|
||||
}
|
||||
|
||||
if (options.trayWindow) {
|
||||
setWindowAutoHide(mainWindow);
|
||||
// showWindow(mainWindow)
|
||||
if (options.trayOptions?.showAtStartup){
|
||||
showWindow(mainWindow)
|
||||
}
|
||||
}else{
|
||||
mainWindow.once('ready-to-show', (): void => {
|
||||
mainWindow.setAlwaysOnTop(true)
|
||||
mainWindow.show()
|
||||
mainWindow.focus()
|
||||
mainWindow.setAlwaysOnTop(false)
|
||||
|
||||
// moveToCurrentDesktop(mainWindow)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -18,12 +18,12 @@ app.on('ready', async () => {
|
||||
}
|
||||
*/
|
||||
|
||||
mainWindow = await createMainWindow(mainWindow)
|
||||
mainWindow = await createMainWindow()
|
||||
})
|
||||
|
||||
app.on('activate', async () => {
|
||||
if (!mainWindow) {
|
||||
mainWindow = await createMainWindow(mainWindow)
|
||||
mainWindow = await createMainWindow()
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
+7
-9
@@ -2,11 +2,6 @@ import { app, screen, Menu, Tray, BaseWindow, BrowserWindow } from 'electron'
|
||||
import Constants from './utils/Constants.ts'
|
||||
import { getDisplayNearestPoint } from './desktop.ts'
|
||||
|
||||
// defaults
|
||||
// const width = 800;
|
||||
// const height = 500;
|
||||
// const DEFAULT_MARGIN = {x: 0, y: 0} ;
|
||||
|
||||
let tray;
|
||||
let trayOptions;
|
||||
const DEFAULT_OPTIONS = {
|
||||
@@ -17,13 +12,14 @@ const DEFAULT_OPTIONS = {
|
||||
height: 650,
|
||||
}
|
||||
|
||||
export function createTray(window: BaseWindow, options) {
|
||||
export function createTray(window: BaseWindow, trayWindow: boolean, options) {
|
||||
trayOptions = options || DEFAULT_OPTIONS;
|
||||
trayOptions.trayWindow=trayWindow;
|
||||
tray = new Tray('buildAssets/icons/icon16.png');
|
||||
|
||||
tray.on('double-click', function (event) {
|
||||
toggleWindow(window)
|
||||
});
|
||||
// tray.on('double-click', function (event) {
|
||||
// toggleWindow(window)
|
||||
// });
|
||||
tray.on('right-click', function (event) {
|
||||
toggleWindow(window)
|
||||
});
|
||||
@@ -92,6 +88,8 @@ export function showWindow(window: BaseWindow) {
|
||||
}
|
||||
|
||||
export function alignWindow(window: BaseWindow) {
|
||||
if (!trayOptions.trayWindow) return;
|
||||
|
||||
const position = calculateWindowPosition();
|
||||
const b = window.getBounds()
|
||||
window.setBounds({
|
||||
|
||||
@@ -12,7 +12,8 @@ export default class Constants {
|
||||
|
||||
static IS_DEV_ENV = process.env.NODE_ENV === 'development'
|
||||
|
||||
// required IS_DEV_ENV
|
||||
// To show devtools at startup. It requires IS_DEV_ENV=true.
|
||||
// Note: For debugging purpose, window won't be closed if click elsewhere, if devtools is open.
|
||||
static IS_DEVTOOLS = true
|
||||
|
||||
static IS_MAC = process.platform === 'darwin'
|
||||
|
||||
Reference in new issue
Block a user