@fto-consult/expo-ui 7.5.2 → 7.5.3
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 +37 -23
- package/electron/index.js +54 -22
- package/electron/init/main.js +25 -2
- package/electron/preload.js +23 -1
- package/electron/utils/config.js +0 -1
- package/electron/utils/session.js +1 -1
- package/package.json +1 -1
- package/src/context/Provider.js +6 -1
package/bin/index.js
CHANGED
@@ -44,19 +44,21 @@ program.command('generate-getTable')
|
|
44
44
|
|
45
45
|
program.command('electron')
|
46
46
|
.description('utilitaire cli pour la plateforme electron. NB : Le package electron doit être installé globalement via l\'instruction npm i -g electron')
|
47
|
-
.argument('<cmd>', 'la commande à exécuter (start,init,build)')
|
47
|
+
.argument('<cmd>', 'la commande à exécuter (start,init,build,package). Start permet de démarrer le script electron, init permet d\'initialiser l\'application, build permet de compiler le code expo (exporter), package permet d\'effectuer le packaging de l\'application pour la distribution')
|
48
48
|
//.option('-r, --project-root [dir]', 'le project root de l\'application')
|
49
|
-
|
49
|
+
//.option('-c, --config [dir]', 'le chemin (relatif au project root) du fichier de configuration de l\'application electron')
|
50
50
|
//.option('-s, --splash [dir]', 'le chemin (relatif au project root) du fichier du splash screen de l\'application')
|
51
|
-
.option('-o, --out [dir]', 'le chemin
|
52
|
-
.option('-u, --url [url]', 'le lien url qui sera ouvert par l\'application')
|
53
|
-
.option('-b, --build [boolean]', 'si ce flag est spécfifié alors l\'application sera compilée')
|
54
|
-
.option('-a, --arch [architecture]', 'l\'architecture de la plateforme')
|
55
|
-
.option('-p, --platform [platform]', 'la plateforme à utiliser pour la compilation')
|
51
|
+
.option('-o, --out [dir]', 'le chemin du répertoire qui contiendra les fichiers build, des fichiers du exporté par le framework expo; commande : build|start')
|
52
|
+
.option('-u, --url [url]', 'le lien url qui sera ouvert par l\'application; commande start')
|
53
|
+
.option('-b, --build [boolean]', 'si ce flag est spécfifié alors l\'application sera compilée; combinée avec la commande start pour indiquer que l\'application sera à nouveau exportée ou pas.')
|
54
|
+
.option('-a, --arch [architecture]', 'l\'architecture de la plateforme; Commande package')
|
55
|
+
.option('-p, --platform [platform]', 'la plateforme à utiliser pour la compilation; commande package')
|
56
|
+
.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')
|
57
|
+
|
56
58
|
.action((script, options) => {
|
57
59
|
const electronProjectRoot = path.resolve(projectRoot,"electron");
|
58
60
|
const opts = Object.assign({},typeof options.opts =='function'? options.opts() : options);
|
59
|
-
let {out,arch,url,build,platform} = opts;
|
61
|
+
let {out,arch,url,build,platform,import:packageImport} = opts;
|
60
62
|
//let {projectRoot} = opts;
|
61
63
|
if(projectRoot == dir){
|
62
64
|
throwError(`Invalid project root ${projectRoot}; project root must be different to ${dir}`);
|
@@ -168,21 +170,33 @@ program.command('electron')
|
|
168
170
|
break;
|
169
171
|
case "build":
|
170
172
|
break;
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
173
|
+
case "package" :
|
174
|
+
if(packageImport || opts.import){ //on importe le projet existant electron forge, @see : https://www.electronforge.io/import-existing-project
|
175
|
+
console.log("importing electron forge existing project....");
|
176
|
+
cmd = "npm install --save-dev @electron-forge/cli";
|
177
|
+
return exec({cmd,projectRoot:electronProjectRoot}).then(()=>{
|
178
|
+
cmd = `npm exec --package=@electron-forge/cli -c "electron-forge import"`;
|
179
|
+
return exec({cmd,projectRoot:electronProjectRoot}).then(()=>{
|
180
|
+
console.log("package electron forge importé avec succèss");
|
181
|
+
})
|
182
|
+
}).catch(reject);
|
183
|
+
|
184
|
+
} else {
|
185
|
+
const electronPackage = require(`${path.resolve(electronProjectRoot,'package.json')}`);
|
186
|
+
electronPackage.name = packageObj.name;
|
187
|
+
electronPackage.version = packageObj.version;
|
188
|
+
//copying package json in build folder
|
189
|
+
writeFile(path.resolve(electronProjectRoot,"package.json"),JSON.stringify(electronPackage,null,"\t"));
|
190
|
+
platform = platform || process.platform;
|
191
|
+
console.log("packaing app from ",electronProjectRoot);
|
192
|
+
return require("./package")({
|
193
|
+
src : electronProjectRoot,
|
194
|
+
dist : path.resolve(outDir,platform),
|
195
|
+
platform,
|
196
|
+
arch : arch || undefined,
|
197
|
+
projectRoot : electronProjectRoot,
|
198
|
+
});
|
199
|
+
}
|
186
200
|
break;
|
187
201
|
}
|
188
202
|
}).catch((e)=>{
|
package/electron/index.js
CHANGED
@@ -61,21 +61,12 @@ const clipboadContextMenu = (_, props) => {
|
|
61
61
|
const log = (message)=>{
|
62
62
|
return win != null && win && win.webContents.send("console.log",message);
|
63
63
|
}
|
64
|
-
|
65
|
-
theme = theme && typeof theme == "string"? theme : "light";
|
66
|
-
theme = theme.toLowerCase().trim();
|
67
|
-
if(theme !== 'system' && theme !=='dark'){
|
68
|
-
theme = "light";
|
69
|
-
}
|
70
|
-
nativeTheme.themeSource = theme;
|
71
|
-
session.set("os-theme",theme);
|
72
|
-
return nativeTheme.shouldUseDarkColors
|
73
|
-
}
|
74
|
-
setOSTheme(session.get("os-theme"));
|
64
|
+
|
75
65
|
const isObj = x => x && typeof x =='object';
|
76
66
|
|
77
67
|
|
78
68
|
function createBrowserWindow (options){
|
69
|
+
const {isMainWindow} = options;
|
79
70
|
options = Object.assign({},options);
|
80
71
|
let menu = options.menu;
|
81
72
|
options.webPreferences = isObj(options.webPreferences)? options.webPreferences : {};
|
@@ -131,6 +122,9 @@ function createBrowserWindow (options){
|
|
131
122
|
});
|
132
123
|
}
|
133
124
|
_win.on('closed', function() {
|
125
|
+
if(isMainWindow && typeof mainProcess.onMainWindowClosed == "function"){
|
126
|
+
mainProcess.onMainWindowClosed(_win);
|
127
|
+
}
|
134
128
|
_win = null;
|
135
129
|
});
|
136
130
|
return _win;
|
@@ -140,6 +134,7 @@ function createWindow () {
|
|
140
134
|
win = createBrowserWindow({
|
141
135
|
showOnLoad : false,
|
142
136
|
loadURL : undefined,
|
137
|
+
isMainWindow : true,
|
143
138
|
registerDevToolsCommand : false,
|
144
139
|
preload : path.resolve(__dirname,'preload.js'),
|
145
140
|
webPreferences : {
|
@@ -177,9 +172,11 @@ function createWindow () {
|
|
177
172
|
win.webContents.send("main-window-blur");
|
178
173
|
}
|
179
174
|
});
|
180
|
-
|
181
|
-
|
175
|
+
|
182
176
|
win.once("ready-to-show",function(){
|
177
|
+
if(typeof mainProcess.onMainWindowReadyToShow ==='function'){
|
178
|
+
mainProcess.onMainWindowReadyToShow(win);
|
179
|
+
}
|
183
180
|
win.minimize()
|
184
181
|
try {
|
185
182
|
if(splash && splash instanceof BrowserWindow){
|
@@ -193,6 +190,9 @@ function createWindow () {
|
|
193
190
|
|
194
191
|
win.on('close', (e) => {
|
195
192
|
if (win) {
|
193
|
+
if(typeof mainProcess.onMainWindowClose == "function"){
|
194
|
+
mainProcess.onMainWindowClose(win);
|
195
|
+
}
|
196
196
|
e.preventDefault();
|
197
197
|
win.webContents.send('before-app-exit');
|
198
198
|
}
|
@@ -264,8 +264,8 @@ function createWindow () {
|
|
264
264
|
win.on('resize',onWinResizeEv);
|
265
265
|
win.off('move',onWinResizeEv);
|
266
266
|
win.on('move',onWinResizeEv);
|
267
|
-
if(
|
268
|
-
mainProcess.
|
267
|
+
if(typeof mainProcess.onCreateMainWindow =='function'){
|
268
|
+
mainProcess.onCreateMainWindow(win);
|
269
269
|
}
|
270
270
|
return win;
|
271
271
|
}
|
@@ -307,11 +307,9 @@ ipcMain.on("toggle-dev-tools",function(event,value) {
|
|
307
307
|
|
308
308
|
|
309
309
|
app.whenReady().then(() => {
|
310
|
-
const readOpts = {toggleDevTools,
|
311
|
-
if(typeof mainProcess.
|
312
|
-
mainProcess.
|
313
|
-
} else if(typeof mainProcess.appOnReady =='function'){
|
314
|
-
mainProcess.appOnReady(readOpts);
|
310
|
+
const readOpts = {toggleDevTools,browserWindow:win,mainWindow:win};
|
311
|
+
if(typeof mainProcess.whenAppReady =='function'){
|
312
|
+
mainProcess.whenAppReady(readOpts);
|
315
313
|
}
|
316
314
|
globalShortcut.register('CommandOrControl+F12', () => {
|
317
315
|
toggleDevTools();
|
@@ -387,7 +385,7 @@ ipcMain.on("get-paths.json",(event)=>{
|
|
387
385
|
});
|
388
386
|
|
389
387
|
ipcMain.on("get-app-name",(event)=>{
|
390
|
-
event.returnValue = packageJSON.name;
|
388
|
+
event.returnValue = packageJSON.realAppName || packageJSON.name;
|
391
389
|
return event.returnValue ;
|
392
390
|
});
|
393
391
|
|
@@ -533,7 +531,7 @@ ipcMain.on("is-dev-tools-open",function(event,value) {
|
|
533
531
|
return win.webContents.isDevToolsOpened();
|
534
532
|
}
|
535
533
|
return false;
|
536
|
-
})
|
534
|
+
});
|
537
535
|
|
538
536
|
|
539
537
|
ipcMain.on("window-set-progressbar",(event,interval)=>{
|
@@ -544,7 +542,41 @@ ipcMain.on("window-set-progressbar",(event,interval)=>{
|
|
544
542
|
}
|
545
543
|
})
|
546
544
|
|
545
|
+
const setOSTheme = (theme) => {
|
546
|
+
theme = theme && typeof theme == "string"? theme : "light";
|
547
|
+
theme = theme.toLowerCase().trim();
|
548
|
+
if(theme !== 'system' && theme !=='dark'){
|
549
|
+
theme = "light";
|
550
|
+
}
|
551
|
+
nativeTheme.themeSource = theme;
|
552
|
+
session.set("os-theme",theme);
|
553
|
+
return nativeTheme.shouldUseDarkColors
|
554
|
+
}
|
555
|
+
|
547
556
|
/**** customisation des thèmes de l'application */
|
548
557
|
ipcMain.handle('set-system-theme:toggle', (event,theme) => {
|
549
558
|
return setOSTheme(theme);
|
559
|
+
});
|
560
|
+
|
561
|
+
ipcMain.handle('set-system-theme:dark-mode', (event) => {
|
562
|
+
nativeTheme.themeSource = 'dark';
|
563
|
+
return nativeTheme.shouldUseDarkColors;
|
564
|
+
});
|
565
|
+
ipcMain.handle('set-system-theme:light-mode', (event) => {
|
566
|
+
nativeTheme.themeSource = 'light';
|
567
|
+
return nativeTheme.shouldUseDarkColors;
|
568
|
+
});
|
569
|
+
|
570
|
+
|
571
|
+
ipcMain.handle('dark-mode:toggle', () => {
|
572
|
+
if (nativeTheme.shouldUseDarkColors) {
|
573
|
+
nativeTheme.themeSource = 'light'
|
574
|
+
} else {
|
575
|
+
nativeTheme.themeSource = 'dark'
|
576
|
+
}
|
577
|
+
return nativeTheme.shouldUseDarkColors
|
578
|
+
})
|
579
|
+
|
580
|
+
ipcMain.handle('dark-mode:system', () => {
|
581
|
+
nativeTheme.themeSource = 'system'
|
550
582
|
});
|
package/electron/init/main.js
CHANGED
@@ -8,6 +8,25 @@
|
|
8
8
|
*/
|
9
9
|
|
10
10
|
module.exports = {
|
11
|
+
/**** cette fonction est appelée à chaque fois que l'on désire créer une instance du BrowserWindow
|
12
|
+
@param {object} BrowserWindowOptions
|
13
|
+
Lors de la création de la fenêtre principal, BrowserWindowOptions continent la propriété isMainWindow à true
|
14
|
+
la prop isMainWindow {boolean} spécifie s'il s'agit de la fenêtre principale
|
15
|
+
la prop isPDFWindow {boolean}, spécifie s'il s'agit de la fenêtre destinée à l'affichage d'un fichier pdf
|
16
|
+
*/
|
17
|
+
beforeCreateWindow : function({isMainWindow,isPDFWindow,...BrowserWindowOptions}){},
|
18
|
+
/*** exécutée lorsque l'évènement ready-to-show de la fenêtre principale BrowserWindow est appelée
|
19
|
+
@param {Instance of BrowserWindow} mainBrowserWindow
|
20
|
+
*/
|
21
|
+
onMainWindowReadyToShow : function(mainBrowserWindow){},
|
22
|
+
/**** exécutée lorsque l'évènement close de la fenêtre principale est appelée
|
23
|
+
@param {Instance of BrowserWindow} mainBrowserWindow
|
24
|
+
*/
|
25
|
+
onMainWindowClose : function(mainBrowserWindow){},
|
26
|
+
/**** exécutée lorsque l'évènement closed de la fenêtre principale est appélée
|
27
|
+
@param {InstanceOf BrowserWindow} mainBrowserWindow
|
28
|
+
*/
|
29
|
+
onMainWindowClosed : function(mainBrowserWindow){},
|
11
30
|
/*****
|
12
31
|
must return an Instance of Browser window
|
13
32
|
width: 500, height: 400, transparent: true, frame: false, alwaysOnTop: true
|
@@ -19,9 +38,13 @@ module.exports = {
|
|
19
38
|
},
|
20
39
|
/*** this function is called when app is ready
|
21
40
|
toggleDevTools : {function},la fonction permettant de toggle les outils de developements
|
22
|
-
|
41
|
+
browserWindow|mainWindow : {BrowserWindow}, le browser window principal de l'application
|
42
|
+
*/
|
43
|
+
whenAppReady : function({toggleDevTools,browserWindow,mainWindow}){},
|
44
|
+
/*** exécutée une fois que la fonction createWindow est appelée pour créer le main Browser window de l'application
|
45
|
+
@param {InstanceOf BrowserWindow} mainBrowserWindow
|
23
46
|
*/
|
24
|
-
|
47
|
+
onCreateMainWindow : function(mainBrowserWindow){
|
25
48
|
|
26
49
|
}
|
27
50
|
}
|
package/electron/preload.js
CHANGED
@@ -389,6 +389,7 @@ const ELECTRON = {
|
|
389
389
|
fileName,
|
390
390
|
pdfFilePath : mainPath,
|
391
391
|
showOnLoad : true,
|
392
|
+
isPDFWindow : true,//spécifie s'il s'agit de la fenêtre pdf
|
392
393
|
webPreferences: {
|
393
394
|
plugins: true
|
394
395
|
}
|
@@ -397,7 +398,28 @@ const ELECTRON = {
|
|
397
398
|
}
|
398
399
|
})
|
399
400
|
}
|
400
|
-
}
|
401
|
+
},
|
402
|
+
get toggleDarkMode(){
|
403
|
+
return ()=>{
|
404
|
+
return ipcRenderer.invoke('dark-mode:toggle');
|
405
|
+
}
|
406
|
+
},
|
407
|
+
get setThemeToSystem (){
|
408
|
+
return ()=>{
|
409
|
+
return ipcRenderer.invoke('dark-mode:system');
|
410
|
+
}
|
411
|
+
},
|
412
|
+
/***** fait passer le theme au mode dark */
|
413
|
+
get setThemeToDark(){
|
414
|
+
return ()=>{
|
415
|
+
return ipcRenderer.invoke('set-system-theme:dark-mode');
|
416
|
+
}
|
417
|
+
},
|
418
|
+
get setThemeToLight(){
|
419
|
+
return ()=>{
|
420
|
+
return ipcRenderer.invoke('set-system-theme:light-mode');
|
421
|
+
}
|
422
|
+
},
|
401
423
|
};
|
402
424
|
|
403
425
|
require("./pload")(ELECTRON,paths || {});
|
package/electron/utils/config.js
CHANGED
package/package.json
CHANGED
package/src/context/Provider.js
CHANGED
@@ -21,7 +21,7 @@ import {canFetchOffline} from "$capi/utils";
|
|
21
21
|
import { SWR_REFRESH_TIMEOUT } from "./utils";
|
22
22
|
import * as Utils from "$cutils";
|
23
23
|
import {setDeviceIdRef} from "$capp";
|
24
|
-
import {isMobileNative} from "$cplatform";
|
24
|
+
import {isMobileNative,isElectron} from "$cplatform";
|
25
25
|
import notify from "$cnotify";
|
26
26
|
import {showPrompt} from "$ecomponents/Dialog/confirm";
|
27
27
|
import {SWRConfig} from "$swr";
|
@@ -186,6 +186,11 @@ const Provider = ({children,getTableData,handleHelpScreen,navigation,swrConfig,a
|
|
186
186
|
const isDark = theme.dark || theme.isDark || isDynamicThemeSupported && isColorShemeDark ;
|
187
187
|
const elevation = defaultObj(theme.elevation,isDark ? pTheme.dark?.elevation : pTheme.light?.elevation)
|
188
188
|
const newTheme = isDark ? { ...MD3DarkTheme, colors: pTheme.dark } : { ...MD3LightTheme, colors: pTheme.light };
|
189
|
+
if(isElectron() && typeof window.ELECTRON =='object' && typeof ELECTRON.setThemeToDark =="function" && typeof ELECTRON.setThemeToLight =="function"){
|
190
|
+
if(isDark){
|
191
|
+
ELECTRON.setThemeToDark();
|
192
|
+
} else ELECTRON.setThemeToLight();
|
193
|
+
}
|
189
194
|
for(let i in newTheme){
|
190
195
|
if(i !== 'colors' && !(i in theme)){
|
191
196
|
theme[i] = newTheme[i];
|