@fto-consult/expo-ui 7.5.35 → 7.5.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/index.js +5 -5
- package/electron/index.js +145 -145
- package/electron/init/main.js +1 -0
- package/package.json +1 -1
- package/electron/main-app/index copy 2.js +0 -557
- package/electron/main-app/index copy.js +0 -53
- package/electron/main-app/index.js +0 -557
@@ -1,557 +0,0 @@
|
|
1
|
-
const {app, BrowserWindow,Tray,Menu,MenuItem,globalShortcut,systemPreferences,powerMonitor,ipcMain,dialog, nativeTheme} = require('electron')
|
2
|
-
const session = require("../utils/session");
|
3
|
-
const path = require("path");
|
4
|
-
const fs = require("fs");
|
5
|
-
const isValidUrl = require("../utils/isValidUrl");
|
6
|
-
const debounce = require("../utils/debounce");
|
7
|
-
|
8
|
-
const isObj = x => x && typeof x =='object';
|
9
|
-
|
10
|
-
const mainProcessRef = {current:{}};
|
11
|
-
|
12
|
-
// fermee automatiquement quand l'objet JavaScript sera garbage collected.
|
13
|
-
let win = undefined;
|
14
|
-
|
15
|
-
let projectRoot = undefined;
|
16
|
-
let packageJSON = undefined;
|
17
|
-
let appName = undefined;
|
18
|
-
|
19
|
-
Menu.setApplicationMenu(null);
|
20
|
-
|
21
|
-
module.exports = function(mainOptions){
|
22
|
-
mainOptions = Object.assign({},mainOptions);
|
23
|
-
let {url:pUrl} = mainOptions;
|
24
|
-
projectRoot = mainOptions.projectRoot;
|
25
|
-
appName = mainOptions.appName;
|
26
|
-
packageJSON = Object.assign({},mainOptions.packageJSON);
|
27
|
-
|
28
|
-
appName = typeof appName == "string" && appName || typeof packageJSON.realAppName =="string" && packageJSON.realAppName || typeof packageJSON.name =="string" && packageJSON.name || "";
|
29
|
-
const indexFilePath = path.resolve(path.join(projectRoot,"dist",'index.html'));
|
30
|
-
const mainProcessPath = path.resolve('processes',"main","index.js");
|
31
|
-
const mainProcessIndex = projectRoot && fs.existsSync(path.resolve(projectRoot,mainProcessPath)) && path.resolve(projectRoot,mainProcessPath);
|
32
|
-
const mainProcessRequired = mainProcessIndex && require(`${mainProcessIndex}`);
|
33
|
-
//pour étendre les fonctionnalités au niveau du main proceess, bien vouloir écrire dans le fichier projectRoot/electron/main/index.js
|
34
|
-
const mainProcess = mainProcessRequired && typeof mainProcessRequired =='object'? mainProcessRequired : {};
|
35
|
-
mainProcessRef.current = mainProcess;
|
36
|
-
// Gardez une reference globale de l'objet window, si vous ne le faites pas, la fenetre sera
|
37
|
-
|
38
|
-
if(!isValidUrl(pUrl) && !fs.existsSync(indexFilePath)){
|
39
|
-
throw {message:`Unable to start the application: index file located at [${indexFilePath}] does not exists : projectRoot = [${projectRoot}], isAsar:[${require.main}]`}
|
40
|
-
}
|
41
|
-
|
42
|
-
//app.disableHardwareAcceleration();
|
43
|
-
|
44
|
-
app.whenReady().then(() => {
|
45
|
-
const readOpts = {toggleDevTools,browserWindow:win,mainWindow:win};
|
46
|
-
if(typeof mainProcess.whenAppReady =='function'){
|
47
|
-
mainProcess.whenAppReady(readOpts);
|
48
|
-
}
|
49
|
-
globalShortcut.register('CommandOrControl+F12', () => {
|
50
|
-
return toggleDevTools();
|
51
|
-
});
|
52
|
-
app.on('activate', function () {
|
53
|
-
if (win == null || (BrowserWindow.getAllWindows().length === 0)) createWindow()
|
54
|
-
});
|
55
|
-
});
|
56
|
-
|
57
|
-
|
58
|
-
const gotTheLock = app.requestSingleInstanceLock()
|
59
|
-
/*if (!gotTheLock) {
|
60
|
-
//throw {message : "application want to quit heeein "+gotTheLock};
|
61
|
-
//quit()
|
62
|
-
} else*/ {
|
63
|
-
app.on('second-instance', (event, commandLine, workingDirectory) => {
|
64
|
-
// Someone tried to run a second instance, we should focus our window.
|
65
|
-
//pour plus tard il sera possible d'afficher la gestion multi fenêtre en environnement electron
|
66
|
-
if (win) {
|
67
|
-
if (win.isMinimized()) win.restore()
|
68
|
-
win.focus()
|
69
|
-
}
|
70
|
-
})
|
71
|
-
}
|
72
|
-
}
|
73
|
-
|
74
|
-
function createBrowserWindow (options){
|
75
|
-
const {isMainWindow} = options;
|
76
|
-
options = Object.assign({},options);
|
77
|
-
const menu = options.menu;
|
78
|
-
options.webPreferences = isObj(options.webPreferences)? options.webPreferences : {};
|
79
|
-
const mainProcess = typeof mainProcessRef.current == "object" && mainProcessRef.current || {};
|
80
|
-
options.webPreferences = {
|
81
|
-
sandbox: false,
|
82
|
-
webSecurity : true,
|
83
|
-
plugin:false,
|
84
|
-
autoHideMenuBar: true,
|
85
|
-
contextIsolation: true,
|
86
|
-
contentSecurityPolicy: `
|
87
|
-
default-src 'none';
|
88
|
-
script-src 'self';
|
89
|
-
img-src 'self' data:;
|
90
|
-
style-src 'self';
|
91
|
-
font-src 'self';
|
92
|
-
`,
|
93
|
-
...options.webPreferences,
|
94
|
-
devTools: typeof options.webPreferences.devTools === 'boolean'? options.webPreferences.devTools : false,
|
95
|
-
allowRunningInsecureContent: false,
|
96
|
-
nodeIntegration: false,
|
97
|
-
preload: options.preload ? options.preload : null,
|
98
|
-
}
|
99
|
-
if(options.modal && !options.parent && win){
|
100
|
-
options.parent = win;
|
101
|
-
}
|
102
|
-
if(typeof options.show ==='undefined'){
|
103
|
-
options.show = false;
|
104
|
-
}
|
105
|
-
let showOnLoad = options.showOnLoad ===true ? true : undefined;
|
106
|
-
if(showOnLoad){
|
107
|
-
options.show = false;
|
108
|
-
}
|
109
|
-
if(typeof mainProcess?.beforeCreateWindow =='function'){
|
110
|
-
const opts = Object.assign({},mainProcess.beforeCreateWindow(options));
|
111
|
-
options = {...options,...opts};
|
112
|
-
}
|
113
|
-
let _win = new BrowserWindow(options);
|
114
|
-
if(!menu){
|
115
|
-
_win.setMenu(null);
|
116
|
-
_win.removeMenu();
|
117
|
-
_win.setMenuBarVisibility(false)
|
118
|
-
_win.setAutoHideMenuBar(true)
|
119
|
-
}
|
120
|
-
const url = isValidUrl(options.loadURL) || typeof options.loadURL ==='string' && options.loadURL.trim().startsWith("file://") ? options.loadURL : undefined;
|
121
|
-
if(url){
|
122
|
-
_win.loadURL(url);
|
123
|
-
} else if(options.file && fs.existsSync(options.file)){
|
124
|
-
_win.loadFile(options.file);
|
125
|
-
}
|
126
|
-
if(showOnLoad){
|
127
|
-
_win.once('ready-to-show', () => {
|
128
|
-
_win.show();
|
129
|
-
_win.webContents.send("window-ready-to-show",JSON.stringify(options.readyToShowOptions));
|
130
|
-
});
|
131
|
-
}
|
132
|
-
_win.on('closed', function() {
|
133
|
-
if(isMainWindow && typeof mainProcess?.onMainWindowClosed == "function"){
|
134
|
-
mainProcess.onMainWindowClosed(_win);
|
135
|
-
}
|
136
|
-
_win = null;
|
137
|
-
});
|
138
|
-
_win.webContents.on('context-menu',clipboadContextMenu);
|
139
|
-
return _win;
|
140
|
-
}
|
141
|
-
|
142
|
-
|
143
|
-
function createWindow () {
|
144
|
-
const mainProcess = mainProcessRef.current;
|
145
|
-
// Créer le browser window
|
146
|
-
win = createBrowserWindow({
|
147
|
-
showOnLoad : false,
|
148
|
-
loadURL : undefined,
|
149
|
-
isMainWindow : true,
|
150
|
-
registerDevToolsCommand : false,
|
151
|
-
preload : path.resolve(__dirname,'preload.js'),
|
152
|
-
webPreferences : {
|
153
|
-
devTools : true,
|
154
|
-
}
|
155
|
-
});
|
156
|
-
const sOptions = {width: 500, height: 400, transparent: true, frame: false, alwaysOnTop: true};
|
157
|
-
const splash = typeof mainProcess.splashScreen ==='function'&& mainProcess.splashScreen(sOptions)
|
158
|
-
|| typeof mainProcess.splash ==='function' && mainProcess.splash(sOptions)
|
159
|
-
|| (mainProcess.splash instanceof BrowserWindow) && mainProcess.splash
|
160
|
-
|| (mainProcess.splashScreen instanceof BrowserWindow) && mainProcess.splashScreen;
|
161
|
-
null;
|
162
|
-
let hasInitWindows = false;
|
163
|
-
win.on('show', () => {
|
164
|
-
//win.blur();
|
165
|
-
setTimeout(() => {
|
166
|
-
win.focus();
|
167
|
-
win.moveTop();
|
168
|
-
win.webContents.focus();
|
169
|
-
if(!hasInitWindows){
|
170
|
-
hasInitWindows = true;
|
171
|
-
win.webContents.send('appReady');
|
172
|
-
}
|
173
|
-
}, 200);
|
174
|
-
});
|
175
|
-
|
176
|
-
win.on("focus",()=>{
|
177
|
-
if(win && hasInitWindows){
|
178
|
-
win.webContents.send("main-window-focus");
|
179
|
-
}
|
180
|
-
});
|
181
|
-
win.on("blur",()=>{
|
182
|
-
if(win && hasInitWindows){
|
183
|
-
win.webContents.send("main-window-blur");
|
184
|
-
}
|
185
|
-
});
|
186
|
-
|
187
|
-
win.once("ready-to-show",function(){
|
188
|
-
if(typeof mainProcess.onMainWindowReadyToShow ==='function'){
|
189
|
-
mainProcess.onMainWindowReadyToShow(win);
|
190
|
-
}
|
191
|
-
win.minimize()
|
192
|
-
try {
|
193
|
-
if(splash && splash instanceof BrowserWindow){
|
194
|
-
splash.destroy();
|
195
|
-
}
|
196
|
-
} catch{ }
|
197
|
-
win.restore();
|
198
|
-
win.show();
|
199
|
-
//log(icon," is consooleeeee")
|
200
|
-
})
|
201
|
-
|
202
|
-
win.on('close', (e) => {
|
203
|
-
if (win) {
|
204
|
-
if(typeof mainProcess.onMainWindowClose == "function"){
|
205
|
-
mainProcess.onMainWindowClose(win);
|
206
|
-
}
|
207
|
-
e.preventDefault();
|
208
|
-
win.webContents.send('before-app-exit');
|
209
|
-
}
|
210
|
-
});
|
211
|
-
if(isValidUrl(pUrl)){
|
212
|
-
win.loadURL(pUrl);
|
213
|
-
} else {
|
214
|
-
win.loadFile(indexFilePath)
|
215
|
-
}
|
216
|
-
|
217
|
-
win.on('unresponsive', async () => {
|
218
|
-
const { response } = await dialog.showMessageBox({
|
219
|
-
title: "L'application a cessé de répondre",
|
220
|
-
message : 'Voulez vous relancer l\'application?',
|
221
|
-
buttons: ['Relancer', 'Arrêter'],
|
222
|
-
cancelId: 1
|
223
|
-
});
|
224
|
-
if (response === 0) {
|
225
|
-
win.forcefullyCrashRenderer()
|
226
|
-
win.reload()
|
227
|
-
} else {
|
228
|
-
win.forcefullyCrashRenderer()
|
229
|
-
app.exit();
|
230
|
-
}
|
231
|
-
});
|
232
|
-
|
233
|
-
// Émit lorsque la fenêtre est fermée.
|
234
|
-
win.on('closed', () => {
|
235
|
-
win = null
|
236
|
-
})
|
237
|
-
win.setMenu(null);
|
238
|
-
|
239
|
-
/*** les dimenssions de la fenêtre principale */
|
240
|
-
let mWindowSessinName = "mainWindowSizes";
|
241
|
-
let mWindowPositionSName = mWindowSessinName+"-positions";
|
242
|
-
let sizeW = session.get(mWindowSessinName);
|
243
|
-
if(!sizeW || typeof sizeW !== 'object'){
|
244
|
-
sizeW = {};
|
245
|
-
}
|
246
|
-
let sPositions = session.get(mWindowPositionSName);
|
247
|
-
if(!sPositions || typeof sPositions !=='object'){
|
248
|
-
sPositions = {};
|
249
|
-
}
|
250
|
-
let isNumber = x => typeof x =="number";
|
251
|
-
if(isNumber(sizeW.width) && isNumber(sizeW.height)){
|
252
|
-
win.setSize(sizeW.width,sizeW.height);
|
253
|
-
if(isNumber(sPositions.x) && isNumber(sPositions.y)){
|
254
|
-
win.setPosition(sPositions.x,sPositions.y);
|
255
|
-
}
|
256
|
-
}
|
257
|
-
const onWinResizeEv = debounce(function () {
|
258
|
-
if(win){
|
259
|
-
let wSize = win.getSize();
|
260
|
-
if(Array.isArray(wSize) && wSize.length == 2){
|
261
|
-
let [width,height] = wSize;
|
262
|
-
if(width && height){
|
263
|
-
session.set(mWindowSessinName,{width,height});
|
264
|
-
}
|
265
|
-
let [x,y] = win.getPosition();
|
266
|
-
session.set(mWindowPositionSName,{x,y});
|
267
|
-
}
|
268
|
-
}
|
269
|
-
}, 100);
|
270
|
-
win.off('resize',onWinResizeEv);
|
271
|
-
win.on('resize',onWinResizeEv);
|
272
|
-
win.off('move',onWinResizeEv);
|
273
|
-
win.on('move',onWinResizeEv);
|
274
|
-
if(typeof mainProcess.onCreateMainWindow =='function'){
|
275
|
-
mainProcess.onCreateMainWindow(win);
|
276
|
-
}
|
277
|
-
return win;
|
278
|
-
}
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
const toggleDevTools = (value)=>{
|
283
|
-
if(win !==null && win.webContents){
|
284
|
-
const isOpen= win.webContents.isDevToolsOpened();
|
285
|
-
value = value === undefined ? !isOpen : value;
|
286
|
-
if(value && !isOpen){
|
287
|
-
win.webContents.openDevTools();
|
288
|
-
return win.webContents.isDevToolsOpened();
|
289
|
-
} else {
|
290
|
-
if(isOpen) win.webContents.closeDevTools();
|
291
|
-
}
|
292
|
-
return win.webContents.isDevToolsOpened();
|
293
|
-
}
|
294
|
-
return false;
|
295
|
-
}
|
296
|
-
ipcMain.on("toggle-dev-tools",function(event,value) {
|
297
|
-
return toggleDevTools(value);
|
298
|
-
});
|
299
|
-
|
300
|
-
ipcMain.handle("create-browser-windows",function(event,options){
|
301
|
-
if(typeof options =='string'){
|
302
|
-
try {
|
303
|
-
const t = JSON.parse(options);
|
304
|
-
options = t;
|
305
|
-
} catch{}
|
306
|
-
}
|
307
|
-
options = Object.assign({},options);
|
308
|
-
createBrowserWindow(options);
|
309
|
-
});
|
310
|
-
|
311
|
-
ipcMain.on("restart-app",x =>{app.relaunch();})
|
312
|
-
let tray = null;
|
313
|
-
let isJSON = function (json_string){
|
314
|
-
if(!json_string || typeof json_string != 'string') return false;
|
315
|
-
var text = json_string;
|
316
|
-
return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(text.replace(/"(\\.|[^"\\])*"/g, '')));
|
317
|
-
}
|
318
|
-
ipcMain.on("update-system-tray",(event,opts)=>{
|
319
|
-
opts = opts && typeof opts == 'object'? opts : {};
|
320
|
-
let {contextMenu,tooltip} = opts;
|
321
|
-
if(tray){
|
322
|
-
} else {
|
323
|
-
tray = new Tray();
|
324
|
-
}
|
325
|
-
if(!tooltip || typeof tooltip !=="string"){
|
326
|
-
tooltip = ""
|
327
|
-
}
|
328
|
-
tray.setToolTip(tooltip);
|
329
|
-
if(isJSON(contextMenu)){
|
330
|
-
contextMenu = JSON.parse(contextMenu);
|
331
|
-
}
|
332
|
-
if(Array.isArray(contextMenu) && contextMenu.length) {
|
333
|
-
let tpl = []
|
334
|
-
contextMenu.map((m,index)=>{
|
335
|
-
if(!m || typeof m !=='object') return;
|
336
|
-
m.click = (e)=>{
|
337
|
-
if(win && win.webContents) win.webContents.send("click-on-system-tray-menu-item",{
|
338
|
-
action : m.action && typeof m.action =='string'? m.action : undefined,
|
339
|
-
index,
|
340
|
-
menuItem : JSON.stringify(m),
|
341
|
-
})
|
342
|
-
}
|
343
|
-
tpl.push(m);
|
344
|
-
})
|
345
|
-
contextMenu = Menu.buildFromTemplate(tpl);
|
346
|
-
} else contextMenu = null;
|
347
|
-
tray.setContextMenu(contextMenu)
|
348
|
-
})
|
349
|
-
ipcMain.on("get-path",(event,pathName)=>{
|
350
|
-
const p = app.getPath(pathName);
|
351
|
-
event.returnValue = p;
|
352
|
-
return p;
|
353
|
-
});
|
354
|
-
|
355
|
-
ipcMain.on("get-project-root",(event)=>{
|
356
|
-
event.returnValue = projectRoot;
|
357
|
-
return event.returnValue;
|
358
|
-
});
|
359
|
-
ipcMain.on("get-electron-project-root",(event)=>{
|
360
|
-
event.returnValue = projectRoot;
|
361
|
-
return event.returnValue ;
|
362
|
-
});
|
363
|
-
|
364
|
-
ipcMain.on("get-package.json",(event)=>{
|
365
|
-
event.returnValue = JSON.stringify(packageJSON);
|
366
|
-
return event.returnValue ;
|
367
|
-
});
|
368
|
-
|
369
|
-
ipcMain.on("get-app-name",(event)=>{
|
370
|
-
event.returnValue = appName;
|
371
|
-
return event.returnValue ;
|
372
|
-
});
|
373
|
-
|
374
|
-
ipcMain.on("get-media-access-status",(event,mediaType)=>{
|
375
|
-
let p = systemPreferences.getMediaAccessStatus(mediaType);
|
376
|
-
event.returnValue = p;
|
377
|
-
return p;
|
378
|
-
});
|
379
|
-
|
380
|
-
ipcMain.on("ask-for-media-access",(event,mediaType)=>{
|
381
|
-
systemPreferences.askForMediaAccess(mediaType);
|
382
|
-
});
|
383
|
-
|
384
|
-
ipcMain.on("get-app-icon",(event)=>{
|
385
|
-
event.returnValue = win != win && win.getIcon && win.getIcon();
|
386
|
-
});
|
387
|
-
ipcMain.on("set-app-icon",(event,iconPath)=>{
|
388
|
-
if(iconPath && win != null){
|
389
|
-
win.setIcon(iconPath);
|
390
|
-
event.returnValue = iconPath;
|
391
|
-
} else {
|
392
|
-
event.returnValue = null;
|
393
|
-
}
|
394
|
-
});
|
395
|
-
|
396
|
-
ipcMain.on('minimize-main-window', () => {
|
397
|
-
if(win !== null && win){
|
398
|
-
win.blur();
|
399
|
-
win.minimize();
|
400
|
-
}
|
401
|
-
})
|
402
|
-
ipcMain.on('restore-main-window', () => {
|
403
|
-
if(win && win !== null){
|
404
|
-
win.restore()
|
405
|
-
win.blur();
|
406
|
-
setTimeout(() => {
|
407
|
-
win.focus();
|
408
|
-
win.moveTop();
|
409
|
-
win.webContents.focus();
|
410
|
-
}, 200);
|
411
|
-
}
|
412
|
-
})
|
413
|
-
ipcMain.on('close-main-render-process', _ => {
|
414
|
-
if(win){
|
415
|
-
win.destroy();
|
416
|
-
}
|
417
|
-
win = null;
|
418
|
-
if(typeof gc =="function"){
|
419
|
-
gc();
|
420
|
-
}
|
421
|
-
quit();
|
422
|
-
});
|
423
|
-
|
424
|
-
const quit = ()=>{
|
425
|
-
try {
|
426
|
-
app.quit();
|
427
|
-
} catch(e){
|
428
|
-
console.log(e," triing kit app")
|
429
|
-
}
|
430
|
-
}
|
431
|
-
|
432
|
-
|
433
|
-
const powerMonitorCallbackEvent = (action)=>{
|
434
|
-
if(!win || !win.webContents) return;
|
435
|
-
if(action =="suspend" || action =="lock-screen"){
|
436
|
-
win.webContents.send("main-app-suspended",action);
|
437
|
-
return;
|
438
|
-
}
|
439
|
-
win.webContents.send("main-app-restaured",action);
|
440
|
-
win.webContents.focus();
|
441
|
-
return null;
|
442
|
-
}
|
443
|
-
if(powerMonitor){
|
444
|
-
["suspend","resume","lock-screen","unlock-screen"].map((action)=>{
|
445
|
-
powerMonitor.on(action,(event)=>{
|
446
|
-
powerMonitorCallbackEvent(action,event);
|
447
|
-
})
|
448
|
-
})
|
449
|
-
}
|
450
|
-
ipcMain.on("set-main-window-title",(event,title)=>{
|
451
|
-
if(win !== null){
|
452
|
-
win.setTitle(title);
|
453
|
-
}
|
454
|
-
});
|
455
|
-
|
456
|
-
ipcMain.handle("show-open-dialog",function(event,options){
|
457
|
-
if(typeof options =="string"){
|
458
|
-
try {
|
459
|
-
const t = JSON.parse(options);
|
460
|
-
options = t;
|
461
|
-
} catch{}
|
462
|
-
}
|
463
|
-
if(!isObj(options)){
|
464
|
-
options = {};
|
465
|
-
}
|
466
|
-
return dialog.showOpenDialog(win,options)
|
467
|
-
})
|
468
|
-
|
469
|
-
ipcMain.handle("show-save-dialog",function(event,options){
|
470
|
-
if(!isObj(options)){
|
471
|
-
options = {};
|
472
|
-
}
|
473
|
-
return dialog.showSaveDialog(win,options)
|
474
|
-
});
|
475
|
-
|
476
|
-
ipcMain.on("is-dev-tools-open",function(event,value) {
|
477
|
-
if(win !==null && win.webContents){
|
478
|
-
return win.webContents.isDevToolsOpened();
|
479
|
-
}
|
480
|
-
return false;
|
481
|
-
});
|
482
|
-
|
483
|
-
ipcMain.on("window-set-progressbar",(event,interval)=>{
|
484
|
-
if(typeof interval !="number" || interval <0) interval = 0;
|
485
|
-
interval = Math.floor(interval);
|
486
|
-
if(win){
|
487
|
-
win.setProgressBar(interval);
|
488
|
-
}
|
489
|
-
})
|
490
|
-
|
491
|
-
const setOSTheme = (theme) => {
|
492
|
-
theme = theme && typeof theme == "string"? theme : "light";
|
493
|
-
theme = theme.toLowerCase().trim();
|
494
|
-
if(theme !== 'system' && theme !=='dark'){
|
495
|
-
theme = "light";
|
496
|
-
}
|
497
|
-
nativeTheme.themeSource = theme;
|
498
|
-
session.set("os-theme",theme);
|
499
|
-
return nativeTheme.shouldUseDarkColors
|
500
|
-
}
|
501
|
-
|
502
|
-
/**** customisation des thèmes de l'application */
|
503
|
-
ipcMain.handle('set-system-theme:toggle', (event,theme) => {
|
504
|
-
return setOSTheme(theme);
|
505
|
-
});
|
506
|
-
|
507
|
-
ipcMain.handle('set-system-theme:dark-mode', (event) => {
|
508
|
-
nativeTheme.themeSource = 'dark';
|
509
|
-
return nativeTheme.shouldUseDarkColors;
|
510
|
-
});
|
511
|
-
ipcMain.handle('set-system-theme:light-mode', (event) => {
|
512
|
-
nativeTheme.themeSource = 'light';
|
513
|
-
return nativeTheme.shouldUseDarkColors;
|
514
|
-
});
|
515
|
-
|
516
|
-
|
517
|
-
ipcMain.handle('dark-mode:toggle', () => {
|
518
|
-
if (nativeTheme.shouldUseDarkColors) {
|
519
|
-
nativeTheme.themeSource = 'light'
|
520
|
-
} else {
|
521
|
-
nativeTheme.themeSource = 'dark'
|
522
|
-
}
|
523
|
-
return nativeTheme.shouldUseDarkColors
|
524
|
-
})
|
525
|
-
|
526
|
-
ipcMain.handle('dark-mode:system', () => {
|
527
|
-
nativeTheme.themeSource = 'system'
|
528
|
-
});
|
529
|
-
|
530
|
-
const clipboadContextMenu = (_, props) => {
|
531
|
-
if (props.isEditable || props.selectionText) {
|
532
|
-
const menu = new Menu();
|
533
|
-
if(props.selectionText){
|
534
|
-
menu.append(new MenuItem({ label: 'Copier', role: 'copy' }));
|
535
|
-
if(props.isEditable){
|
536
|
-
menu.append(new MenuItem({ label: 'Couper', role: 'cut' }));
|
537
|
-
}
|
538
|
-
}
|
539
|
-
if(props.isEditable){
|
540
|
-
menu.append(new MenuItem({ label: 'Coller', role: 'paste' }));
|
541
|
-
}
|
542
|
-
menu.popup();
|
543
|
-
}
|
544
|
-
};
|
545
|
-
|
546
|
-
// Quitte l'application quand toutes les fenêtres sont fermées.
|
547
|
-
app.on('window-all-closed', () => {
|
548
|
-
// Sur macOS, il est commun pour une application et leur barre de menu
|
549
|
-
// de rester active tant que l'utilisateur ne quitte pas explicitement avec Cmd + Q
|
550
|
-
if (process.platform !== 'darwin') {
|
551
|
-
quit();
|
552
|
-
}
|
553
|
-
});
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
module.exports.createBrowserWindow = createBrowserWindow;
|