-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
executable file
·89 lines (81 loc) · 2.29 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* @Author: whf
* @Date: 2021-01-06 10:01:40
* @LastEditTime: 2021-01-14 15:35:27
* @FilePath: \AneuFiler\main.js
*/
const {app, BrowserWindow,globalShortcut} = require('electron')
const log = require('electron-log')
const path = require('path')
const url = require('url')
const ipc =require('electron').ipcMain
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow
function createWindow () {
// Create the browser window.
mainWindow = new BrowserWindow({
width: 680,
height: 410,
autoHideMenuBar: true,
frame: true,
transparent: false,
resizable: true,
alwaysOnTop: false, // [true] had bad experience on windows
webPreferences: {
nodeIntegration: true,
contextIsolation:false,//slove the alarm problem
enableRemoteModule:true //ensure renderer.js can be used normally require('electron').remote
}
})
// and load the index.html of the app.
mainWindow.loadFile('index.html')
// Open the DevTools.
// mainWindow.webContents.openDevTools()
// Emitted when the window is closed.
mainWindow.on('closed', function () { mainWindow = null })
}
let newwin =null;
ipc.on('tab3',()=>{
if(newwin){
newwin.show()
}else{
newwin =new BrowserWindow({
width:600,
height:300,
autoHideMenuBar:true,
frame:true,
transparent:false,
resizable:true,
x:1000,
y:300,
parent:mainWindow,
webPreferences:{
nodeIntegration:true,
contextIsolation:false,
enableRemoteModule:true
}
})
newwin.loadURL(path.join("file:",__dirname,'new.html'));
newwin.on('closed',()=>{
newwin=null
})
newwin.on('focus',()=>{
globalShortcut.register('CommandOrControl+F',function(){
if(newwin && newwin.webContents){
newwin.webContents.send('on-find','')
}
})
})
newwin.on('blur',()=>{
globalShortcut.unregister('CommandOrControl+F')
})
}
})
app.on('ready', function() { createWindow() })
// Quit when all windows are closed.
app.on('window-all-closed', function () {
app.quit()
globalShortcut.unregister('CommandOrControl+F')
})
app.on('activate', function () { if (mainWindow === null) createWindow() })