-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
95 lines (85 loc) · 2.25 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
90
91
92
const { app, Menu, BrowserWindow, globalShortcut } = require('electron')
var opacity = 0.5;
const template = [
// { role: 'appMenu' }
{
label: '文件',
submenu: [
{
label: '关闭',
role: 'close'
}
]
},
{
label: '窗口',
submenu: [
{
label: '开发者模式',
role: 'toggledevtools'
},
]
},
]
const menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)
const mainRemote = require("@electron/remote/main")
const { setupTitlebar, attachTitlebarToWindow } = require("custom-electron-titlebar/main");
mainRemote.initialize()
const path = require('path')
setupTitlebar();
var mainWin = null
var status = 0; // 0 可配置 1 锁定
const createWindow = () => {
const win = new BrowserWindow({
width: 1600,
height: 900,
transparent: true,
titleBarStyle: 'hidden',
// alwaysOnTop: true,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
devTools: true,
sandbox: false,
preload: path.join(__dirname, 'assets', 'preload.js')
},
})
win.loadFile('index.html')
mainRemote.enable(win.webContents)
mainWin = win
// attach fullscreen(f11 and not 'maximized') && focus listeners
attachTitlebarToWindow(win);
}
const sendMsg = (type, data) => {
mainWin.webContents.send('asynchronous-reply', JSON.stringify({
type: type,
data: data
}))
}
app.whenReady().then(() => {
createWindow()
mainWin.webContents.devTools = true
globalShortcut.register('Ctrl+F1', function () {
if (status) {
mainWin.setAlwaysOnTop(false)
mainWin.setIgnoreMouseEvents(false)
mainWin.setOpacity(1)
status = 0
} else {
mainWin.setAlwaysOnTop(true)
mainWin.setIgnoreMouseEvents(true)
mainWin.setOpacity(opacity)
status = 1
}
sendMsg('changeStatus', status)
})
globalShortcut.register('Ctrl+Shift+=', function () {
if (opacity < 1) opacity += 0.1
if (status === 1) mainWin.setOpacity(opacity)
})
globalShortcut.register('Ctrl+Shift+-', function () {
if (opacity > 0) opacity -= 0.1
if (status === 1) mainWin.setOpacity(opacity)
})
})