@fto-consult/expo-ui 3.0.0 → 3.1.0

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,4 +1,5 @@
1
1
  const path = require("path");
2
+ const fs = require("fs");
2
3
  module.exports = (opts)=>{
3
4
  const dir = path.resolve(__dirname);
4
5
  const base = opts.base || process.cwd();
@@ -110,5 +111,22 @@ module.exports = (opts)=>{
110
111
  nodeModulesPath : path.resolve(root,"node_modules"),
111
112
  outputPath
112
113
  });
114
+ const $assets = r.$assets;
115
+ const electronPaths = {
116
+ assets : $assets,
117
+ images : r.$images,
118
+ projectRoot : base,//la racine au projet
119
+ };
120
+ const electronAssetsPath = path.resolve(dir,"electron","assets");
121
+ if($assets){
122
+ const l1 = path.resolve($assets,"logo.png"), l2 = path.resolve($assets,"images","logo.png");
123
+ const logoPath = fs.existsSync(l1)? l1 : fs.existsSync(l2)? l2 : undefined;
124
+ if(logoPath){
125
+ fs.copyFileSync(logoPath,path.resolve(electronAssetsPath,"images","logo.png"),fs.constants.COPYFILE_FICLONE);
126
+ electronPaths.logo = logoPath;
127
+ }
128
+ }
129
+ ///on sauvegarde les chemins des fichiers utiles, qui seront utilisées par la variable electron plus tard
130
+ require("./writeFile")(path.resolve(dir,"electron","paths.json"),JSON.stringify(electronPaths));
113
131
  return r;
114
132
  }
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env node
2
+ /**@see : https://blog.shahednasser.com/how-to-create-a-npx-tool/ */
3
+ 'use strict';
4
+ process.on('unhandledRejection', err => {
5
+ throw err;
6
+ });
7
+ const spawnAsync = require('cross-spawn').spawn;
8
+ const { realpathSync } = require('fs-extra');
9
+
10
+ //const { ensureMinProjectSetupAsync } = require('../build/Config');
11
+
12
+ const args = process.argv.slice(2);
13
+
14
+ const scriptIndex = args.findIndex(x => x === 'start' || x === 'customize');
15
+ const script = scriptIndex === -1 ? args[0] : args[scriptIndex];
16
+ const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];
17
+ console.log(args," is argggggg",script);
18
+ if (['start', 'customize'].includes(script)) {
19
+ spawnAsync(
20
+ 'node',
21
+ nodeArgs.concat(require.resolve('./scripts/' + script)).concat(args.slice(scriptIndex + 1)),
22
+ { stdio: 'inherit' }
23
+ ).then(result => {
24
+ if (result.signal) {
25
+ if (result.signal === 'SIGKILL') {
26
+ console.log(
27
+ 'The build failed because the process exited too early. ' +
28
+ 'This probably means the system ran out of memory or someone called ' +
29
+ '`kill -9` on the process.'
30
+ );
31
+ } else if (result.signal === 'SIGTERM') {
32
+ console.log(
33
+ 'The build failed because the process exited too early. ' +
34
+ 'Someone might have called `kill` or `killall`, or the system could ' +
35
+ 'be shutting down.'
36
+ );
37
+ }
38
+ process.exit(1);
39
+ }
40
+ process.exit(result.status);
41
+ });
42
+ } else if (script === undefined) {
43
+ const projectRoot = realpathSync(process.cwd());
44
+
45
+ //ensureMinProjectSetupAsync(projectRoot);
46
+ } else {
47
+ console.log('Invalid command "' + script + '".');
48
+ }
@@ -4,45 +4,8 @@
4
4
  process.on('unhandledRejection', err => {
5
5
  throw err;
6
6
  });
7
- const spawnAsync = require('cross-spawn').spawn;
8
- const { realpathSync } = require('fs-extra');
9
-
10
- //const { ensureMinProjectSetupAsync } = require('../build/Config');
11
-
12
7
  const args = process.argv.slice(2);
13
8
 
14
- const scriptIndex = args.findIndex(x => x === 'start' || x === 'customize');
15
- const script = scriptIndex === -1 ? args[0] : args[scriptIndex];
16
- const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];
17
- console.log(args," is argggggg",script);
18
- if (['start', 'customize'].includes(script)) {
19
- spawnAsync(
20
- 'node',
21
- nodeArgs.concat(require.resolve('./scripts/' + script)).concat(args.slice(scriptIndex + 1)),
22
- { stdio: 'inherit' }
23
- ).then(result => {
24
- if (result.signal) {
25
- if (result.signal === 'SIGKILL') {
26
- console.log(
27
- 'The build failed because the process exited too early. ' +
28
- 'This probably means the system ran out of memory or someone called ' +
29
- '`kill -9` on the process.'
30
- );
31
- } else if (result.signal === 'SIGTERM') {
32
- console.log(
33
- 'The build failed because the process exited too early. ' +
34
- 'Someone might have called `kill` or `killall`, or the system could ' +
35
- 'be shutting down.'
36
- );
37
- }
38
- process.exit(1);
39
- }
40
- process.exit(result.status);
41
- });
42
- } else if (script === undefined) {
43
- const projectRoot = realpathSync(process.cwd());
9
+ console.log(args," is arggggg");
44
10
 
45
- //ensureMinProjectSetupAsync(projectRoot);
46
- } else {
47
- console.log('Invalid command "' + script + '".');
48
- }
11
+ process.exist();
package/electron/index.js CHANGED
@@ -1,8 +1,7 @@
1
1
  const {app, BrowserWindow,Tray,Menu,MenuItem,systemPreferences,powerMonitor,dialog, nativeTheme} = require('electron')
2
- let appConfig = require("../src/app/config");
3
- let appReady = false;
2
+ const appConfig = {}//require("../src/app/config");
3
+ const session = require("./session");
4
4
  const path = require("path");
5
- const parentDir = path.resolve(__dirname);
6
5
  // Gardez une reference globale de l'objet window, si vous ne le faites pas, la fenetre sera
7
6
  // fermee automatiquement quand l'objet JavaScript sera garbage collected.
8
7
  let win = undefined;
@@ -34,8 +33,7 @@ let clipboadContextMenu = (_, props) => {
34
33
  }
35
34
  };
36
35
 
37
- let Conf = require('./src/config');
38
- let session = new Conf({cwd:app.getPath('userData')});
36
+
39
37
 
40
38
  const setOSTheme = (theme) => {
41
39
  theme = theme && typeof theme == "string"? theme : "light";
@@ -110,7 +108,7 @@ function createWindow () {
110
108
  win = createBrowserWindow({
111
109
  showOnLoad : false,
112
110
  loadURL : undefined,
113
- preload : path.resolve(__dirname,'src/preload.js'),
111
+ //preload : path.resolve(__dirname,'src/preload.js'),
114
112
  webPreferences : {
115
113
  devTools : true,
116
114
  }
@@ -121,7 +119,7 @@ function createWindow () {
121
119
  width: 500, height: 400, transparent: true, frame: false, alwaysOnTop: true});
122
120
  let copyRight = appConfig.name+" version "+appConfig.version+". "+appConfig.copyRight;
123
121
  copyRight = encodeURI(copyRight);
124
- splash.loadURL(`file://${__dirname}/src/splash/index.html?copyRight=${copyRight}`);
122
+ //splash.loadURL(`file://${__dirname}/src/splash/index.html?copyRight=${copyRight}`);
125
123
  let hasInitWindows = false;
126
124
  win.on('show', () => {
127
125
  //win.blur();
@@ -0,0 +1,31 @@
1
+ 'use strict';
2
+ const path = require('path');
3
+ const electron = require('electron');
4
+ const Conf = require('conf');
5
+
6
+ class ElectronStore extends Conf {
7
+ constructor(options) {
8
+ const defaultCwd = "";
9
+
10
+ options = options && typeof options == 'object' ? options : {}
11
+ options = {
12
+ name: 'config',
13
+ ...options
14
+ };
15
+
16
+ if (options.cwd) {
17
+ options.cwd = path.isAbsolute(options.cwd) ? options.cwd : path.join(defaultCwd, options.cwd);
18
+ } else {
19
+ options.cwd = defaultCwd;
20
+ }
21
+ options.configName = options.name;
22
+ delete options.name;
23
+ super(options);
24
+ }
25
+
26
+ openInEditor() {
27
+ electron.shell.openItem(this.path);
28
+ }
29
+ }
30
+
31
+ module.exports = ElectronStore;
@@ -0,0 +1,97 @@
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");
6
+ let totalRAM = os.totalmem();
7
+ if(typeof totalRAM !=="number"){
8
+ totalRAM = 0;
9
+ }
10
+ let getMem = (unit,key)=>{
11
+ let memory = 0;
12
+ if(typeof os[key] =="function"){
13
+ memory = os[key]();
14
+ }
15
+ if(typeof memory !=="number"){
16
+ memory = 0;
17
+ }
18
+ if(!memory) return 0;
19
+ if(typeof unit !=="string") unit = "gb";
20
+ switch(unit.toLowerCase()){
21
+ case "kb" :
22
+ return memory / 1024;
23
+ case "mb" :
24
+ return memory / (1024 * 1024);
25
+ case "gb" :
26
+ return memory / (1024 * 1024 * 1024);
27
+ }
28
+ return memory;
29
+ }
30
+ APP.extend(ELECTRON,{
31
+ toggleDevTools : (value)=>{
32
+ ipcRenderer.send("electron-toggle-dev-tools",defaultBool(value,true));
33
+ },
34
+ gc : x =>{
35
+ if(typeof global.gc =='function') return global.gc();
36
+ return false;
37
+ },
38
+ DEVICE : {
39
+ computerName : os.hostname(),
40
+ operatingSystem : os.type(),
41
+ isWindows : isWin,
42
+ isLinux,
43
+ isMac : process.platform =='darwin'? true : false,
44
+ isDarwin : process.platform =='darwin'? true : false,
45
+ arch : os.arch(),
46
+ totalRAMInGB : totalRAM / (1024 * 1024 * 1024),
47
+ getFreeRAM : (unit)=> getMem(unit,"freemem"),
48
+ getTotalRAM : (unit)=> getMem(unit,'totalmem')
49
+ },
50
+ setTitle : (title) =>{
51
+ if(title && typeof title =="string"){
52
+ ipcRenderer.send("electron-set-main-window-title",title);
53
+ }
54
+ },
55
+ createWindow : (options)=>{
56
+ options = defaultObj(options);
57
+ options.showOnLoad = defaultBool(options.showOnLoad,true);
58
+ return ipcRenderer.invoke("electron-create-browser-windows",options);
59
+ },
60
+ createPDFWindow :(options)=>{
61
+ options = defaultObj(options);
62
+ options.modal = true;
63
+ return ELECTRON.createWindow(options);
64
+ },
65
+ createProgressBar : (options)=>{
66
+ if(!options || typeof options != 'object' || Array.isArray(options)){
67
+ options = {};
68
+ }
69
+ return //new ProgressBar(options,app);
70
+ },
71
+ getAutoUpdaterEvents : ()=> [
72
+ //'checking-for-update',
73
+ 'update-available',
74
+ 'update-not-available',
75
+ 'error',
76
+ 'download-progress',
77
+ 'update-downloaded'
78
+ ],
79
+ })
80
+ const username = require('username');
81
+ let { machineIdSync} = require('node-machine-id');
82
+ if(process.env && typeof process.env =="object"){
83
+ let logName = process.env["LOGNAME"] || process.env["USER"];
84
+ if(logName && typeof logName =="string"){
85
+ ELECTRON.DEVICE.computerUserName = logName;
86
+ }
87
+ }
88
+ let uuid = machineIdSync({original: true});
89
+ 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
+ });
96
+ return ELECTRON;
97
+ }
@@ -0,0 +1,456 @@
1
+ (function(window) {
2
+ let showingExitApp = undefined;
3
+ let sudo = require('sudo-prompt');
4
+ const { exec } = require('child_process');
5
+ if(typeof window.isElectron != 'function'){
6
+ Object.defineProperties(window,{
7
+ ELECTRON : {
8
+ value : {},writable:false,override : false
9
+ },
10
+ isElectron : {
11
+ value : () => true,
12
+ override : false,
13
+ writable : false
14
+ },
15
+ getPouchdbElectron : {
16
+ value : (PouchDB,window,sqlPouch)=> {
17
+ window.sqlitePlugin = {openDatabase:require('websql')};
18
+ PouchDB.plugin(function CapacitorSqlitePlugin (PouchDB) {
19
+ PouchDB.adapter('node-sqlite', sqlPouch(), true)
20
+ });
21
+ return {adapter:"node-sqlite"};
22
+ },
23
+ },
24
+ })
25
+ }
26
+ ELECTRON;
27
+ let fs = require("fs");
28
+ let _app = require("./app.config");
29
+ require("./pload")(ELECTRON);
30
+ const {ipcRenderer} = require('electron')
31
+ let APP_NAME = defaultStr(_app.name).toUpperCase();
32
+ let path = require("path");
33
+ let getPath = function(pathName){
34
+ return ipcRenderer.sendSync("electron-get-path",pathName);
35
+ }
36
+ let APP_PATH = path.join(getPath("appData"),APP_NAME).toLowerCase();
37
+ let databasePath = path.join(APP_PATH,"databases");
38
+ let ROOT_APP_FOLDER = undefined;
39
+ let separator = (path.sep)
40
+ let DOWNLOADING_FILES= {};
41
+ if(typeof separator != 'string' || !separator){
42
+ separator = (()=>{
43
+ let filePath = databasePath;
44
+ var sepIndex = filePath.lastIndexOf('/');
45
+ if(sepIndex == -1){
46
+ sepIndex = filePath.lastIndexOf('\\');
47
+ }
48
+ // include the trailing separator
49
+ return filePath.substring(0, sepIndex+1);
50
+ })();
51
+ }
52
+ function createDirSync(targetDir, { isRelativeToScript = false } = {}) {
53
+ if(!targetDir || typeof targetDir != 'string') return false;
54
+ const sep = path.sep;
55
+ const initDir = path.isAbsolute(targetDir) ? sep : '';
56
+ const baseDir = isRelativeToScript ? __dirname : '.';
57
+
58
+ return targetDir.split(sep).reduce((parentDir, childDir) => {
59
+ const curDir = path.resolve(baseDir, parentDir, childDir);
60
+ try {
61
+ fs.mkdirSync(curDir);
62
+ } catch (err) {
63
+ if (err.code === 'EEXIST') { // curDir already exists!
64
+ return curDir;
65
+ }
66
+
67
+ // To avoid `EISDIR` error on Mac and `EACCES`-->`ENOENT` and `EPERM` on Windows.
68
+ if (err.code === 'ENOENT') { // Throw the original parentDir error on curDir `ENOENT` failure.
69
+ throw new Error(`EACCES: permission denied, mkdir '${parentDir}'`);
70
+ }
71
+
72
+ const caughtErr = ['EACCES', 'EPERM', 'EISDIR'].indexOf(err.code) > -1;
73
+ if (!caughtErr || caughtErr && curDir === path.resolve(targetDir)) {
74
+ throw err; // Throw if it's just the last created dir.
75
+ }
76
+ }
77
+
78
+ return curDir;
79
+ }, initDir);
80
+ }
81
+ const Config = require('./config');
82
+ let confPath = process.env.ProgramData || process.env.ALLUSERSPROFILE;
83
+ if(confPath && typeof confPath =="string"){
84
+ if(fs.existsSync(confPath) && (_app.name) && typeof _app.name =='string'){
85
+ confPath = path.join(confPath,_app.name.toUpperCase());
86
+ if(!fs.existsSync(confPath)){
87
+ createDirSync(confPath);
88
+ }
89
+ if(fs.existsSync(confPath)){
90
+ ROOT_APP_FOLDER = confPath;
91
+ databasePath = path.join(confPath,"databases");
92
+ createDirSync(databasePath);
93
+ confPath = path.join(confPath,"CONFIG");
94
+ createDirSync(confPath);
95
+ }
96
+ } else confPath = undefined;
97
+ } else confPath = undefined;
98
+ let config = new Config({cwd:confPath});
99
+ if(typeof ELECTRON.getBackupPath !== 'function'){
100
+ let backupPathField = "_e_backupDataPath";
101
+ let cBackupPathField = "company"+backupPathField;
102
+ let dbPathField = "_electron_DBPathField";
103
+
104
+ Object.defineProperties(ELECTRON,{
105
+ getBackupPath : {
106
+ value : (p)=>{
107
+ let ePath = config.get(cBackupPathField);
108
+ let defPath = ROOT_APP_FOLDER || path.join(getPath("documents"),APP_NAME);
109
+ ELECTRON.COMPANY_BACKUP_PATH = defaultStr(ePath,defPath);
110
+ if(!fs.existsSync(ELECTRON.COMPANY_BACKUP_PATH)){
111
+ ELECTRON.COMPANY_BACKUP_PATH = defPath;
112
+ }
113
+ if(isNonNullString(p)){
114
+ return path.join(ELECTRON.COMPANY_BACKUP_PATH,p);
115
+ }
116
+ return ELECTRON.COMPANY_BACKUP_PATH;
117
+ },override:false,writable:false
118
+ },
119
+ getDatabasePath : {
120
+ value : ()=>{
121
+ let folder = APP.FOLDERS_MANAGER.getCurrent();
122
+ if(isObj(folder) && fs.existsSync(folder.databasePath)){
123
+ return databasePath;
124
+ }
125
+ let p = config.get(dbPathField);
126
+ if(fs.existsSync(p)){
127
+ databasePath = p
128
+ }
129
+ if(!fs.existsSync(databasePath)){
130
+ console.log(databasePath,' does not exists');
131
+ createDirSync(databasePath);
132
+ }
133
+ return databasePath;
134
+ },override:false,writable:false
135
+ },
136
+ setDatabasePath : {
137
+ value : (newPath)=>{
138
+ config.set(dbPathField,newPath)
139
+ },override:false,writable:false
140
+ },
141
+ setBackupPath : {
142
+ value : (newPath)=>{
143
+ newPath = defaultStr(newPath,ROOT_APP_FOLDER,path.join(getPath("documents"),APP_NAME));
144
+ ELECTRON.COMPANY_BACKUP_PATH = newPath;
145
+ config.set(cBackupPathField,ELECTRON.COMPANY_BACKUP_PATH)
146
+ },override:false,writable:false
147
+ },
148
+ showOpenDialog : {
149
+ value : (options)=>{
150
+ options = defaultObj(options);
151
+ return ipcRenderer.invoke("electron-show-open-dialog",options);
152
+ },override:false, writable:false
153
+ },
154
+ showSaveDialog : {
155
+ value : (options)=>{
156
+ options = defaultObj(options);
157
+ return ipcRenderer.invoke("electron-show-save-dialog",options);
158
+ },override:false, writable:false
159
+ },
160
+ unlinkDownloadingFile : {
161
+ value : (opts)=>{
162
+ opts = defaultObj(opts);
163
+ let p = opts.filePath+".download";
164
+ if(fs.existsSync(p)){
165
+ fs.unlink(p, function(err) {
166
+ if(err && err.code == 'ENOENT') {
167
+ // file doens't exist
168
+ console.info("File doesn't exist, won't remove it.");
169
+ } else if (err) {
170
+ console.error(err,"Error occurred while trying to remove file");
171
+ } else {
172
+ console.info(`removed`, p);
173
+ }
174
+ });
175
+ }
176
+ },override : false, writable : false
177
+ },
178
+ DOWNLOADING_FILES : {value : DOWNLOADING_FILES, override : false, writable : false},
179
+ restartApp : {
180
+ value : ()=>{
181
+ ipcRenderer.sendSync("electron-restart-app")
182
+ }, override : false, writable : false
183
+ },
184
+ downloadFile : {
185
+ value : (opts) =>{
186
+ opts = defaultObj(opts);
187
+ opts.directory = defaultStr(opts.directory,ELECTRON.PATH.DOWNLOADS);
188
+ opts.fileName = defaultStr(opts.fileName,APP.getName().toUpperCase())
189
+ opts.filePath = path.join(opts.directory,opts.fileName);
190
+ opts.onProgress = defaultFunc(opts.onProgress,(percentage,chunk,remainingSize)=> {})
191
+ opts.maxAttempts = defaultDecimal(opts.maxAttempts,4);
192
+ opts.onError = defaultFunc(opts.onError,x =>x);
193
+ let {onResponse} = opts;
194
+ opts.onResponse = function(response){
195
+ let length = response.headers['content-length'];
196
+ if(!isDecimal(length)){
197
+ length = parseFloat(length) || 0;
198
+ }
199
+ if(isFunction(onResponse)){
200
+ onResponse({...response,
201
+ length,fileSize:length,
202
+ fileSizeInBytes:length,
203
+ fileSizeInKiloBytes : length/1024,
204
+ fileSizeInMegaBytes : length / (1024*1024)
205
+ })
206
+ }
207
+ }
208
+ if(!isNonNullString(opts.url)) return Promise.reject({msg:'Ipossible de télécharger le fichier car l\'url est non définit'});
209
+ if(isObj(DOWNLOADING_FILES[opts.url]) && isPromise(DOWNLOADING_FILES[opts.url].promise)) {
210
+ return DOWNLOADING_FILES[opts.url];
211
+ }
212
+ opts.cloneFiles = defaultBool(opts.cloneFiles,false);//This will cause the downloader to re-write an existing file.
213
+
214
+ /*** If you want to completely skip downloading a file, when a file with the same name already exists, use config.skipExistingFileName = true */
215
+ opts.skipExistingFileName = defaultBool(opts.skipExistingFileName,false);
216
+ let Downloader = require('nodejs-file-downloader');
217
+ let downloader = new Downloader(opts);
218
+ let promise = downloader.download().then((result)=>{
219
+ return result;
220
+ }).catch((e)=>{
221
+ return e
222
+ //console.log(e," downloading file electron");
223
+ }).finally(()=>{
224
+ delete DOWNLOADING_FILES[opts.url];
225
+ });
226
+ DOWNLOADING_FILES[opts.url] = {
227
+ download : x=> promise,
228
+ promise,
229
+ context:downloader,
230
+ cancel : x => {
231
+ try {downloader.cancel();} catch(e){
232
+ console.log(e," canceled download");
233
+ } finally{
234
+ ELECTRON.unlinkDownloadingFile(opts);
235
+ delete DOWNLOADING_FILES[opts.url];
236
+ }
237
+ },
238
+ }
239
+ return DOWNLOADING_FILES[opts.url];
240
+ },override : false, writable : false
241
+ },
242
+ /*** le gestionnaire des configurations application electron :
243
+ * voir : https://github.com/sindresorhus/electron-store
244
+ */
245
+ CONFIG : {
246
+ value : config, override:false,writable:false
247
+ },
248
+ databasePath : {
249
+ value : ()=>{
250
+ let path = ELECTRON.getDatabasePath();
251
+ return path;
252
+ },override:false,writable:false
253
+ },
254
+ is : {
255
+ value : true,override:false,writable : false
256
+ },
257
+ APP_PATH : {
258
+ value : APP_PATH,override:false,writable:false
259
+ },
260
+ PATH : {
261
+ value : {
262
+ ...path,
263
+ SEPARATOR : separator,
264
+ SEP : separator,
265
+ get : getPath,
266
+ HOME : getPath("home"),
267
+ USERDATA : getPath("userData"),
268
+ /***
269
+ * Per-user application data directory, which by default points to:
270
+ * %APPDATA% on Windows
271
+ * $XDG_CONFIG_HOME or ~/.config on Linux
272
+ * ~/Library/Application Support on macOS
273
+ */
274
+ APPDATA : getPath("appData"),
275
+ CACHE : getPath("cache"),
276
+ TEMP : getPath("temp"),//Temporary directory.
277
+ EXECUTABLE : getPath("exe"),//The current executable file.
278
+ EXE : getPath("exe"),//The current executable file.
279
+ DOCUMENTS : getPath("documents"),
280
+ DOWNLOADS : path.join(APP_PATH,"downloads"),
281
+ DESKTOP : getPath("desktop"),//The current user's Desktop directory.
282
+ }, override:false,writable:false
283
+ },
284
+ ///retourne le chemin dont la chaine de caractère est passé en paramètre
285
+ getPath : {
286
+ value : getPath, override:false,writable:false
287
+ },
288
+ exec : {
289
+ value : (opts,successCB,errorCB)=>{
290
+ if(isNonNullString(opts)){
291
+ opts = {cmd:opts};
292
+ }
293
+ let {cmd} = opts;
294
+ opts = defaultObj(opts);
295
+ successCB = defaultFunc(successCB,opts.onSuccess)
296
+ errorCB = defaultFunc(errorCB,opts.onError);
297
+ return new Promise((resolve,reject)=>{
298
+ let handle = function(error, stdout, stderr) {
299
+ if(error){
300
+ errorCB({error,stderr})
301
+ return reject({error,stderr})
302
+ }
303
+ successCB(stdout);
304
+ resolve(stdout);
305
+ }
306
+ if(opts.sudo || opts.runAsAdmin){
307
+ sudo.exec(cmd, opts,handle)
308
+ } else {
309
+ exec(cmd,handle);
310
+ }
311
+ })
312
+ }
313
+ },
314
+ installNewAppVersion : {
315
+ value : (conf,successCB,errorCB)=>{
316
+ if(isNonNullString(conf)){
317
+ conf = {filePath:conf}
318
+ }
319
+ conf = defaultObj(conf);
320
+ let {notify} = APP.require("$dialog");
321
+
322
+ if(isNonNullString(conf.filePath) && fs.existsSync(conf.filePath)){
323
+ let cmd = conf.filePath;
324
+ if(ELECTRON.DEVICE.isLinux){
325
+ cmd = "dpkg -i "+cmd;
326
+ }
327
+ let rootPath = path.join(__dirname,'..')
328
+ let incs = path.join(rootPath, ELECTRON.DEVICE.isWindows?'icon.ico':ELECTRON.DEVICE.isLinux?'icon.png':'incs');
329
+ const options = {
330
+ title : "Authorisez "+APP.getName()+"",
331
+ name: APP.getName(),
332
+ incs,
333
+ icon : incs,
334
+ cmd,
335
+ sudo:true,
336
+ onSoucces : (stdout)=>{
337
+ let message = "Le processus d'installation de la mise à jour de l'application a été exécutée evec succès. Veuillez relancer l'application";
338
+ notify.success(message);
339
+ },
340
+ onError: ({error})=>{
341
+ notify.error("Erreur lors de l'exécution du fichier d'installation : "+defaultStr(error.message));
342
+ }
343
+ //icns: '/Applications/Electron.app/Contents/Resources/Electron.icns'
344
+ };
345
+ return ELECTRON.exec(options,successCB,errorCB)
346
+ }
347
+ }, override : false, writable : false
348
+ },
349
+ updateSystemTheme : {
350
+ value : (theme)=>{
351
+ return ipcRenderer.invoke("electron-set-system-theme:toggle",theme);
352
+ },override:false, writable:false
353
+ },
354
+ })
355
+ }
356
+ if(!window.APP){
357
+ Object.defineProperties(window,{
358
+ APP : {
359
+ value : {},override:false,writable:false
360
+ }
361
+ })
362
+ }
363
+ ELECTRON.getBackupPath();
364
+ require("./app/index")(ELECTRON)
365
+ require('v8-compile-cache');
366
+ require("v8").setFlagsFromString('--expose_gc');
367
+
368
+ let _gc = x =>{
369
+ if(!isObj(window.APP) || !isFunction(window.APP.isInitialized)){
370
+ return null;
371
+ }
372
+ if(!window.APP.isInitialized()){
373
+ return null;
374
+ }
375
+ return require("vm").runInNewContext('gc');
376
+ }
377
+ Object.defineProperties(window,{
378
+ gc : {value:_gc,override:false,writable:false}
379
+ })
380
+ Object.defineProperties(ELECTRON,{
381
+ gc : {value:_gc,override:false,writable:false}
382
+ })
383
+
384
+ ipcRenderer.on('before-app-exit', (args) => {
385
+ let {notify,showConfirm} = APP.require("$dialog");
386
+ hidePreloader();
387
+ if(showingExitApp) return;
388
+ showingExitApp = true;
389
+ showConfirm({
390
+ title : 'Quittez l\'application',
391
+ message : 'Voulez vous vraiment quitter l\'application?',
392
+ yes : 'Oui',
393
+ no : 'Non',
394
+ onCancel : () =>{
395
+ showingExitApp = false;
396
+ },
397
+ onSuccess : ()=>{
398
+ showingExitApp = false;
399
+ let backupDataOnClose = true;
400
+ let promises = []
401
+
402
+ if(APP.COMPANY && APP.COMPANY.electronBackupDataOnClose !== undefined){
403
+ backupDataOnClose = APP.COMPANY.electronBackupDataOnClose;
404
+ }
405
+ if(backupDataOnClose){
406
+ promises.push(APP.exportData({}).then().catch((e)=>{
407
+ console.log(e,' on backup databases before exit');
408
+ notify.error("Une erreur est survenue pendant la sauvegarde des données!! : "+JSON.stringify(e))
409
+ }))
410
+ }
411
+ if(APP.COMPANY && defaultVal(APP.COMPANY.syncDataOnExit,0)){
412
+ let {sync} = APP.require("$database");
413
+ promises.push(sync.run({cancel:false}));
414
+ }
415
+ let exit = ()=>{
416
+ let disconectUserOnExit= true;
417
+ if(APP.COMPANY && APP.COMPANY.disconectUserOnExit !== undefined){
418
+ disconectUserOnExit = APP.COMPANY.disconectUserOnExit;
419
+ }
420
+ if(disconectUserOnExit){
421
+ Auth.doLogout();
422
+ }
423
+ let autoUpdater = APP.getAutoUpdater();
424
+ let canInstall = autoUpdater.canInstall();
425
+ autoUpdater.setInstallOnAppExit(false)
426
+ let ex = x=>ipcRenderer.send("close-main-render-process");
427
+ if(isObj(canInstall)){
428
+ if(canInstall.installOnExit){
429
+ return ELECTRON.installNewAppVersion(canInstall).finally(ex);
430
+ }
431
+ }
432
+ ex();
433
+ }
434
+ Promise.all(promises).then(exit).catch((e)=>{
435
+ console.log(e,' exiting app');
436
+ exit();
437
+ }).finally(exit);
438
+ }
439
+ })
440
+ });
441
+
442
+ ipcRenderer.on("main-app-suspended",()=>{
443
+ APP.stopIDLE(true,true);
444
+ })
445
+ ipcRenderer.on("main-app-restaured",()=>{
446
+ APP.trackIDLE();
447
+ });
448
+ ipcRenderer.on('appReady',()=>{})
449
+ ipcRenderer.on("main-window-focus",()=>{
450
+ APP.runElectronAppStateChangedCallback({isActive:true})
451
+ })
452
+ ipcRenderer.on("main-window-blur",()=>{
453
+ APP.runElectronAppStateChangedCallback({});
454
+ })
455
+ })(window);
456
+
@@ -0,0 +1,5 @@
1
+ const {app} = require('electron');
2
+ let Conf = require('./config');
3
+ const session = new Conf({cwd:app.getPath('userData')});
4
+
5
+ module.exports = session;
package/expo-ui-path.js CHANGED
@@ -13,7 +13,7 @@ module.exports = function (){
13
13
  suffix = path.join(suffix,p);
14
14
  }
15
15
  })
16
- const expoUIPath = "@fto-consult/expo-ui";
16
+ const expoUIPath = path.resolve(process.cwd(),"node_modules","@fto-consult","expo-ui");
17
17
  const sep = path.sep;
18
18
  const rootPath = process.cwd();
19
19
  const src = path.resolve(rootPath,"src");
package/metro.config.js CHANGED
@@ -24,6 +24,6 @@ module.exports = function(opts){
24
24
  'jsx', 'js','tsx',
25
25
  ]
26
26
  // Remove all console logs in production...
27
- config.transformer.minifierConfig.compress.drop_console = true;
27
+ //config.transformer.minifierConfig.compress.drop_console = false;
28
28
  return config;
29
29
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fto-consult/expo-ui",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "Bibliothèque de composants UI Expo,react-native",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -63,7 +63,7 @@
63
63
  "@emotion/native": "^11.10.0",
64
64
  "@expo/html-elements": "^0.2.0",
65
65
  "@expo/vector-icons": "^13.0.0",
66
- "@fto-consult/common": "^2.13.2",
66
+ "@fto-consult/common": "^2.15.0",
67
67
  "@gorhom/portal": "^1.0.14",
68
68
  "@react-native-async-storage/async-storage": "~1.17.3",
69
69
  "@react-native-community/datetimepicker": "6.5.2",
@@ -71,6 +71,7 @@
71
71
  "@react-navigation/native": "^6.1.1",
72
72
  "@react-navigation/native-stack": "^6.9.7",
73
73
  "@shopify/flash-list": "1.3.1",
74
+ "conf": "^10.2.0",
74
75
  "expo": "^47.0.8",
75
76
  "expo-camera": "~13.1.0",
76
77
  "expo-clipboard": "~4.0.1",
package/writeFile.js ADDED
@@ -0,0 +1,16 @@
1
+ const path = require("path");
2
+ const getDirName = require('path').dirname;
3
+ module.exports = function writeFile(path, contents, cb) {
4
+ const p = getDirName(path);
5
+ if(!fs.existsSync(p)){
6
+ try {
7
+ fs.mkdirSync(p,{ recursive: true});
8
+ } catch(e){
9
+ console.log(e," making write file directory")
10
+ }
11
+ }
12
+ if(fs.existsSync(p)){
13
+ return fs.writeFileSync(path, contents, cb);
14
+ }
15
+ throw {message : 'impossible de créer le repertoire '+p};
16
+ }