@fto-consult/expo-ui 7.5.35 → 7.5.36
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 +142 -145
- package/electron/init/main.js +1 -0
- package/package.json +1 -1
package/bin/index.js
CHANGED
@@ -53,13 +53,13 @@ program.command('electron')
|
|
53
53
|
.option('-b, --build [boolean]', 'si ce flag est spécfifié alors l\'application sera compilée; combinée avec la commande start|package pour indiquer que l\'application sera à nouveau exportée ou pas.')
|
54
54
|
.option('-a, --arch [architecture]', 'l\'architecture de la plateforme; Commande package')
|
55
55
|
.option('-p, --platform [platform]', 'la plateforme à utiliser pour la compilation; commande package')
|
56
|
-
.option('-l, --
|
56
|
+
.option('-l, --icon [iconPath]', 'le chemin vers l\'icon de l\'application : (.ico pour window, .incs pour mac et .png pour linux)')
|
57
57
|
.option('-i, --import [boolean]', 'la commande d\'initialisation du package electron forge, utile pour le packaging de l\'application. Elle permet d\'exécuter le cli electron package, pour l\'import d\'un projet existant. Commande package. exemple : expo-ui electron package --import')
|
58
58
|
|
59
59
|
.action((script, options) => {
|
60
60
|
const electronProjectRoot = path.resolve(projectRoot,"electron");
|
61
61
|
const opts = Object.assign({},typeof options.opts =='function'? options.opts() : options);
|
62
|
-
let {out,arch,url,build,platform,import:packageImport,
|
62
|
+
let {out,arch,url,build,platform,import:packageImport,icon} = opts;
|
63
63
|
//let {projectRoot} = opts;
|
64
64
|
if(projectRoot == dir){
|
65
65
|
throwError(`Invalid project root ${projectRoot}; project root must be different to ${dir}`);
|
@@ -78,8 +78,8 @@ program.command('electron')
|
|
78
78
|
const packageObj = require(`${packagePath}`);
|
79
79
|
const homepage = packageObj.homepage;
|
80
80
|
let cmd = undefined;
|
81
|
-
|
82
|
-
require("../electron/create-index-file")({electronProjectRoot,appName:packageObj.name,
|
81
|
+
icon = icon && typeof icon =="string" && fs.existsSync(path.resolve(icon)) && icon || undefined;
|
82
|
+
require("../electron/create-index-file")({electronProjectRoot,appName:packageObj.name,icon});
|
83
83
|
if(!isElectionInitialized || script =='init'){
|
84
84
|
if(script !=='init'){
|
85
85
|
console.log("initializing electron application before ....");
|
@@ -96,7 +96,7 @@ program.command('electron')
|
|
96
96
|
}
|
97
97
|
const start = x=>{
|
98
98
|
return new Promise((resolve,reject)=>{
|
99
|
-
cmd = `electron "${electronProjectRoot}" ${isValidUrl(url)? ` --url ${url}`:''}`;
|
99
|
+
cmd = `electron "${electronProjectRoot}" --root ${electronProjectRoot} ${isValidUrl(url)? ` --url ${url}`:''} ${icon ? `--icon ${path.resolve(icon)}`:""}`;
|
100
100
|
exec({
|
101
101
|
cmd,
|
102
102
|
projectRoot : electronProjectRoot,
|
package/electron/index.js
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
const { program } = require('commander');
|
2
|
-
const
|
2
|
+
const path = require("path");
|
3
|
+
const fs = require("fs");
|
4
|
+
const isValidUrl = require("./utils/isValidUrl");
|
3
5
|
|
4
6
|
const debounce = require("./utils/debounce");
|
5
7
|
const {app, BrowserWindow,Tray,Menu,MenuItem,globalShortcut,systemPreferences,powerMonitor,ipcMain,dialog, nativeTheme} = require('electron')
|
@@ -11,15 +13,14 @@ const isObj = x => x && typeof x =='object';
|
|
11
13
|
program
|
12
14
|
.option('-u, --url <url>', 'L\'adresse url à ouvrir au lancement de l\'application')
|
13
15
|
.option('-r, --root <projectRoot>', 'le chemin du project root de l\'application')
|
16
|
+
.option('-l, --icon [iconPath]', 'le chemin vers le icon de l\'application : (.ico pour window, .incs pour mac et .png pour linux)')
|
14
17
|
.parse();
|
15
18
|
|
16
19
|
const programOptions = program.opts();
|
17
|
-
const {url:pUrl,root:mainProjectRoot} = programOptions;
|
20
|
+
const {url:pUrl,root:mainProjectRoot,icon} = programOptions;
|
21
|
+
const iconPath = icon && typeof icon =="string" && fs.existsSync(path.resolve(icon)) && path.resolve(icon) || undefined;
|
18
22
|
|
19
23
|
const isAsar = (typeof require.main =="string" && require.main ||"").indexOf('app.asar') !== -1;
|
20
|
-
const path = require("path");
|
21
|
-
const fs = require("fs");
|
22
|
-
const isValidUrl = require("./utils/isValidUrl");
|
23
24
|
const distPath = path.join("dist",'index.html');
|
24
25
|
|
25
26
|
const processCWD = process.cwd();
|
@@ -31,7 +32,7 @@ const packageJSON = fs.existsSync(packageJSONPath) ? Object.assign({},require(`$
|
|
31
32
|
const appName = typeof packageJSON.realAppName =='string' && packageJSON.realAppName || typeof packageJSON.name =="string" && packageJSON.name || "";
|
32
33
|
|
33
34
|
// fermee automatiquement quand l'objet JavaScript sera garbage collected.
|
34
|
-
let
|
35
|
+
let mainWindow = undefined;
|
35
36
|
|
36
37
|
Menu.setApplicationMenu(null);
|
37
38
|
|
@@ -42,15 +43,7 @@ const mainProcessRequired = mainProcessIndex && require(`${mainProcessIndex}`);
|
|
42
43
|
//pour étendre les fonctionnalités au niveau du main proceess, bien vouloir écrire dans le fichier projectRoot/electron/main/index.js
|
43
44
|
const mainProcess = mainProcessRequired && typeof mainProcessRequired =='object'? mainProcessRequired : {};
|
44
45
|
|
45
|
-
|
46
|
-
if(!isValidUrl(pUrl) && !fs.existsSync(indexFilePath)){
|
47
|
-
throw {message:`Unable to start the application: index file located at [${indexFilePath}] does not exists : projectRoot = [${projectRoot}], isAsar:[${require.main}]`}
|
48
|
-
}
|
49
|
-
|
50
|
-
const ipcMainHandleEvent = (event,callback)=>{
|
51
|
-
ipcMain.removeHandler(event,callback);
|
52
|
-
return ipcMain.handle(event,callback);
|
53
|
-
}
|
46
|
+
|
54
47
|
const quit = ()=>{
|
55
48
|
try {
|
56
49
|
app.quit();
|
@@ -59,6 +52,11 @@ const quit = ()=>{
|
|
59
52
|
}
|
60
53
|
}
|
61
54
|
|
55
|
+
// Gardez une reference globale de l'objet window, si vous ne le faites pas, la fenetre sera
|
56
|
+
if(!isValidUrl(pUrl) && !fs.existsSync(indexFilePath)){
|
57
|
+
throw {message:`Unable to start the application: index file located at [${indexFilePath}] does not exists : projectRoot = [${projectRoot}], isAsar:[${require.main}]`}
|
58
|
+
}
|
59
|
+
|
62
60
|
//app.disableHardwareAcceleration();
|
63
61
|
|
64
62
|
function createBrowserWindow (options){
|
@@ -85,8 +83,8 @@ function createBrowserWindow (options){
|
|
85
83
|
nodeIntegration: false,
|
86
84
|
preload: options.preload ? options.preload : null,
|
87
85
|
}
|
88
|
-
if(options.modal && !options.parent &&
|
89
|
-
options.parent =
|
86
|
+
if(options.modal && !options.parent && mainWindow){
|
87
|
+
options.parent = mainWindow;
|
90
88
|
}
|
91
89
|
if(typeof options.show ==='undefined'){
|
92
90
|
options.show = false;
|
@@ -99,38 +97,53 @@ function createBrowserWindow (options){
|
|
99
97
|
const opts = Object.assign({},mainProcess.beforeCreateWindow(options));
|
100
98
|
options = {...options,...opts};
|
101
99
|
}
|
102
|
-
|
100
|
+
options.icon = options.icon || iconPath;
|
101
|
+
const window = new BrowserWindow(options);
|
103
102
|
if(!menu){
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
103
|
+
window.setMenu(null);
|
104
|
+
window.removeMenu();
|
105
|
+
window.setMenuBarVisibility(false)
|
106
|
+
window.setAutoHideMenuBar(true)
|
108
107
|
}
|
109
|
-
const url = isValidUrl(options.loadURL) || typeof options.loadURL ==='string' && options.loadURL.trim().startsWith("file://") ? options.loadURL : undefined;
|
110
|
-
if(url){
|
111
|
-
_win.loadURL(url);
|
112
|
-
} else if(options.file && fs.existsSync(path.resolve(options.file))){
|
113
|
-
_win.loadFile(path.resolve(options.file));
|
114
|
-
}
|
115
108
|
if(showOnLoad){
|
116
|
-
|
117
|
-
|
118
|
-
|
109
|
+
window.once('ready-to-show', () => {
|
110
|
+
window.show();
|
111
|
+
window.webContents.send("window-ready-to-show",JSON.stringify(options.readyToShowOptions));
|
119
112
|
});
|
120
113
|
}
|
121
|
-
|
114
|
+
window.on('closed', function() {
|
122
115
|
if(isMainWindow && typeof mainProcess?.onMainWindowClosed == "function"){
|
123
|
-
mainProcess.onMainWindowClosed(
|
116
|
+
mainProcess.onMainWindowClosed(window);
|
124
117
|
}
|
125
|
-
|
118
|
+
window = null;
|
126
119
|
});
|
127
|
-
|
128
|
-
|
120
|
+
window.webContents.on('context-menu',clipboadContextMenu);
|
121
|
+
const url = isValidUrl(options.loadURL) || typeof options.loadURL ==='string' && options.loadURL.trim().startsWith("file://") ? options.loadURL : undefined;
|
122
|
+
if(url){
|
123
|
+
window.loadURL(url);
|
124
|
+
} else if(options.file && fs.existsSync(path.resolve(options.file))){
|
125
|
+
window.loadFile(path.resolve(options.file));
|
126
|
+
}
|
127
|
+
return window;
|
129
128
|
}
|
129
|
+
|
130
|
+
app.whenReady().then(() => {
|
131
|
+
createWindow();
|
132
|
+
const readOpts = {toggleDevTools,browserWindow:mainWindow,mainWindow:mainWindow};
|
133
|
+
if(typeof mainProcess.whenAppReady =='function'){
|
134
|
+
mainProcess.whenAppReady(readOpts);
|
135
|
+
}
|
136
|
+
globalShortcut.register('CommandOrControl+F12', () => {
|
137
|
+
return toggleDevTools();
|
138
|
+
});
|
139
|
+
app.on('activate', function () {
|
140
|
+
if (mainWindow == null || (BrowserWindow.getAllWindows().length === 0)) createWindow()
|
141
|
+
});
|
142
|
+
});
|
130
143
|
|
131
144
|
function createWindow () {
|
132
145
|
// Créer le browser window
|
133
|
-
|
146
|
+
mainWindow = createBrowserWindow({
|
134
147
|
showOnLoad : false,
|
135
148
|
loadURL : undefined,
|
136
149
|
isMainWindow : true,
|
@@ -149,54 +162,54 @@ function createWindow () {
|
|
149
162
|
|| (mainProcess.splashScreen instanceof BrowserWindow) && mainProcess.splashScreen;
|
150
163
|
null;
|
151
164
|
let hasInitWindows = false;
|
152
|
-
|
153
|
-
//
|
165
|
+
mainWindow.on('show', () => {
|
166
|
+
//mainWindow.blur();
|
154
167
|
setTimeout(() => {
|
155
|
-
|
156
|
-
|
157
|
-
|
168
|
+
mainWindow.focus();
|
169
|
+
mainWindow.moveTop();
|
170
|
+
mainWindow.webContents.focus();
|
158
171
|
if(!hasInitWindows){
|
159
172
|
hasInitWindows = true;
|
160
|
-
|
173
|
+
mainWindow.webContents.send('appReady');
|
161
174
|
}
|
162
175
|
}, 200);
|
163
176
|
});
|
164
177
|
|
165
|
-
|
166
|
-
if(
|
167
|
-
|
178
|
+
mainWindow.on("focus",()=>{
|
179
|
+
if(mainWindow && hasInitWindows){
|
180
|
+
mainWindow.webContents.send("main-window-focus");
|
168
181
|
}
|
169
182
|
});
|
170
|
-
|
171
|
-
if(
|
172
|
-
|
183
|
+
mainWindow.on("blur",()=>{
|
184
|
+
if(mainWindow && hasInitWindows){
|
185
|
+
mainWindow.webContents.send("main-window-blur");
|
173
186
|
}
|
174
187
|
});
|
175
|
-
|
188
|
+
mainWindow.once("ready-to-show",function(){
|
176
189
|
if(typeof mainProcess.onMainWindowReadyToShow ==='function'){
|
177
|
-
mainProcess.onMainWindowReadyToShow(
|
190
|
+
mainProcess.onMainWindowReadyToShow(mainWindow);
|
178
191
|
}
|
179
|
-
|
192
|
+
mainWindow.minimize()
|
180
193
|
try {
|
181
194
|
if(splash && splash instanceof BrowserWindow){
|
182
195
|
splash.destroy();
|
183
196
|
}
|
184
197
|
} catch{ }
|
185
|
-
|
186
|
-
|
198
|
+
mainWindow.restore();
|
199
|
+
mainWindow.show();
|
187
200
|
})
|
188
201
|
|
189
|
-
|
190
|
-
if (
|
202
|
+
mainWindow.on('close', (e) => {
|
203
|
+
if (mainWindow) {
|
191
204
|
if(typeof mainProcess.onMainWindowClose == "function"){
|
192
|
-
mainProcess.onMainWindowClose(
|
205
|
+
mainProcess.onMainWindowClose(mainWindow);
|
193
206
|
}
|
194
207
|
e.preventDefault();
|
195
|
-
|
208
|
+
mainWindow.webContents.send('before-app-exit');
|
196
209
|
}
|
197
210
|
});
|
198
211
|
|
199
|
-
|
212
|
+
mainWindow.on('unresponsive', async () => {
|
200
213
|
const { response } = await dialog.showMessageBox({
|
201
214
|
title: "L'application a cessé de répondre",
|
202
215
|
message : 'Voulez vous relancer l\'application?',
|
@@ -204,19 +217,19 @@ function createWindow () {
|
|
204
217
|
cancelId: 1
|
205
218
|
});
|
206
219
|
if (response === 0) {
|
207
|
-
|
208
|
-
|
220
|
+
mainWindow.forcefullyCrashRenderer()
|
221
|
+
mainWindow.reload()
|
209
222
|
} else {
|
210
|
-
|
223
|
+
mainWindow.forcefullyCrashRenderer()
|
211
224
|
app.exit();
|
212
225
|
}
|
213
226
|
});
|
214
227
|
|
215
228
|
// Émit lorsque la fenêtre est fermée.
|
216
|
-
|
217
|
-
|
229
|
+
mainWindow.on('closed', () => {
|
230
|
+
mainWindow = null
|
218
231
|
})
|
219
|
-
|
232
|
+
mainWindow.setMenu(null);
|
220
233
|
|
221
234
|
/*** les dimenssions de la fenêtre principale */
|
222
235
|
let mWindowSessinName = "mainWindowSizes";
|
@@ -231,45 +244,45 @@ function createWindow () {
|
|
231
244
|
}
|
232
245
|
let isNumber = x => typeof x =="number";
|
233
246
|
if(isNumber(sizeW.width) && isNumber(sizeW.height)){
|
234
|
-
|
247
|
+
mainWindow.setSize(sizeW.width,sizeW.height);
|
235
248
|
if(isNumber(sPositions.x) && isNumber(sPositions.y)){
|
236
|
-
|
249
|
+
mainWindow.setPosition(sPositions.x,sPositions.y);
|
237
250
|
}
|
238
251
|
}
|
239
252
|
const onWinResizeEv = debounce(function () {
|
240
|
-
if(
|
241
|
-
let wSize =
|
253
|
+
if(mainWindow){
|
254
|
+
let wSize = mainWindow.getSize();
|
242
255
|
if(Array.isArray(wSize) && wSize.length == 2){
|
243
256
|
let [width,height] = wSize;
|
244
257
|
if(width && height){
|
245
258
|
session.set(mWindowSessinName,{width,height});
|
246
259
|
}
|
247
|
-
let [x,y] =
|
260
|
+
let [x,y] = mainWindow.getPosition();
|
248
261
|
session.set(mWindowPositionSName,{x,y});
|
249
262
|
}
|
250
263
|
}
|
251
264
|
}, 100);
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
265
|
+
mainWindow.off('resize',onWinResizeEv);
|
266
|
+
mainWindow.on('resize',onWinResizeEv);
|
267
|
+
mainWindow.off('move',onWinResizeEv);
|
268
|
+
mainWindow.on('move',onWinResizeEv);
|
256
269
|
if(typeof mainProcess.onCreateMainWindow =='function'){
|
257
|
-
mainProcess.onCreateMainWindow(
|
270
|
+
mainProcess.onCreateMainWindow(mainWindow);
|
258
271
|
}
|
259
|
-
return
|
260
|
-
|
272
|
+
return mainWindow;
|
273
|
+
}
|
261
274
|
|
262
275
|
const toggleDevTools = (value)=>{
|
263
|
-
if(
|
264
|
-
const isOpen=
|
276
|
+
if(mainWindow !==null && mainWindow.webContents){
|
277
|
+
const isOpen= mainWindow.webContents.isDevToolsOpened();
|
265
278
|
value = value === undefined ? !isOpen : value;
|
266
279
|
if(value && !isOpen){
|
267
|
-
|
268
|
-
return
|
280
|
+
mainWindow.webContents.openDevTools();
|
281
|
+
return mainWindow.webContents.isDevToolsOpened();
|
269
282
|
} else {
|
270
|
-
if(isOpen)
|
283
|
+
if(isOpen) mainWindow.webContents.closeDevTools();
|
271
284
|
}
|
272
|
-
return
|
285
|
+
return mainWindow.webContents.isDevToolsOpened();
|
273
286
|
}
|
274
287
|
return false;
|
275
288
|
}
|
@@ -311,7 +324,7 @@ function createWindow () {
|
|
311
324
|
contextMenu.map((m,index)=>{
|
312
325
|
if(!m || typeof m !=='object') return;
|
313
326
|
m.click = (e)=>{
|
314
|
-
if(
|
327
|
+
if(mainWindow && mainWindow.webContents) mainWindow.webContents.send("click-on-system-tray-menu-item",{
|
315
328
|
action : m.action && typeof m.action =='string'? m.action : undefined,
|
316
329
|
index,
|
317
330
|
menuItem : JSON.stringify(m),
|
@@ -359,11 +372,11 @@ function createWindow () {
|
|
359
372
|
});
|
360
373
|
|
361
374
|
ipcMain.on("get-app-icon",(event)=>{
|
362
|
-
event.returnValue =
|
375
|
+
event.returnValue = mainWindow != mainWindow && mainWindow.getIcon && mainWindow.getIcon();
|
363
376
|
});
|
364
377
|
ipcMain.on("set-app-icon",(event,iconPath)=>{
|
365
|
-
if(iconPath &&
|
366
|
-
|
378
|
+
if(iconPath && mainWindow != null){
|
379
|
+
mainWindow.setIcon(iconPath);
|
367
380
|
event.returnValue = iconPath;
|
368
381
|
} else {
|
369
382
|
event.returnValue = null;
|
@@ -371,27 +384,27 @@ function createWindow () {
|
|
371
384
|
});
|
372
385
|
|
373
386
|
ipcMain.on('minimize-main-window', () => {
|
374
|
-
if(
|
375
|
-
|
376
|
-
|
387
|
+
if(mainWindow !== null && mainWindow){
|
388
|
+
mainWindow.blur();
|
389
|
+
mainWindow.minimize();
|
377
390
|
}
|
378
391
|
})
|
379
392
|
ipcMain.on('restore-main-window', () => {
|
380
|
-
if(
|
381
|
-
|
382
|
-
|
393
|
+
if(mainWindow && mainWindow !== null){
|
394
|
+
mainWindow.restore()
|
395
|
+
mainWindow.blur();
|
383
396
|
setTimeout(() => {
|
384
|
-
|
385
|
-
|
386
|
-
|
397
|
+
mainWindow.focus();
|
398
|
+
mainWindow.moveTop();
|
399
|
+
mainWindow.webContents.focus();
|
387
400
|
}, 200);
|
388
401
|
}
|
389
402
|
})
|
390
403
|
ipcMain.on('close-main-render-process', _ => {
|
391
|
-
if(
|
392
|
-
|
404
|
+
if(mainWindow){
|
405
|
+
mainWindow.destroy();
|
393
406
|
}
|
394
|
-
|
407
|
+
mainWindow = null;
|
395
408
|
if(typeof gc =="function"){
|
396
409
|
gc();
|
397
410
|
}
|
@@ -399,13 +412,13 @@ function createWindow () {
|
|
399
412
|
});
|
400
413
|
|
401
414
|
const powerMonitorCallbackEvent = (action)=>{
|
402
|
-
if(!
|
415
|
+
if(!mainWindow || !mainWindow.webContents) return;
|
403
416
|
if(action =="suspend" || action =="lock-screen"){
|
404
|
-
|
417
|
+
mainWindow.webContents.send("main-app-suspended",action);
|
405
418
|
return;
|
406
419
|
}
|
407
|
-
|
408
|
-
|
420
|
+
mainWindow.webContents.send("main-app-restaured",action);
|
421
|
+
mainWindow.webContents.focus();
|
409
422
|
return null;
|
410
423
|
}
|
411
424
|
if(powerMonitor){
|
@@ -416,8 +429,8 @@ function createWindow () {
|
|
416
429
|
})
|
417
430
|
}
|
418
431
|
ipcMain.on("set-main-window-title",(event,title)=>{
|
419
|
-
if(
|
420
|
-
|
432
|
+
if(mainWindow !== null){
|
433
|
+
mainWindow.setTitle(title);
|
421
434
|
}
|
422
435
|
});
|
423
436
|
|
@@ -431,19 +444,19 @@ function createWindow () {
|
|
431
444
|
if(!isObj(options)){
|
432
445
|
options = {};
|
433
446
|
}
|
434
|
-
return dialog.showOpenDialog(
|
447
|
+
return dialog.showOpenDialog(mainWindow,options)
|
435
448
|
})
|
436
449
|
|
437
450
|
ipcMain.handle("show-save-dialog",function(event,options){
|
438
451
|
if(!isObj(options)){
|
439
452
|
options = {};
|
440
453
|
}
|
441
|
-
return dialog.showSaveDialog(
|
454
|
+
return dialog.showSaveDialog(mainWindow,options)
|
442
455
|
});
|
443
456
|
|
444
457
|
ipcMain.on("is-dev-tools-open",function(event,value) {
|
445
|
-
if(
|
446
|
-
return
|
458
|
+
if(mainWindow !==null && mainWindow.webContents){
|
459
|
+
return mainWindow.webContents.isDevToolsOpened();
|
447
460
|
}
|
448
461
|
return false;
|
449
462
|
});
|
@@ -451,12 +464,13 @@ function createWindow () {
|
|
451
464
|
ipcMain.on("window-set-progressbar",(event,interval)=>{
|
452
465
|
if(typeof interval !="number" || interval <0) interval = 0;
|
453
466
|
interval = Math.floor(interval);
|
454
|
-
if(
|
455
|
-
|
467
|
+
if(mainWindow){
|
468
|
+
mainWindow.setProgressBar(interval);
|
456
469
|
}
|
457
|
-
})
|
470
|
+
});
|
458
471
|
|
459
|
-
|
472
|
+
/**** customisation des thèmes de l'application */
|
473
|
+
ipcMain.handle('set-system-theme:toggle', (event,theme) => {
|
460
474
|
theme = theme && typeof theme == "string"? theme : "light";
|
461
475
|
theme = theme.toLowerCase().trim();
|
462
476
|
if(theme !== 'system' && theme !=='dark'){
|
@@ -465,11 +479,6 @@ function createWindow () {
|
|
465
479
|
nativeTheme.themeSource = theme;
|
466
480
|
session.set("os-theme",theme);
|
467
481
|
return nativeTheme.shouldUseDarkColors
|
468
|
-
}
|
469
|
-
|
470
|
-
/**** customisation des thèmes de l'application */
|
471
|
-
ipcMain.handle('set-system-theme:toggle', (event,theme) => {
|
472
|
-
return setOSTheme(theme);
|
473
482
|
});
|
474
483
|
|
475
484
|
ipcMain.handle('set-system-theme:dark-mode', (event) => {
|
@@ -519,31 +528,19 @@ app.on('window-all-closed', () => {
|
|
519
528
|
quit();
|
520
529
|
}
|
521
530
|
});
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
if (
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
}
|
536
|
-
|
537
|
-
app.whenReady().then(() => {
|
538
|
-
createWindow();
|
539
|
-
const readOpts = {toggleDevTools,browserWindow:win,mainWindow:win};
|
540
|
-
if(typeof mainProcess.whenAppReady =='function'){
|
541
|
-
mainProcess.whenAppReady(readOpts);
|
531
|
+
|
532
|
+
if(mainProcess.enableSingleInstance !== false){
|
533
|
+
const gotTheLock = app.requestSingleInstanceLock()
|
534
|
+
if (!gotTheLock) {
|
535
|
+
quit()
|
536
|
+
} else {
|
537
|
+
app.on('second-instance', (event, commandLine, workingDirectory) => {
|
538
|
+
// Someone tried to run a second instance, we should focus our window.
|
539
|
+
//pour plus tard il sera possible d'afficher la gestion multi fenêtre en environnement electron
|
540
|
+
if (mainWindow) {
|
541
|
+
if (mainWindow.isMinimized()) mainWindow.restore()
|
542
|
+
mainWindow.focus()
|
543
|
+
}
|
544
|
+
})
|
542
545
|
}
|
543
|
-
|
544
|
-
return toggleDevTools();
|
545
|
-
});
|
546
|
-
app.on('activate', function () {
|
547
|
-
if (win == null || (BrowserWindow.getAllWindows().length === 0)) createWindow()
|
548
|
-
});
|
549
|
-
});
|
546
|
+
}
|
package/electron/init/main.js
CHANGED
@@ -8,6 +8,7 @@
|
|
8
8
|
*/
|
9
9
|
|
10
10
|
module.exports = {
|
11
|
+
enableSingleInstance: true, // si l'application n'autorise qu'une seule instance active. ça sous entend qu'à l'instant t, une seule instance de l'application ne peut être exécutée sur le profil de l'utilisateur lambda
|
11
12
|
/**** cette fonction est appelée à chaque fois que l'on désire créer une instance du BrowserWindow
|
12
13
|
@param {object} BrowserWindowOptions
|
13
14
|
Lors de la création de la fenêtre principal, BrowserWindowOptions continent la propriété isMainWindow à true
|