@fto-consult/expo-ui 3.6.1 → 4.0.1

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.
@@ -1,14 +1,30 @@
1
1
  const getDirName = require('path').dirname;
2
2
  const fs = require("fs");
3
- module.exports = function createDir(path) {
3
+ module.exports = function createDir(path,cb) {
4
4
  if(!path || typeof path !='string') return false;
5
5
  const p = getDirName(path);
6
6
  if(!fs.existsSync(p)){
7
7
  try {
8
8
  fs.mkdirSync(p,{ recursive: true});
9
9
  } catch(e){
10
- console.log(e," making write file directory")
10
+ if (e.code === 'EEXIST') { // p already exists!
11
+ return p;
12
+ }
13
+ // To avoid `EISDIR` error on Mac and `EACCES`-->`ENOENT` and `EPERM` on Windows.
14
+ if (e.code === 'ENOENT') { // Throw the original parentDir error on curDir `ENOENT` failure.
15
+ throw new Error(`EACCES: permission denied, mkdir '${path.resolve(p,"..")}'`);
16
+ } else {
17
+ console.log(e," making write file directory")
18
+ }
19
+ /*const caughtErr = ['EACCES', 'EPERM', 'EISDIR'].indexOf(e.code) > -1;
20
+ if (!caughtErr || caughtErr && curDir === path.resolve(targetDir)) {
21
+ throw err; // Throw if it's just the last created dir.
22
+ }*/
11
23
  }
12
24
  }
13
- return fs.existsSync(p);
25
+ const ex = fs.existsSync(p);
26
+ if(ex && typeof cb =='function'){
27
+ cb(p);
28
+ }
29
+ return ex ? p : false;
14
30
  }
@@ -0,0 +1,31 @@
1
+ const path = require("path");
2
+ const getDirName = require('path').dirname;
3
+ const fs = require("fs");
4
+ module.exports = function createDirSync(targetDir, { isRelativeToScript = false } = {}) {
5
+ if(!targetDir || typeof targetDir != 'string') return false;
6
+ const sep = path.sep;
7
+ const initDir = path.isAbsolute(targetDir) ? sep : '';
8
+ const baseDir = isRelativeToScript ? __dirname : '.';
9
+
10
+ return targetDir.split(sep).reduce((parentDir, childDir) => {
11
+ const curDir = path.resolve(baseDir, parentDir, childDir);
12
+ try {
13
+ fs.mkdirSync(curDir);
14
+ } catch (err) {
15
+ if (err.code === 'EEXIST') { // curDir already exists!
16
+ return curDir;
17
+ }
18
+
19
+ // To avoid `EISDIR` error on Mac and `EACCES`-->`ENOENT` and `EPERM` on Windows.
20
+ if (err.code === 'ENOENT') { // Throw the original parentDir error on curDir `ENOENT` failure.
21
+ throw new Error(`EACCES: permission denied, mkdir '${parentDir}'`);
22
+ }
23
+
24
+ const caughtErr = ['EACCES', 'EPERM', 'EISDIR'].indexOf(err.code) > -1;
25
+ if (!caughtErr || caughtErr && curDir === path.resolve(targetDir)) {
26
+ throw err; // Throw if it's just the last created dir.
27
+ }
28
+ }
29
+ return curDir;
30
+ }, initDir);
31
+ }
package/electron/exec.js CHANGED
@@ -31,7 +31,7 @@ const loaderTimer = function(timout) {
31
31
  var P = ["\\", "|", "/", "-"];
32
32
  var x = 0;
33
33
  return setInterval(function() {
34
- process.stdout.write("\r"+text+" "+P[x++]);
34
+ process.stdout.write("\r "+text+P[x++]);
35
35
  x &= 3;
36
36
  }, timout);
37
37
  };
package/electron/index.js CHANGED
@@ -1,13 +1,23 @@
1
1
  const {app, BrowserWindow,Tray,Menu,MenuItem,systemPreferences,powerMonitor,dialog, nativeTheme} = require('electron')
2
- const appConfig = {}//require("../src/app/config");
3
- const session = require("./src/session");
2
+ const appConfig = {}//require("../app/config");
3
+ const session = require("./session");
4
4
  const path = require("path");
5
+ const fs = require("fs");
6
+ const ePath = path.resolve(__dirname);
7
+ if(!fs.existsSync(path.resolve(ePath,"paths.json"))){
8
+ throw {message : 'Chemin de noms, fichier paths.json introuvable!! Exécutez l\'application en enviornnement web|mobile|android|ios puis re-essayez'}
9
+ }
5
10
  const paths = require("./paths.json");
6
11
  const images = paths.$images, assets = paths.$assets, logo = paths.logo;
12
+ const projectRoot = paths.projectRoot || '';
13
+ const electronProjectRoot = projectRoot && fs.existsSync(path.resolve(projectRoot,"electron")) && path.resolve(projectRoot,"electron") || null;
14
+ const mainProcessIndex = electronProjectRoot && fs.existsSync(path.resolve(electronProjectRoot,"main.process.js")) && path.resolve(electronProjectRoot,"main.process.js");
15
+ const mainProcessRequired = mainProcessIndex && require(`${mainProcessIndex}`);
16
+ //pour étendre les fonctionnalités au niveau du main proceess, bien vouloir écrire dans le fichier projectRoot/electron/main.process.js
17
+ const mainProcess = mainProcessRequired && typeof mainProcessRequired =='object'? mainProcessRequired : {};
7
18
  // Gardez une reference globale de l'objet window, si vous ne le faites pas, la fenetre sera
8
19
  // fermee automatiquement quand l'objet JavaScript sera garbage collected.
9
20
  let win = undefined;
10
- let fs = require("fs");
11
21
  const isWindow = process.platform =="win32",
12
22
  isMac = process.platform =='darwin',
13
23
  isLinux = process.platform =="linux";
@@ -75,10 +85,11 @@ function createBrowserWindow (options){
75
85
  let menu = options.menu;
76
86
  options.webPreferences = isObj(options.webPreferences)? options.webPreferences : {}
77
87
  options.webPreferences = {
88
+ sandbox: false,
78
89
  ...options.webPreferences,
90
+ contextIsolation: true,
79
91
  devTools: typeof options.webPreferences.devTools === 'boolean'? options.webPreferences.devTools : false,
80
92
  icon,
81
- contextIsolation: false,
82
93
  webSecurity : true,
83
94
  autoHideMenuBar: true,
84
95
  allowRunningInsecureContent: false,
@@ -103,6 +114,9 @@ function createBrowserWindow (options){
103
114
  if(showOnLoad){
104
115
  options.show = false;
105
116
  }
117
+ if(mainProcess && typeof mainProcess.beforeCreateWindow =='function'){
118
+ mainProcess.beforeCreateWindow(options);
119
+ }
106
120
  let _win = new BrowserWindow(options);
107
121
  if(!menu){
108
122
  _win.setMenu(null);
@@ -124,14 +138,13 @@ function createBrowserWindow (options){
124
138
  });
125
139
  return _win;
126
140
  }
127
-
128
-
141
+ const args = require("./parseArgs")();
129
142
  function createWindow () {
130
143
  // Créer le browser window
131
144
  win = createBrowserWindow({
132
145
  showOnLoad : false,
133
146
  loadURL : undefined,
134
- //preload : path.resolve(__dirname,'src/preload.js'),
147
+ preload : path.resolve(__dirname,'preload.js'),
135
148
  webPreferences : {
136
149
  devTools : true,
137
150
  }
@@ -142,7 +155,7 @@ function createWindow () {
142
155
  width: 500, height: 400, transparent: true, frame: false, alwaysOnTop: true});
143
156
  let copyRight = appConfig.name+" version "+appConfig.version+". "+appConfig.copyRight;
144
157
  copyRight = encodeURI(copyRight);
145
- //splash.loadURL(`file://${__dirname}/src/splash/index.html?copyRight=${copyRight}`);
158
+ //splash.loadURL(`file://${__dirname}/splash/index.html?copyRight=${copyRight}`);
146
159
  let hasInitWindows = false;
147
160
  win.on('show', () => {
148
161
  //win.blur();
@@ -183,7 +196,11 @@ function createWindow () {
183
196
  win.webContents.send('before-app-exit');
184
197
  }
185
198
  });
186
- win.loadFile(path.resolve(path.join(__dirname,"dist",'index.html')))
199
+ if(args.url){
200
+ win.loadURL(args.url);
201
+ } else {
202
+ win.loadFile(path.resolve(path.join(__dirname,"dist",'index.html')))
203
+ }
187
204
 
188
205
  win.on('unresponsive', async () => {
189
206
  const { response } = await dialog.showMessageBox({
@@ -446,14 +463,25 @@ ipcMain.handle("electron-show-save-dialog",function(event,options){
446
463
  }
447
464
  return dialog.showSaveDialog(win,options)
448
465
  })
466
+ ipcMain.on("electron-is-dev-tools-open",function(event,value) {
467
+ if(win !==null && win.webContents){
468
+ return win.webContents.isDevToolsOpened();
469
+ }
470
+ return false;
471
+ })
449
472
  ipcMain.on("electron-toggle-dev-tools",function(event,value) {
450
473
  if(win !==null && win.webContents){
451
- if(value){
452
- if(!win.webContents.isDevToolsOpened()) win.webContents.openDevTools();
474
+ const isOpen= win.webContents.isDevToolsOpened();
475
+ value = value === undefined ? !isOpen : value;
476
+ if(value && !isOpen){
477
+ win.webContents.openDevTools();
478
+ return win.webContents.isDevToolsOpened();
453
479
  } else {
454
- if(win.webContents.isDevToolsOpened()) win.webContents.closeDevTools();
480
+ if(isOpen) win.webContents.closeDevTools();
455
481
  }
482
+ return win.webContents.isDevToolsOpened();
456
483
  }
484
+ return false;
457
485
  })
458
486
 
459
487
  ipcMain.on("electron-window-set-progressbar",(event,interval)=>{
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "sage-ftc",
3
+ "version": "1.0.0",
4
+ "description": "Accès distant aux données commerciales et comptables Sage100C de partout",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "test",
8
+ "start": "npx expo start",
9
+ "start-c": "npx expo start -c",
10
+ "build": "npx expo export:web",
11
+ "electron": "npx ./expo-ui start electron",
12
+ "build-android": "eas build --clear-cache -p android --profile preview",
13
+ "delete-node-modules": "rimraf ./**/node_modules"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/borispipo/sage-ftc.git"
18
+ },
19
+ "keywords": [
20
+ "XposeFTC",
21
+ "Sage100C",
22
+ "Accès",
23
+ "distant"
24
+ ],
25
+ "author": "BorisFouomene@fto-consulting",
26
+ "license": "UNLICENCED",
27
+ "bugs": {
28
+ "url": "https://github.com/borispipo/sage-ftc/issues"
29
+ },
30
+ "homepage": "./",
31
+ "dependencies": {
32
+ "@fto-consult/expo-ui": "^3.2.0",
33
+ "react-native": "0.70.5"
34
+ },
35
+ "devDependencies": {
36
+ "@babel/plugin-proposal-export-namespace-from": "^7.18.9",
37
+ "@babel/preset-react": "^7.18.6",
38
+ "@expo/metro-config": "^0.5.2",
39
+ "@expo/webpack-config": "^0.17.3",
40
+ "babel-plugin-inline-dotenv": "^1.7.0",
41
+ "babel-plugin-module-resolver": "^4.1.0",
42
+ "babel-plugin-transform-inline-environment-variables": "^0.4.4"
43
+ }
44
+ }
@@ -1,10 +1,13 @@
1
1
  module.exports = (argv,supportedScript)=>{
2
+ if(!Array.isArray(argv)) {
3
+ argv = process.argv.slice(2);
4
+ }
2
5
  const args = {};
3
- if(!Array.isArray(argv) || !supportedScript || typeof supportedScript !=='object') return {};
6
+ supportedScript = typeof supportedScript =='object' && supportedScript || null;
4
7
  argv.map(arg=>{
5
8
  if(!arg || typeof arg != 'string') return;
6
9
  arg = arg.trim();
7
- if(arg in supportedScript){
10
+ if(supportedScript && arg in supportedScript){
8
11
  args.script = arg;
9
12
  } else if(arg.includes("=")){
10
13
  const split = arg.split("=");
@@ -1,13 +1,16 @@
1
- module.exports = (ELECTRON)=>{
2
- let isWin = process.platform === "win32"? true : false;
3
- let isLinux = process.platform === "linux"? true : false;
4
- let {ipcRenderer} = require("electron");
5
- let os = require("os");
1
+ const { machineIdSync} = require('node-machine-id');
2
+ const fs = require("fs");
3
+ const path = require("path");
4
+ module.exports = (ELECTRON,paths)=>{
5
+ const isWin = process.platform === "win32"? true : false;
6
+ const isLinux = process.platform === "linux"? true : false;
7
+ const {ipcRenderer} = require("electron");
8
+ const os = require("os");
6
9
  let totalRAM = os.totalmem();
7
10
  if(typeof totalRAM !=="number"){
8
11
  totalRAM = 0;
9
12
  }
10
- let getMem = (unit,key)=>{
13
+ const getMem = (unit,key)=>{
11
14
  let memory = 0;
12
15
  if(typeof os[key] =="function"){
13
16
  memory = os[key]();
@@ -27,7 +30,7 @@ module.exports = (ELECTRON)=>{
27
30
  }
28
31
  return memory;
29
32
  }
30
- APP.extend(ELECTRON,{
33
+ const ext = {
31
34
  toggleDevTools : (value)=>{
32
35
  ipcRenderer.send("electron-toggle-dev-tools",defaultBool(value,true));
33
36
  },
@@ -76,22 +79,32 @@ module.exports = (ELECTRON)=>{
76
79
  'download-progress',
77
80
  'update-downloaded'
78
81
  ],
79
- })
80
- const username = require('username');
81
- let { machineIdSync} = require('node-machine-id');
82
+ };
83
+ for(var i in ext){
84
+ ELECTRON[i] = ext[i];
85
+ }
82
86
  if(process.env && typeof process.env =="object"){
83
- let logName = process.env["LOGNAME"] || process.env["USER"];
87
+ const logName = process.env["LOGNAME"] || process.env["USER"];
84
88
  if(logName && typeof logName =="string"){
85
89
  ELECTRON.DEVICE.computerUserName = logName;
86
90
  }
87
91
  }
88
- let uuid = machineIdSync({original: true});
92
+ const uuid = machineIdSync({original: true});
89
93
  if(uuid && typeof uuid =='string') ELECTRON.DEVICE.uuid = uuid;
90
-
91
- username().then((u)=>{
92
- if(u && typeof u =="string"){
93
- ELECTRON.DEVICE.computerUserName = u;
94
- }
95
- });
94
+
95
+ ELECTRON.DEVICE.computerUserName = process.env.SUDO_USER ||
96
+ process.env.C9_USER ||
97
+ process.env.LOGNAME ||
98
+ process.env.USER ||
99
+ process.env.LNAME ||
100
+ process.env.USERNAME || '';
101
+
102
+ const projectRoot = (paths || {}).projectRoot;
103
+ const electronProjectRoot = projectRoot && fs.existsSync(path.resolve(projectRoot,"electron")) && path.resolve(projectRoot,"electron") || null;
104
+ const rendererProcessIndex = electronProjectRoot && fs.existsSync(path.resolve(electronProjectRoot,"renderer.process.js")) && path.resolve(electronProjectRoot,"renderer.process.js");
105
+ //pour étendre les fonctionnalités au niveau du renderer proceess, bien vouloir écrire dans le fichier projectRoot/electron/renderer.process.js
106
+ // dans lequel exporter une fonction prenant en paramètre l'objet electron, que l'on peut étendre et le rendre accessible depuis l'application
107
+ const rendererProcess = rendererProcessIndex && require(`${rendererProcessIndex}`);
108
+ (typeof rendererProcess ==='function') && rendererProcess(ELECTRON);
96
109
  return ELECTRON;
97
110
  }
@@ -0,0 +1,19 @@
1
+ /****
2
+ * envoie un message au client à travers la fonction postMessage de window, le message envoyé sera de la forme :
3
+ * {
4
+ * message : ELECTRON_MESSAGE/{message en question},
5
+ * callback : {function}, la fonction de rappel
6
+ * params : {array}, les paramètres supplémentaires à la fonction
7
+ * }
8
+ * @param message {string|object} le message à envoyer au client web
9
+ * @param [...params], le reste des paramètres
10
+ */
11
+ module.exports = function(message,...params){
12
+ message = typeof message =='string' ? {message} : message;
13
+ const opts = message && typeof message =='object' && !Array.isArray(message) ? message : {};
14
+ message = opts.message;
15
+ if(!message || typeof message !='string') return null;
16
+ opts.params = Array.isArray(opts.params) && opts.params || Array.isArray(params) && params || [];
17
+ opts.message = "ELECTRON_MESSAGE/"+message.trim();
18
+ return window.postMessage(opts);
19
+ }
@@ -0,0 +1,333 @@
1
+ const createDir = require("./createDir");
2
+ const postMessage = require("./postMessage");
3
+ const { contextBridge, ipcRenderer, shell } = require('electron')
4
+ const appInstance = require("./app/instance");
5
+ const path = require("path");
6
+ const fs = require("fs");
7
+ const isObj = x=>x && typeof x =='object' && !Array.isArray(x);
8
+ const isNonNullString = x=>x && typeof x =='string';
9
+ const ePath = path.resolve(__dirname);
10
+ const packagePath = path.resolve(ePath,"package.app.json");
11
+ if(!fs.existsSync(packagePath)){
12
+ throw {message : "Chemin du fichier "+packagePath+ " introuvable"};
13
+ }
14
+ const _app = require(`${packagePath}`);
15
+ if(!_app || typeof _app !=='object' || typeof _app.name !=='string'){
16
+ throw {message : "Contenu du fichier "+packagePath+" invalide!! Veuillez spécifier un nom valide d'application, propriété <<name>> dudit fichier"}
17
+ }
18
+ const paths = require("./paths.json");
19
+ const projectRoot = paths.projectRoot || '';
20
+ const APP_NAME = _app.name.trim().toUpperCase();
21
+ let backupPathField = "_e_backupDataPath";
22
+ let cBackupPathField = "company"+backupPathField;
23
+ let dbPathField = "_electron_DBPathField";
24
+ const getPath = function(pathName){
25
+ if(typeof pathName !=='string' || !pathName) return;
26
+ return ipcRenderer.sendSync("electron-get-path",pathName);
27
+ }
28
+ const APP_PATH = path.join(getPath("appData"),APP_NAME).toLowerCase();
29
+ let databasePath = path.join(APP_PATH,"databases");
30
+ let ROOT_APP_FOLDER = undefined;
31
+ const separator = (path.sep)
32
+ if(typeof separator != 'string' || !separator){
33
+ separator = (()=>{
34
+ let filePath = databasePath;
35
+ var sepIndex = filePath.lastIndexOf('/');
36
+ if(sepIndex == -1){
37
+ sepIndex = filePath.lastIndexOf('\\');
38
+ }
39
+ // include the trailing separator
40
+ return filePath.substring(0, sepIndex+1);
41
+ })();
42
+ }
43
+ const Config = require('./config');
44
+ let confPath = process.env.ProgramData || process.env.ALLUSERSPROFILE;
45
+ if(confPath && typeof confPath =="string"){
46
+ if(fs.existsSync(confPath)){
47
+ confPath = path.join(confPath,APP_NAME);
48
+ if(createDir(confPath)){
49
+ ROOT_APP_FOLDER = confPath;
50
+ databasePath = path.join(confPath,"databases");
51
+ createDir(databasePath);
52
+ confPath = path.join(confPath,"CONFIG");
53
+ createDir(confPath);
54
+ }
55
+ } else confPath = undefined;
56
+ } else confPath = undefined;
57
+ const config = new Config({cwd:confPath});
58
+
59
+ const getDatabasePath = ()=>{
60
+ const p = config.get(dbPathField);
61
+ if(fs.existsSync(p)){
62
+ databasePath = p
63
+ }
64
+ if(!fs.existsSync(databasePath)){
65
+ createDir(databasePath);
66
+ }
67
+ return databasePath;
68
+ }
69
+ const setDatabasePath = (newPath)=>{
70
+ config.set(dbPathField,newPath)
71
+ };
72
+ const setBackupPath = (newPath)=>{
73
+ newPath = typeof newPath =='string' && newPath || typeof ROOT_APP_FOLDER =='string' && ROOT_APP_FOLDER || path.join(getPath("documents"),APP_NAME);
74
+ ELECTRON.APP_BACKUP_PATH = newPath;
75
+ config.set(cBackupPathField,ELECTRON.APP_BACKUP_PATH)
76
+ };
77
+ const APPRef = {
78
+ current : null,
79
+ };
80
+ ///invoke event name
81
+ const ipcInvoke = async (eventName, ...params)=> {
82
+ return await ipcRenderer.invoke(eventName, ...params);
83
+ }
84
+ const validChannels = ["toMain", "myRenderChannel"];
85
+ const removeListener = (channel, callback) => {
86
+ if (isNonNullString(channel) /*&& validChannels.includes(channel)*/) {
87
+ ipcRenderer.removeListener(channel, callback);
88
+ }
89
+ }, removeAllListeners = (channel) => {
90
+ if (isNonNullString(channel) /*&& validChannels.includes(channel)*/) {
91
+ ipcRenderer.removeAllListeners(channel)
92
+ }
93
+ };
94
+ const ELECTRON = {
95
+ get getPouchdb(){
96
+ return (PouchDB,sqlPouch)=> {
97
+ window.sqlitePlugin = {openDatabase:require('websql')};
98
+ PouchDB.plugin(function CapacitorSqlitePlugin (PouchDB) {
99
+ PouchDB.adapter('node-sqlite', sqlPouch(), true)
100
+ });
101
+ return {adapter:"node-sqlite"};
102
+ };
103
+ },
104
+ get getBackupPath(){
105
+ return (p)=>{
106
+ const eePath = config.get(cBackupPathField);
107
+ const defPath = ROOT_APP_FOLDER || path.join(getPath("documents"),APP_NAME);
108
+ ELECTRON.APP_BACKUP_PATH = typeof eePath =='string' && eePath || typeof defPath =='string' && defPath || '';
109
+ if(!fs.existsSync(ELECTRON.APP_BACKUP_PATH)){
110
+ ELECTRON.APP_BACKUP_PATH = defPath;
111
+ }
112
+ if(p && typeof (p) ==='string'){
113
+ return path.join(ELECTRON.APP_BACKUP_PATH,p);
114
+ }
115
+ return ELECTRON.APP_BACKUP_PATH;
116
+ };
117
+ },
118
+ get databasePath (){
119
+ return getDatabasePath();
120
+ },
121
+ get getDatabasePath(){
122
+ return getDatabasePath;
123
+ },
124
+ set databasePath(dPath){
125
+ return setDatabasePath(dPath);
126
+ },
127
+ get setDatabasePath (){
128
+ return setDatabasePath;
129
+ },
130
+ set backupPath (backupPath){
131
+ return setBackupPath(backupPath);
132
+ },
133
+ get setBackupPath (){
134
+ return setBackupPath;
135
+ } ,
136
+ get CONFIG (){
137
+ return config;
138
+ },
139
+ get showOpenDialog(){
140
+ return (options)=>{
141
+ options = typeof options =='object' && options && !Array.isArray(options)? options : {};
142
+ return ipcRenderer.invoke("electron-show-open-dialog",options);
143
+ }
144
+ },
145
+ get showSaveDialog(){
146
+ return (options)=>{
147
+ options = typeof options =='object' && options && !Array.isArray(options)? options : {};
148
+ return ipcRenderer.invoke("electron-show-save-dialog",options);
149
+ };
150
+ },
151
+ get restartApp(){
152
+ return ()=>{
153
+ ipcRenderer.sendSync("electron-restart-app")
154
+ };
155
+ },
156
+ get is() {
157
+ return true;
158
+ },
159
+ get APP_PATH(){
160
+ return APP_PATH;
161
+ },
162
+ get initializeAPPInstance(){
163
+ return ({APP,notify})=>{
164
+ ELECTRON.notify = notify;
165
+ ELECTRON.APP = APP;
166
+ }
167
+ },
168
+ get PATH (){
169
+ return {
170
+ SEPARATOR : separator,
171
+ SEP : separator,
172
+ get : getPath,
173
+ HOME : getPath("home"),
174
+ USERDATA : getPath("userData"),
175
+ /***
176
+ * Per-user application data directory, which by default points to:
177
+ * %APPDATA% on Windows
178
+ * $XDG_CONFIG_HOME or ~/.config on Linux
179
+ * ~/Library/Application Support on macOS
180
+ */
181
+ APPDATA : getPath("appData"),
182
+ CACHE : getPath("cache"),
183
+ TEMP : getPath("temp"),//Temporary directory.
184
+ EXECUTABLE : getPath("exe"),//The current executable file.
185
+ EXE : getPath("exe"),//The current executable file.
186
+ DOCUMENTS : getPath("documents"),
187
+ DOWNLOADS : path.join(APP_PATH,"downloads"),
188
+ DESKTOP : getPath("desktop"),//The current user's Desktop directory.
189
+ }
190
+ },
191
+ ///retourne le chemin dont la chaine de caractère est passé en paramètre
192
+ get getPath(){
193
+ return getPath;
194
+ },
195
+ get updateSystemTheme(){
196
+ return (theme)=>{
197
+ return ipcRenderer.invoke("electron-set-system-theme:toggle",theme);
198
+ };
199
+ },
200
+ get SESSION (){
201
+ return {
202
+ set : (key,value) =>{
203
+ return config.set(key,value);
204
+ },
205
+ get : (key) =>{
206
+ return config.get(key);
207
+ }
208
+ };
209
+ },
210
+ get on (){
211
+ return (eventName, callback)=> {
212
+ console.log(eventName," is evname eee",callback);
213
+ return ipcRenderer.on(eventName, callback)
214
+ };
215
+ },
216
+ get shellOpenExternal(){
217
+ return async (url)=> {
218
+ await shell.openExternal(url)
219
+ }
220
+ },
221
+ get shellOpenPath(){
222
+ return async (file)=> {
223
+ await shell.openPath(file)
224
+ };
225
+ },
226
+ get shellTrashItem(){
227
+ return async (file)=> {
228
+ await shell.trashItem(file)
229
+ };
230
+ },
231
+ get trigger (){
232
+ return (channel, ...data) => {
233
+ if (isNonNullString(channel) /*&& validChannels.includes(channel)*/) {
234
+ ipcRenderer.send(channel);
235
+ }
236
+ };
237
+ },
238
+ get on (){
239
+ return (channel, callback) => {
240
+ if (isNonNullString(channel) /*&& validChannels.includes(channel)*/) {
241
+ // Filtering the event param from ipcRenderer
242
+ const newCallback = (_, data) => callback(data);
243
+ ipcRenderer.on(channel, newCallback);
244
+ }
245
+ };
246
+ },
247
+ get once (){
248
+ return (channel, callback) => {
249
+ if (isNonNullString(channel) /*&& validChannels.includes(channel)*/) {
250
+ const newCallback = (_, data) => callback(data);
251
+ ipcRenderer.once(channel, newCallback);
252
+ }
253
+ };
254
+ },
255
+ get removeListener(){
256
+ return removeListener;
257
+ },
258
+ get removeAllListeners(){
259
+ return removeAllListeners;
260
+ },
261
+ get off (){
262
+ return removeListener;
263
+ },
264
+ get offAll(){
265
+ return removeAllListeners;
266
+ },
267
+ get version(){
268
+ return process.versions.electron;
269
+ },
270
+ get isWindowsStore(){
271
+ return process.windowsStore;
272
+ },
273
+ get versions(){
274
+ return {
275
+ node: () => process.versions.node,
276
+ chrome: () => process.versions.chrome,
277
+ electron: () => process.versions.electron,
278
+ };
279
+ },
280
+ /****@see : https://www.electronjs.org/docs/latest/tutorial/ipc */
281
+ get openFile(){
282
+ return () => ipcRenderer.invoke('dialog:openFile');
283
+ },
284
+ get ping(){
285
+ return () => ipcRenderer.invoke('ping');
286
+ },
287
+ get exitApp (){
288
+ return x=>ipcRenderer.send("close-main-render-process");
289
+ },
290
+ get onGetAppInstance(){
291
+ return (APP)=>{
292
+ appInstance.set(APP);
293
+ }
294
+ },
295
+ get toggleDevTools(){
296
+ return async (toggle)=>{
297
+ return await ipcRenderer.send("electron-toggle-dev-tools",toggle);
298
+ }
299
+ }
300
+ };
301
+
302
+ require("./pload")(ELECTRON,paths || {});
303
+ ELECTRON.getBackupPath();
304
+ //require("./app/index")(ELECTRON)
305
+ //require('v8-compile-cache');
306
+ //require("v8").setFlagsFromString('--expose_gc');
307
+
308
+ ipcRenderer.on('before-app-exit', () => {
309
+ return postMessage("BEFORE_EXIT");
310
+ });
311
+
312
+ ipcRenderer.on("main-app-suspended",()=>{
313
+ postMessage({
314
+ message : "STOP_IDLE",
315
+ });
316
+ })
317
+ ipcRenderer.on("main-app-restaured",()=>{
318
+ postMessage({
319
+ message : "TRACK_IDLE",
320
+ });
321
+ });
322
+ ipcRenderer.on('appReady',()=>{})
323
+ ipcRenderer.on("main-window-focus",()=>{
324
+ postMessage("WINDOW_FOCUS");
325
+ })
326
+ ipcRenderer.on("main-window-blur",()=>{
327
+ postMessage("WINDOW_BLUR");
328
+ });
329
+
330
+ process.once('loaded', () => {
331
+ contextBridge.exposeInMainWorld('isElectron',true);
332
+ contextBridge.exposeInMainWorld('ELECTRON',ELECTRON);
333
+ })