yangjie #47
64
main.js
64
main.js
|
|
@ -29,6 +29,7 @@ let regKey;
|
||||||
let connection = null;
|
let connection = null;
|
||||||
let envStr;
|
let envStr;
|
||||||
let startNumber = 0;
|
let startNumber = 0;
|
||||||
|
let isShare = true;
|
||||||
powerSaveBlocker.start('prevent-display-sleep')
|
powerSaveBlocker.start('prevent-display-sleep')
|
||||||
const id = powerSaveBlocker.start('prevent-display-sleep')
|
const id = powerSaveBlocker.start('prevent-display-sleep')
|
||||||
powerSaveBlocker.stop(id)
|
powerSaveBlocker.stop(id)
|
||||||
|
|
@ -66,33 +67,12 @@ class AppWindow extends BrowserWindow {
|
||||||
function quit() {
|
function quit() {
|
||||||
app.quit()
|
app.quit()
|
||||||
}
|
}
|
||||||
|
let tray;
|
||||||
function createTray() {
|
function createTray() {
|
||||||
const iconPath = `${__dirname}/src/assets/${updateJs.getIcon(envStr)}.png`;
|
const iconPath = `${__dirname}/src/assets/${updateJs.getIcon(envStr)}.png`;
|
||||||
const trayIcon = nativeImage.createFromPath(iconPath);
|
const trayIcon = nativeImage.createFromPath(iconPath);
|
||||||
const tray = new Tray(trayIcon);
|
tray = new Tray(trayIcon);
|
||||||
const contextMenu = Menu.buildFromTemplate([
|
|
||||||
{
|
|
||||||
label: '打开', click: () => {
|
|
||||||
mainWindow.webContents.send('isOpenWindows');
|
|
||||||
},
|
|
||||||
// icon: iconPath,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: '最小化到系统托盘', click: () => {
|
|
||||||
mainWindow.hide();
|
|
||||||
},
|
|
||||||
// icon: iconPath,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: '退出', click: async () => {
|
|
||||||
quit()
|
|
||||||
},
|
|
||||||
// icon: iconPath,
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
tray.setToolTip(updateJs.getTitle(envStr));
|
tray.setToolTip(updateJs.getTitle(envStr));
|
||||||
tray.setContextMenu(contextMenu);
|
|
||||||
tray.on('click', () => {
|
tray.on('click', () => {
|
||||||
mainWindow.webContents.send('isOpenWindows');
|
mainWindow.webContents.send('isOpenWindows');
|
||||||
});
|
});
|
||||||
|
|
@ -101,6 +81,13 @@ function createTray() {
|
||||||
function createWindow() {
|
function createWindow() {
|
||||||
mainWindow = new AppWindow();
|
mainWindow = new AppWindow();
|
||||||
mainWindow.focus();
|
mainWindow.focus();
|
||||||
|
mainWindow.hookWindowMessage(278, function (e) {
|
||||||
|
mainWindow.setEnabled(false);//窗口禁用
|
||||||
|
setTimeout(() => {
|
||||||
|
mainWindow.setEnabled(true);//窗口启用
|
||||||
|
}, 100);
|
||||||
|
return true;
|
||||||
|
})
|
||||||
}
|
}
|
||||||
const additionalData = { myKey: 'myValue' }
|
const additionalData = { myKey: 'myValue' }
|
||||||
app.on('ready', () => {
|
app.on('ready', () => {
|
||||||
|
|
@ -513,10 +500,34 @@ app.on('ready', () => {
|
||||||
// 设置桌面应用基础属性
|
// 设置桌面应用基础属性
|
||||||
ipcMain.handle('setMainWindowSize', (event, config) => {
|
ipcMain.handle('setMainWindowSize', (event, config) => {
|
||||||
if (config.width === 250) {
|
if (config.width === 250) {
|
||||||
|
const contextMenu = Menu.buildFromTemplate([
|
||||||
|
{
|
||||||
|
label: '退出',
|
||||||
|
click: () => quit(),
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
tray.setContextMenu(contextMenu);
|
||||||
mainWindow.setSkipTaskbar(true)
|
mainWindow.setSkipTaskbar(true)
|
||||||
mainWindow.setResizable(false)
|
mainWindow.setResizable(false)
|
||||||
mainWindow.setAlwaysOnTop(true, 'screen-saver')
|
mainWindow.setAlwaysOnTop(true, 'screen-saver')
|
||||||
|
} else {
|
||||||
|
const contextMenu = Menu.buildFromTemplate([
|
||||||
|
{
|
||||||
|
label: '打开',
|
||||||
|
click: () => mainWindow.webContents.send('isOpenWindows'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '最小化到系统托盘',
|
||||||
|
click: () => mainWindow.hide(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '退出',
|
||||||
|
click: () => quit(),
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
tray.setContextMenu(contextMenu);
|
||||||
}
|
}
|
||||||
|
console.log(isShare);
|
||||||
// 设置最小窗口尺寸
|
// 设置最小窗口尺寸
|
||||||
mainWindow.setMinimumSize(config.width, config.height);
|
mainWindow.setMinimumSize(config.width, config.height);
|
||||||
// 设置最大尺寸
|
// 设置最大尺寸
|
||||||
|
|
@ -580,6 +591,13 @@ app.on('ready', () => {
|
||||||
// 测试 | 生产
|
// 测试 | 生产
|
||||||
child.loadURL(`file://${path.join(__dirname, './dist/index.html')}#/${config.key}`);
|
child.loadURL(`file://${path.join(__dirname, './dist/index.html')}#/${config.key}`);
|
||||||
}
|
}
|
||||||
|
child.hookWindowMessage(278, function (e) {
|
||||||
|
child.setEnabled(false);//窗口禁用
|
||||||
|
setTimeout(() => {
|
||||||
|
child.setEnabled(true);//窗口启用
|
||||||
|
}, 100);
|
||||||
|
return true;
|
||||||
|
})
|
||||||
childWindow[config.key] = child
|
childWindow[config.key] = child
|
||||||
child.once('ready-to-show', () => {
|
child.once('ready-to-show', () => {
|
||||||
if (config.show) {
|
if (config.show) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue