@fto-consult/expo-ui 7.5.34 → 7.5.35

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