-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
219 lines (183 loc) · 5.33 KB
/
index.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
//TODO:
//Upgrade the installation with that inno program
//https://www.electronjs.org/docs/latest/tutorial/tutorial-packaging
const { app, BrowserWindow, Menu, Tray, ipcMain, nativeTheme } = require('electron')
// app.commandLine.appendSwitch('--disable-features=SameSiteByDefaultCookies')
// const EventEmitter = require('events')
const path = require('path')
var splash;
var win;
// const loadingEvents = new EventEmitter()
function createWindow () {
splash = new BrowserWindow({width: 350, height: 450, transparent: true, frame: false, alwaysOnTop: true, center: true, icon: __dirname + '/favicon.ico'});
splash.loadFile('images/wnsplash.png');
win = new BrowserWindow({
webPreferences: {
nodeIntegration: true,
worldSafeExecuteJavaScript: true,
contextIsolation: true,
preload: path.join(__dirname, "electronEvents.js")
},
titleBarStyle: 'hidden',
titleBarOverlay: {
color: '#1a1a1a',
symbolColor: '#c8c8c8',
height: 60
},
width: 946,
height: 633,
show: false,
backgroundColor: '#000',
icon: __dirname + '/favicon.ico'
})
// win.removeMenu()
win.loadFile('WriteNote/index.html')
win.once('ready-to-show', () => {
splash.destroy();
win.show();
});
}
app.whenReady().then(() => {
createWindow()
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
win.webContents.on('did-finish-load', function() {
win.webContents.executeJavaScript("isApp = true")
})
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit()
})
//Discord Rich Presence
require('dotenv').config()
const client = require('discord-rich-presence')(process.env.discordKey);
const timeLaunched = Date.now();
function discordStatus(text, subtext){
if(subtext){
client.updatePresence({
details: text,
largeImageKey: "writenotets",
state: subtext,
startTimestamp: timeLaunched,
instance: true
});
}
else{
client.updatePresence({
details: text,
largeImageKey: "writenotets",
instance: true
});
}
}
discordStatus("Looking at their library");
ipcMain.on('request-mainprocess-action', (event, arg) => {
discordStatus(arg.message, arg.message2);
});
//
//tray
var Registry = require('winreg');
async function isUsedSystemLightTheme() {
const reg = new Registry({
hive: Registry.HKCU,
key: '\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize',
});
return new Promise((resolve) => reg.get('SystemUsesLightTheme', (err, item) => {
if (!err) return resolve(item.value === '0x1');
resolve(false);
}));
}
let tray = null
app.whenReady().then(() => {
tray = new Tray(__dirname + '/images/wnTrayDark.png')
const contextMenu = Menu.buildFromTemplate([
{ label: 'Open', click: () => win.webContents.executeJavaScript('openSidepanel("open")') },
{ label: 'Save', click: () => win.webContents.executeJavaScript('SaveFile()') },
{ type: 'separator' },
{ label: 'About', click: () => win.webContents.executeJavaScript('showSettings("About")') },
{ type: 'separator' },
{ label: 'Exit', click: () => app.exit(0) },
// { Submenu examples
// label: 'Edit',
// submenu: [
// { role: 'undo' },
// { role: 'redo' },
// { type: 'separator' },
// { role: 'cut' },
// { role: 'copy' },
// { role: 'paste' },
// { role: 'selectAll' },
// { type: 'separator' },
// {
// label: 'Speech',
// submenu: [
// { role: 'startSpeaking' },
// { role: 'stopSpeaking' }
// ]
// }
// ]
// },
])
tray.setToolTip('WriteNote')
tray.setContextMenu(contextMenu)
tray.on('click', () => app.focus());
// app.on('balloon-click', () => { i genually don't know what this does or used to do
// tray.removeBalloon()
// })
function updateTrayIcon(isDarkTheme){
if(isDarkTheme==true){
tray.setImage(__dirname + '/images/wnTrayLight.png')
}
else{
tray.setImage(__dirname + '/images/wnTrayLight.png')
}
}
nativeTheme.on('updated', () => isUsedSystemLightTheme().then(function(result){
updateTrayIcon(result)
}))
isUsedSystemLightTheme().then(function(result){
updateTrayIcon(result)
})
})
//
//windos-taskbar
app.setUserTasks([
{
program: process.execPath,
arguments: '--new-window',
iconPath: process.execPath,
iconIndex: 0,
title: 'New Window',
description: 'Create a new window'
}
])
//
// Some miscellaneous code!
// app.whenReady().then(() => {
// const { Notification } = require("electron");
// const NOTIFICATION_TITLE = "You've started it up";
// const NOTIFICATION_BODY = "Welcome to your new text editor!";
// new Notification({
// title: NOTIFICATION_TITLE,
// body: NOTIFICATION_BODY,
// }).show();
// })
// app.whenReady().then(() => {
// const INCREMENT = 0.03
// const INTERVAL_DELAY = 100 // ms
// let c = 0
// progressInterval = setInterval(() => {
// // update progress bar to next value
// // values between 0 and 1 will show progress, >1 will show indeterminate or stick at 100%
// win.setProgressBar(c)
// // increment or reset progress bar
// if (c < 2) {
// c += INCREMENT
// } else {
// c = (-INCREMENT * 5) // reset to a bit less than 0 to show reset state
// }
// }, INTERVAL_DELAY)
// })