-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.js
163 lines (137 loc) · 3.59 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
const electron = require( 'electron' )
const app = electron.app
const BrowserWindow = electron.BrowserWindow
const Tray = electron.Tray
const Menu = electron.Menu
const settings = require( 'electron-settings' );
const path = require( 'path' )
const url = require( 'url' )
var mainWindow
var settingsWindow
var initWindow
var tray
const template = [ {
role: 'help',
submenu: [ {
label: 'Learn More',
click() {
//require( 'electron' ).shell.openExternal( 'https://electron.atom.io' )
}
}, {
role: 'toggledevtools'
} ]
}, {
label: 'Settings',
click: function( item, BrowserWindow ) {
createSettingsWindow();
},
}, {
label: 'Clear Message',
accelerator: "CmdOrCtrl+r",
click: function( item, BrowserWindow ) {
mainWindow.webContents.send( 'commentclear' );
}
}, {
label: 'Always-On-Top',
type: 'checkbox',
accelerator: "CmdOrCtrl+t",
checked: false,
click: function( item, BrowserWindow ) {
mainWindow.setAlwaysOnTop( item.checked );
}
}, {
label: 'Click-through',
type: 'checkbox',
accelerator: "CmdOrCtrl+f",
checked: false,
click: function( item, BrowserWindow ) {
mainWindow.setIgnoreMouseEvents( item.checked );
//console.log( `Active ${item.checked}` )
}
}, {
label: 'Initialization',
accelerator: "CmdOrCtrl+i",
click: function( item, BrowserWindow ) {
createInitWindow();
}
},
{
role: 'quit',
label: 'Quit App'
} ]
function createInitWindow() {
// Create the browser window.
initWindow = new BrowserWindow( {
width: 400,
height: 500,
frame: true,
resizable: false,
autoHideMenuBar: true,
} )
initWindow.loadURL( url.format( {
pathname: path.join( __dirname, 'public/core/init.html' ),
protocol: 'file:',
slashes: true
} ) )
initWindow.on( 'closed', function() {
initWindow = null
} )
}
function createSettingsWindow() {
settingsWindow = new BrowserWindow( {
width: 400,
height: 500,
frame: true,
resizable: false,
autoHideMenuBar: true,
} )
settingsWindow.loadURL( url.format( {
pathname: path.join( __dirname, 'public/core/settings.html' ),
protocol: 'file:',
slashes: true
} ) )
settingsWindow.on( 'closed', function() {
settingsWindow = null
} )
}
function createWindow() {
mainWindow = new BrowserWindow( {
width: 400,
height: 600,
transparent: true,
frame: false,
//webPreferences: {
//preload: path.join(__dirname, 'public/preload.js'),
//}
} )
mainWindow.setSkipTaskbar( true );
mainWindow.loadURL( url.format( {
pathname: path.join( __dirname, 'public/index.html' ),
protocol: 'file:',
slashes: true,
} ) )
mainWindow.on( 'closed', function() {
mainWindow = null
} )
tray = new Tray( path.join( __dirname, 'icon.ico' ) )
const contextMenu = Menu.buildFromTemplate( template )
Menu.setApplicationMenu( contextMenu )
tray.setContextMenu( contextMenu )
tray.on( 'click', function() {
mainWindow.show()
mainWindow.focus()
} )
}
app.on( 'ready', createWindow )
app.on( 'window-all-closed', function() {
//tray.displayBalloon({ content: 'Your App is Still Runing Here!' })
if ( process.platform !== 'darwin' ) {
app.quit()
}
} )
app.on( 'activate', function() {
if ( mainWindow === null ) {
createWindow()
}
} )
const Process = require( './process' )