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 { app, BrowserWindow, RenderProcessGoneDetails, BrowserWindowConstructorOptions } from 'electron'
|
||||||
import Constants from './utils/Constants'
|
import Constants from './utils/Constants'
|
||||||
import IPCs from './IPCs'
|
import IPCs from './IPCs'
|
||||||
import { createTray, setWindowAutoHide } from './tray.ts'
|
import { createTray, setWindowAutoHide, showWindow } from './tray.ts'
|
||||||
import { moveToCurrentDesktop } from './desktop.ts'
|
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
tray: true,
|
tray: true,
|
||||||
@@ -13,8 +12,9 @@ const options = {
|
|||||||
menu: false,
|
menu: false,
|
||||||
tooltip: 'Vutron App',
|
tooltip: 'Vutron App',
|
||||||
margin: {x:0, y:0},
|
margin: {x:0, y:0},
|
||||||
width: Constants.IS_DEV_ENV ? 1500 : 1200,
|
width: Constants.IS_DEV_ENV ? 800 : 600,
|
||||||
height: 650,
|
height: 650,
|
||||||
|
showAtStartup: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@ export const createMainWindow = async (): Promise<BrowserWindow> => {
|
|||||||
height: options.height,
|
height: options.height,
|
||||||
useContentSize: true,
|
useContentSize: true,
|
||||||
webPreferences: Constants.DEFAULT_WEB_PREFERENCES,
|
webPreferences: Constants.DEFAULT_WEB_PREFERENCES,
|
||||||
frame: !options.trayWindow,
|
frame: true
|
||||||
}
|
}
|
||||||
if (options.trayWindow){
|
if (options.trayWindow){
|
||||||
opt = {
|
opt = {
|
||||||
@@ -72,20 +72,20 @@ export const createMainWindow = async (): Promise<BrowserWindow> => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (options.tray) {
|
if (options.tray) {
|
||||||
createTray(mainWindow, options.trayOptions);
|
createTray(mainWindow, options.trayWindow, options.trayOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.trayWindow) {
|
if (options.trayWindow) {
|
||||||
setWindowAutoHide(mainWindow);
|
setWindowAutoHide(mainWindow);
|
||||||
// showWindow(mainWindow)
|
if (options.trayOptions?.showAtStartup){
|
||||||
|
showWindow(mainWindow)
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
mainWindow.once('ready-to-show', (): void => {
|
mainWindow.once('ready-to-show', (): void => {
|
||||||
mainWindow.setAlwaysOnTop(true)
|
mainWindow.setAlwaysOnTop(true)
|
||||||
mainWindow.show()
|
mainWindow.show()
|
||||||
mainWindow.focus()
|
mainWindow.focus()
|
||||||
mainWindow.setAlwaysOnTop(false)
|
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 () => {
|
app.on('activate', async () => {
|
||||||
if (!mainWindow) {
|
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 Constants from './utils/Constants.ts'
|
||||||
import { getDisplayNearestPoint } from './desktop.ts'
|
import { getDisplayNearestPoint } from './desktop.ts'
|
||||||
|
|
||||||
// defaults
|
|
||||||
// const width = 800;
|
|
||||||
// const height = 500;
|
|
||||||
// const DEFAULT_MARGIN = {x: 0, y: 0} ;
|
|
||||||
|
|
||||||
let tray;
|
let tray;
|
||||||
let trayOptions;
|
let trayOptions;
|
||||||
const DEFAULT_OPTIONS = {
|
const DEFAULT_OPTIONS = {
|
||||||
@@ -17,13 +12,14 @@ const DEFAULT_OPTIONS = {
|
|||||||
height: 650,
|
height: 650,
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createTray(window: BaseWindow, options) {
|
export function createTray(window: BaseWindow, trayWindow: boolean, options) {
|
||||||
trayOptions = options || DEFAULT_OPTIONS;
|
trayOptions = options || DEFAULT_OPTIONS;
|
||||||
|
trayOptions.trayWindow=trayWindow;
|
||||||
tray = new Tray('buildAssets/icons/icon16.png');
|
tray = new Tray('buildAssets/icons/icon16.png');
|
||||||
|
|
||||||
tray.on('double-click', function (event) {
|
// tray.on('double-click', function (event) {
|
||||||
toggleWindow(window)
|
// toggleWindow(window)
|
||||||
});
|
// });
|
||||||
tray.on('right-click', function (event) {
|
tray.on('right-click', function (event) {
|
||||||
toggleWindow(window)
|
toggleWindow(window)
|
||||||
});
|
});
|
||||||
@@ -92,6 +88,8 @@ export function showWindow(window: BaseWindow) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function alignWindow(window: BaseWindow) {
|
export function alignWindow(window: BaseWindow) {
|
||||||
|
if (!trayOptions.trayWindow) return;
|
||||||
|
|
||||||
const position = calculateWindowPosition();
|
const position = calculateWindowPosition();
|
||||||
const b = window.getBounds()
|
const b = window.getBounds()
|
||||||
window.setBounds({
|
window.setBounds({
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ export default class Constants {
|
|||||||
|
|
||||||
static IS_DEV_ENV = process.env.NODE_ENV === 'development'
|
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_DEVTOOLS = true
|
||||||
|
|
||||||
static IS_MAC = process.platform === 'darwin'
|
static IS_MAC = process.platform === 'darwin'
|
||||||
|
|||||||
Reference in new issue
Block a user