@radiantabyss/neutralino 1.0.2 → 1.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.
- package/package.json +1 -1
- package/src/Bootstrap.js +22 -8
- package/src/Command.js +41 -0
- package/src/Routing/Middleware.js +1 -1
- package/src/Routing/Route.js +5 -6
- package/src/Routing/RouteCrud.js +2 -0
- package/src/Routing/Router.js +9 -8
- package/src/Support/Config.js +23 -20
- package/src/Support/Globals.js +29 -0
- package/src/Support/Helpers.js +5 -0
- package/src/Support/Item.js +63 -0
- package/src/Support/Items.js +363 -0
- package/src/Support/Storage.js +23 -0
- package/src/Support/Str.js +209 -0
- package/src/Tray.js +47 -0
- package/src/Validator.js +1 -1
- package/src/Models.js +0 -19
- /package/src/{Invoke.js → Invoked.js} +0 -0
package/package.json
CHANGED
package/src/Bootstrap.js
CHANGED
|
@@ -1,24 +1,38 @@
|
|
|
1
1
|
import Response from './Response.js';
|
|
2
|
-
import
|
|
2
|
+
import Invoked from './Invoked.js';
|
|
3
3
|
import Validator from './Validator.js';
|
|
4
4
|
import IPC from './IPC.js';
|
|
5
5
|
|
|
6
|
+
import Globals from './Support/Globals.js';
|
|
6
7
|
import Config from './Support/Config.js';
|
|
7
|
-
import
|
|
8
|
+
import Storage from './Support/Storage.js';
|
|
8
9
|
import Helpers from './Support/Helpers.js';
|
|
10
|
+
import Item from './Support/Item';
|
|
11
|
+
import Items from './Support/Items';
|
|
12
|
+
|
|
13
|
+
window.RA = {};
|
|
14
|
+
|
|
15
|
+
export default async () => {
|
|
16
|
+
Neutralino.init();
|
|
17
|
+
|
|
18
|
+
window.Config = Config;
|
|
19
|
+
window.Storage = Storage;
|
|
20
|
+
window.Item = Item;
|
|
21
|
+
window.Items = Items;
|
|
22
|
+
|
|
23
|
+
//globals
|
|
24
|
+
let globals = await Globals();
|
|
25
|
+
for (let key in globals) {
|
|
26
|
+
window[key] = globals[key];
|
|
27
|
+
}
|
|
9
28
|
|
|
10
|
-
export default () => {
|
|
11
29
|
//helpers
|
|
12
30
|
for ( let key in Helpers ) {
|
|
13
31
|
window[key] = Helpers[key];
|
|
14
32
|
}
|
|
15
33
|
|
|
16
|
-
window.RA = {};
|
|
17
|
-
window.Config = Config;
|
|
18
|
-
window.Env = Env;
|
|
19
|
-
|
|
20
34
|
window.Response = Response;
|
|
21
|
-
window.
|
|
35
|
+
window.Invoked = Invoked;
|
|
22
36
|
window.Validator = Validator;
|
|
23
37
|
window.IPC = IPC;
|
|
24
38
|
};
|
package/src/Command.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
let context = import.meta.glob('/app/Domains/**/*.js');
|
|
2
|
+
|
|
3
|
+
const getMatchedCommand = async () => {
|
|
4
|
+
const files = Object.keys(context);
|
|
5
|
+
|
|
6
|
+
for ( let i = 0; i < files.length; i++ ) {
|
|
7
|
+
let split = files[i].split('/');
|
|
8
|
+
split.shift();
|
|
9
|
+
let name = split[split.length - 1].replace('.js', '');
|
|
10
|
+
split.pop();
|
|
11
|
+
split.pop();
|
|
12
|
+
split.shift();
|
|
13
|
+
split.shift();
|
|
14
|
+
|
|
15
|
+
if ( !name.match(/Command/) || name == 'Command' ) {
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let module = await context[files[i]]();
|
|
20
|
+
let signature_split = module.default.signature.split(' ');
|
|
21
|
+
if ( signature_split[0] == NL_ARGS[1] ) {
|
|
22
|
+
return module.default;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default async () => {
|
|
30
|
+
let command = await getMatchedCommand();
|
|
31
|
+
await Neutralino.os.execCommand('cmd /c echo');
|
|
32
|
+
|
|
33
|
+
if ( !command ) {
|
|
34
|
+
throw `Command with signature "${NL_ARGS[1]}" not found.`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let args = NL_ARGS;
|
|
38
|
+
args.shift();
|
|
39
|
+
args.shift();
|
|
40
|
+
await command.run.apply(this, args);
|
|
41
|
+
}
|
|
@@ -24,7 +24,7 @@ let runMiddleware = async (to, from, i = 0) => {
|
|
|
24
24
|
|
|
25
25
|
//middleware doesnt exist
|
|
26
26
|
if ( !Middleware[to.meta.middleware[i]] ) {
|
|
27
|
-
throw new Error(
|
|
27
|
+
throw new Error(`Middleware "${to.meta.middleware[i]}" not found.`);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
//run middleware
|
package/src/Routing/Route.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import Str from './../Support/Str';
|
|
2
|
+
|
|
1
3
|
let group_middleware = null;
|
|
2
4
|
|
|
3
5
|
function addRoute(method, path, action, middleware, name, throw_error) {
|
|
@@ -5,9 +7,6 @@ function addRoute(method, path, action, middleware, name, throw_error) {
|
|
|
5
7
|
throw `Action missing for ${path}`;
|
|
6
8
|
}
|
|
7
9
|
|
|
8
|
-
//format path
|
|
9
|
-
path = path.replace(/\{([\s\S]+?)\}/g, ':$1');
|
|
10
|
-
|
|
11
10
|
//get action
|
|
12
11
|
action = action.replace(/\\/g, '.').replace(/\//g, '.');
|
|
13
12
|
let split = action.split('.');
|
|
@@ -21,16 +20,16 @@ function addRoute(method, path, action, middleware, name, throw_error) {
|
|
|
21
20
|
|
|
22
21
|
let component;
|
|
23
22
|
try {
|
|
24
|
-
component = getAction(Actions, split[split.length - 1], namespace, action_name);
|
|
23
|
+
component = getAction(window.RA.Actions, split[split.length - 1], namespace, action_name);
|
|
25
24
|
}
|
|
26
25
|
catch(e) {
|
|
27
26
|
if ( throw_error ) {
|
|
28
|
-
throw `Action ${action_name} doesn't exist.`;
|
|
27
|
+
throw `Action "${action_name}" doesn't exist.`;
|
|
29
28
|
}
|
|
30
29
|
return;
|
|
31
30
|
}
|
|
32
31
|
|
|
33
|
-
window.RA.RouteFiles[__neutralino_route_file].push({
|
|
32
|
+
window.RA.RouteFiles[window.RA.__neutralino_route_file].push({
|
|
34
33
|
name: action_name,
|
|
35
34
|
component,
|
|
36
35
|
path,
|
package/src/Routing/RouteCrud.js
CHANGED
package/src/Routing/Router.js
CHANGED
|
@@ -21,15 +21,15 @@ const loadModules = async () => {
|
|
|
21
21
|
let file = files[i].replace('/app/Routes/', '').replace(/\.js$/, '');
|
|
22
22
|
window.RA.__neutralino_route_file = file;
|
|
23
23
|
|
|
24
|
-
if ( !RouteFiles[window.RA.__neutralino_route_file] ) {
|
|
25
|
-
RouteFiles[window.RA.__neutralino_route_file] = [];
|
|
24
|
+
if ( !window.RA.RouteFiles[window.RA.__neutralino_route_file] ) {
|
|
25
|
+
window.RA.RouteFiles[window.RA.__neutralino_route_file] = [];
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
await context[files[i]]();
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
const match = async(args
|
|
32
|
+
const match = async(args) => {
|
|
33
33
|
let matched = null;
|
|
34
34
|
let params = [];
|
|
35
35
|
|
|
@@ -69,11 +69,12 @@ const match = async(args, event) => {
|
|
|
69
69
|
for (let i = 1; i < match.length; i++) {
|
|
70
70
|
params.push(match[i]);
|
|
71
71
|
}
|
|
72
|
+
|
|
73
|
+
break;
|
|
72
74
|
}
|
|
73
75
|
}
|
|
74
76
|
|
|
75
|
-
|
|
76
|
-
params.push(event);
|
|
77
|
+
Invoked.data = args.payload;
|
|
77
78
|
|
|
78
79
|
return {
|
|
79
80
|
Route: matched,
|
|
@@ -88,12 +89,12 @@ export default async () => {
|
|
|
88
89
|
await loadModules();
|
|
89
90
|
|
|
90
91
|
//handle route matching
|
|
91
|
-
IPC.handle('invoke', async (
|
|
92
|
+
IPC.handle('invoke', async (args) => {
|
|
92
93
|
args.payload = JSON.parse(args.payload);
|
|
93
94
|
|
|
94
|
-
let matched = await match(args
|
|
95
|
+
let matched = await match(args);
|
|
95
96
|
if ( !matched.Route ) {
|
|
96
|
-
throw `Route ${matched.path} not found.`;
|
|
97
|
+
throw `Route "${matched.path}" not found.`;
|
|
97
98
|
}
|
|
98
99
|
|
|
99
100
|
return await matched.Route.component.run(...matched.params);
|
package/src/Support/Config.js
CHANGED
|
@@ -7,33 +7,36 @@ const self = {
|
|
|
7
7
|
await Neutralino.filesystem.writeFile(`${APP_PATH}/configs/${config}.json`, JSON.stringify(data, null, 4));
|
|
8
8
|
},
|
|
9
9
|
|
|
10
|
-
get(config) {
|
|
11
|
-
|
|
12
|
-
},
|
|
10
|
+
async get(config, key = null) {
|
|
11
|
+
let data = await self.read(config);
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
},
|
|
13
|
+
if ( key !== null ) {
|
|
14
|
+
return data[key];
|
|
15
|
+
}
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
self.write(config, data);
|
|
17
|
+
return data;
|
|
21
18
|
},
|
|
22
19
|
|
|
23
|
-
|
|
24
|
-
let data =
|
|
25
|
-
data[key] = value;
|
|
26
|
-
self.write(config, data);
|
|
27
|
-
},
|
|
20
|
+
async set(config, value, key = null) {
|
|
21
|
+
let data = value;
|
|
28
22
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
if ( key !== null ) {
|
|
24
|
+
data = await self.read(config);
|
|
25
|
+
data[key] = value;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
await self.write(config, data);
|
|
33
29
|
},
|
|
34
30
|
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
async remove(config, key = null) {
|
|
32
|
+
let data = {};
|
|
33
|
+
|
|
34
|
+
if ( key !== null ) {
|
|
35
|
+
data = await self.read(config);
|
|
36
|
+
delete data[key];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
await self.write(config, data);
|
|
37
40
|
},
|
|
38
41
|
};
|
|
39
42
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export default async function() {
|
|
2
|
+
let APP_PATH = await Neutralino.filesystem.getAbsolutePath('.');
|
|
3
|
+
let IS_PACKAGED = NL_RESMODE == 'bundle';
|
|
4
|
+
let STATIC_PATH = `${APP_PATH}/static`;
|
|
5
|
+
|
|
6
|
+
//set window type
|
|
7
|
+
let WINDOW_TYPE = 'main';
|
|
8
|
+
for ( let arg of NL_ARGS ) {
|
|
9
|
+
if ( arg.match(/--window-type/) ) {
|
|
10
|
+
WINDOW_TYPE = arg.replace(/--window-type=/, '');
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
//set display profile
|
|
15
|
+
let DISPLAY_PROFILE = '';
|
|
16
|
+
for ( let display of await Neutralino.computer.getDisplays() ) {
|
|
17
|
+
DISPLAY_PROFILE += `${display.resolution.width}_${display.resolution.height}_${window.devicePixelRatio}_`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
APP_PATH,
|
|
22
|
+
STATIC_PATH,
|
|
23
|
+
IS_PACKAGED,
|
|
24
|
+
WINDOW_TYPE,
|
|
25
|
+
DISPLAY_PROFILE,
|
|
26
|
+
MAIN_WINDOW: null,
|
|
27
|
+
UPDATE_WINDOW: null,
|
|
28
|
+
}
|
|
29
|
+
}
|
package/src/Support/Helpers.js
CHANGED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
let self = {
|
|
2
|
+
patch(item, data) {
|
|
3
|
+
return self.setKeys(item, Object.keys(data), Object.values(data));
|
|
4
|
+
},
|
|
5
|
+
|
|
6
|
+
setKey(item, key, value) {
|
|
7
|
+
return self.setKeys(item, key, value);
|
|
8
|
+
},
|
|
9
|
+
|
|
10
|
+
setKeys(item, keys, values) {
|
|
11
|
+
let not_empty = window.handleEmpty(item);
|
|
12
|
+
if ( not_empty !== true ) {
|
|
13
|
+
item = {};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if ( Array.isArray(keys) && !Array.isArray(values) ) {
|
|
17
|
+
let array_values = [];
|
|
18
|
+
for ( let key of keys ) {
|
|
19
|
+
array_values.push(values);
|
|
20
|
+
}
|
|
21
|
+
values = array_values;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if ( !Array.isArray(keys) ) {
|
|
25
|
+
keys = [keys];
|
|
26
|
+
values = [values];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
for ( let i = 0; i < keys.length; i++ ) {
|
|
30
|
+
item[keys[i]] = values[i];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return {...item};
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
removeEmptyKeys(item) {
|
|
37
|
+
let new_item = Array.isArray(item) ? [] : {};
|
|
38
|
+
let count = Array.isArray(item) ? item.length : Object.keys(item).length;
|
|
39
|
+
for ( let i = 0; i < count; i++ ) {
|
|
40
|
+
let index = Array.isArray(item) ? i : Object.keys(item)[i];
|
|
41
|
+
|
|
42
|
+
if ( item[index] !== '' ) {
|
|
43
|
+
new_item[index] = item[index];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return new_item;
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
deleteKeys(item, keys) {
|
|
51
|
+
for ( let key of keys ) {
|
|
52
|
+
delete item[key];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return {...item};
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
deleteKey(item, key) {
|
|
59
|
+
return self.deleteKeys(item, [key]);
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export default self;
|
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
const self = {
|
|
2
|
+
pluck(items, key = 'id') {
|
|
3
|
+
let plucked = [];
|
|
4
|
+
for (let i = 0; i < items.length; i++) {
|
|
5
|
+
plucked.push(items[i][key]);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return plucked;
|
|
9
|
+
},
|
|
10
|
+
|
|
11
|
+
spread(items) {
|
|
12
|
+
return JSON.parse(JSON.stringify(items));
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
keyBy(items, key = 'id') {
|
|
16
|
+
let not_empty = window.handleEmpty(items);
|
|
17
|
+
if ( not_empty !== true ) {
|
|
18
|
+
return not_empty;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let new_items = {};
|
|
22
|
+
let count = Array.isArray(items) ? items.length : Object.keys(items).length;
|
|
23
|
+
for ( let i = 0; i < count; i++ ) {
|
|
24
|
+
let index = Array.isArray(items) ? i : Object.keys(items)[i];
|
|
25
|
+
new_items[items[index][key]] = items[index];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return new_items;
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
groupBy(items, key = 'id') {
|
|
32
|
+
let not_empty = window.handleEmpty(items);
|
|
33
|
+
if ( not_empty !== true ) {
|
|
34
|
+
return not_empty;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let new_items = Array.isArray(items) ? [] : {};
|
|
38
|
+
let count = Array.isArray(items) ? items.length : Object.keys(items).length;
|
|
39
|
+
for ( let i = 0; i < count; i++ ) {
|
|
40
|
+
let index = Array.isArray(items) ? i : Object.keys(items)[i];
|
|
41
|
+
|
|
42
|
+
if (typeof new_items[items[index][key]] === 'undefined') {
|
|
43
|
+
new_items[items[index][key]] = [];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
new_items[items[index][key]].push(items[index]);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return new_items;
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
find(items, ids) {
|
|
53
|
+
let not_empty = window.handleEmpty(items);
|
|
54
|
+
if ( not_empty !== true ) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
let single = false;
|
|
59
|
+
if ( !Array.isArray(ids) ) {
|
|
60
|
+
if ( typeof ids === 'string' ) {
|
|
61
|
+
ids = parseInt(ids);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
ids = [ids];
|
|
65
|
+
single = true;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
let new_items = Array.isArray(items) ? [] : {};
|
|
69
|
+
let count = Array.isArray(items) ? items.length : Object.keys(items).length;
|
|
70
|
+
for ( let i = 0; i < count; i++ ) {
|
|
71
|
+
let index = Array.isArray(items) ? i : Object.keys(items)[i];
|
|
72
|
+
|
|
73
|
+
if ( ids.includes(parseInt(items[index].id)) ) {
|
|
74
|
+
if ( Array.isArray(items) ) {
|
|
75
|
+
new_items.push(items[index]);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
new_items[index] = items[index];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if ( single ) {
|
|
84
|
+
if ( Array.isArray(new_items) && new_items.length ) {
|
|
85
|
+
return new_items[0];
|
|
86
|
+
}
|
|
87
|
+
else if ( !Array.isArray(new_items) && Object.keys(new_items).length ) {
|
|
88
|
+
return new_items[Object.keys(new_items)[0]];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return new_items;
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
findByKey(items, key, value = true, single = false) {
|
|
98
|
+
let not_empty = window.handleEmpty(items);
|
|
99
|
+
if ( not_empty !== true ) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
let new_items = Array.isArray(items) ? [] : {};
|
|
104
|
+
let count = Array.isArray(items) ? items.length : Object.keys(items).length;
|
|
105
|
+
for ( let i = 0; i < count; i++ ) {
|
|
106
|
+
let index = Array.isArray(items) ? i : Object.keys(items)[i];
|
|
107
|
+
|
|
108
|
+
if ( items[index][key] == value ) {
|
|
109
|
+
if ( Array.isArray(items) ) {
|
|
110
|
+
new_items.push(items[index]);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
new_items[index] = items[index];
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if ( single ) {
|
|
119
|
+
if ( Array.isArray(new_items) && new_items.length ) {
|
|
120
|
+
return new_items[0];
|
|
121
|
+
}
|
|
122
|
+
else if ( !Array.isArray(new_items) && Object.keys(new_items).length ) {
|
|
123
|
+
return new_items[Object.keys(new_items)[0]];
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return new_items;
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
add(items, item, at_first_position = false) {
|
|
133
|
+
let not_empty = window.handleEmpty(items);
|
|
134
|
+
if ( not_empty !== true ) {
|
|
135
|
+
items = [];
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if ( at_first_position ) {
|
|
139
|
+
items.unshift(item);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
items.push(item);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return items;
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
addMany(items, added, at_first_position = false) {
|
|
149
|
+
let not_empty = window.handleEmpty(items);
|
|
150
|
+
if ( not_empty !== true ) {
|
|
151
|
+
items = [];
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if ( at_first_position ) {
|
|
155
|
+
return added.concat(items);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
return items.concat(added);
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
|
|
162
|
+
patch(items, data) {
|
|
163
|
+
if ( !data.id ) {
|
|
164
|
+
throw 'ID is required.';
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
let id = data.id;
|
|
168
|
+
delete data.id;
|
|
169
|
+
|
|
170
|
+
return self.setKeys(items, id, Object.keys(data), Object.values(data));
|
|
171
|
+
},
|
|
172
|
+
|
|
173
|
+
replace(items, item) {
|
|
174
|
+
let not_empty = window.handleEmpty(items);
|
|
175
|
+
if ( not_empty !== true ) {
|
|
176
|
+
return not_empty;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
let new_items = Array.isArray(items) ? [] : {};
|
|
180
|
+
let count = Array.isArray(items) ? items.length : Object.keys(items).length;
|
|
181
|
+
for ( let i = 0; i < count; i++ ) {
|
|
182
|
+
let index = Array.isArray(items) ? i : Object.keys(items)[i];
|
|
183
|
+
|
|
184
|
+
if ( items[index].id == item.id ) {
|
|
185
|
+
new_items[index] = item;
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
new_items[index] = items[index];
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return new_items;
|
|
193
|
+
},
|
|
194
|
+
|
|
195
|
+
delete(items, ids) {
|
|
196
|
+
let not_empty = window.handleEmpty(items);
|
|
197
|
+
if ( not_empty !== true ) {
|
|
198
|
+
return not_empty;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if ( !Array.isArray(ids) ) {
|
|
202
|
+
if ( typeof ids === 'string' ) {
|
|
203
|
+
ids = parseInt(ids);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
ids = [ids];
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
let new_items = Array.isArray(items) ? [] : {};
|
|
210
|
+
let count = Array.isArray(items) ? items.length : Object.keys(items).length;
|
|
211
|
+
for ( let i = 0; i < count; i++ ) {
|
|
212
|
+
let index = Array.isArray(items) ? i : Object.keys(items)[i];
|
|
213
|
+
|
|
214
|
+
if ( ids.includes(parseInt(items[index].id)) ) {
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if ( Array.isArray(items) ) {
|
|
219
|
+
new_items.push(items[index]);
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
new_items[index] = items[index];
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return new_items;
|
|
227
|
+
},
|
|
228
|
+
|
|
229
|
+
deleteByKey(items, key, value) {
|
|
230
|
+
let not_empty = window.handleEmpty(items);
|
|
231
|
+
if ( not_empty !== true ) {
|
|
232
|
+
return not_empty;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
let new_items = Array.isArray(items) ? [] : {};
|
|
236
|
+
let count = Array.isArray(items) ? items.length : Object.keys(items).length;
|
|
237
|
+
for ( let i = 0; i < count; i++ ) {
|
|
238
|
+
let index = Array.isArray(items) ? i : Object.keys(items)[i];
|
|
239
|
+
|
|
240
|
+
if ( items[index][key] != value ) {
|
|
241
|
+
new_items[index] = items[index];
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return new_items;
|
|
246
|
+
},
|
|
247
|
+
|
|
248
|
+
setKey(items, id, key, value) {
|
|
249
|
+
return self.setKeys(items, id, key, value);
|
|
250
|
+
},
|
|
251
|
+
|
|
252
|
+
setKeys(items, ids, keys, values) {
|
|
253
|
+
let not_empty = window.handleEmpty(items);
|
|
254
|
+
if ( not_empty !== true ) {
|
|
255
|
+
return not_empty;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if ( !Array.isArray(ids) ) {
|
|
259
|
+
if ( typeof ids === 'string' ) {
|
|
260
|
+
ids = parseInt(ids);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
ids = [ids];
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if ( Array.isArray(keys) && !Array.isArray(values) ) {
|
|
267
|
+
let array_values = [];
|
|
268
|
+
for ( let key of keys ) {
|
|
269
|
+
array_values.push(values);
|
|
270
|
+
}
|
|
271
|
+
values = array_values;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if ( !Array.isArray(keys) ) {
|
|
275
|
+
keys = [keys];
|
|
276
|
+
values = [values];
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
let count = Array.isArray(items) ? items.length : Object.keys(items).length;
|
|
280
|
+
for ( let i = 0; i < count; i++ ) {
|
|
281
|
+
let index = Array.isArray(items) ? i : Object.keys(items)[i];
|
|
282
|
+
|
|
283
|
+
if ( ids.includes(parseInt(items[index].id)) ) {
|
|
284
|
+
for ( let j = 0; j < keys.length; j++ ) {
|
|
285
|
+
items[i][keys[j]] = values[j];
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return items;
|
|
291
|
+
},
|
|
292
|
+
|
|
293
|
+
toggleKey(items, id, key) {
|
|
294
|
+
return self.toggleKeys(items, id, key);
|
|
295
|
+
},
|
|
296
|
+
|
|
297
|
+
toggleKeys(items, ids, keys) {
|
|
298
|
+
let not_empty = window.handleEmpty(items);
|
|
299
|
+
if ( not_empty !== true ) {
|
|
300
|
+
return not_empty;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if ( !Array.isArray(ids) ) {
|
|
304
|
+
if ( typeof ids === 'string' ) {
|
|
305
|
+
ids = parseInt(ids);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
ids = [ids];
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
if ( !Array.isArray(keys) ) {
|
|
312
|
+
keys = [keys];
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
let count = Array.isArray(items) ? items.length : Object.keys(items).length;
|
|
316
|
+
for ( let i = 0; i < count; i++ ) {
|
|
317
|
+
let index = Array.isArray(items) ? i : Object.keys(items)[i];
|
|
318
|
+
|
|
319
|
+
if ( ids.includes(parseInt(items[index].id)) ) {
|
|
320
|
+
for ( let j = 0; j < keys.length; j++ ) {
|
|
321
|
+
items[index][keys[j]] = !items[index][keys[j]];
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
return items;
|
|
327
|
+
},
|
|
328
|
+
|
|
329
|
+
sort(items, from, to) {
|
|
330
|
+
const copy = [...items];
|
|
331
|
+
const valueToMove = copy.splice(from, 1)[0];
|
|
332
|
+
copy.splice(to, 0, valueToMove);
|
|
333
|
+
|
|
334
|
+
return copy;
|
|
335
|
+
},
|
|
336
|
+
|
|
337
|
+
next(items, current, key = 'id') {
|
|
338
|
+
for ( let i = 0; i < items.length; i++ ) {
|
|
339
|
+
if ( items[i][key] == current[key] && i < items.length - 1 ) {
|
|
340
|
+
return items[i + 1];
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
return false;
|
|
345
|
+
},
|
|
346
|
+
|
|
347
|
+
prev(items, current, key = 'id') {
|
|
348
|
+
for ( let i = items.length - 1; i >= 0; i-- ) {
|
|
349
|
+
if ( items[i][key] == current[key] && i > 0 ) {
|
|
350
|
+
return items[i - 1];
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
return false;
|
|
355
|
+
},
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
window.pluck = self.pluck;
|
|
359
|
+
window.spread = self.spread;
|
|
360
|
+
window.keyBy = self.keyBy;
|
|
361
|
+
window.groupBy = self.groupBy;
|
|
362
|
+
|
|
363
|
+
export default self;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const self = {
|
|
2
|
+
async get(key) {
|
|
3
|
+
try {
|
|
4
|
+
return JSON.parse(await Neutralino.storage.getData(key));
|
|
5
|
+
}
|
|
6
|
+
catch (e) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
},
|
|
10
|
+
async set(key, value) {
|
|
11
|
+
await Neutralino.storage.setData(key, JSON.stringify(value));
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
async remove(key) {
|
|
15
|
+
await Neutralino.storage.setData(key, null);
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
async clear() {
|
|
19
|
+
await Neutralino.filsystem.remove(`${APP_PATH}/.storage`);
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default self;
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
let self = {
|
|
2
|
+
/*helpers from https://github.com/validatorjs/validator.js*/
|
|
3
|
+
ltrim(str, chars) {
|
|
4
|
+
const pattern = chars ? new RegExp(`^[${chars.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}]+`, 'g') : /^\s+/g;
|
|
5
|
+
return `${str}`.replace(pattern, '');
|
|
6
|
+
},
|
|
7
|
+
|
|
8
|
+
rtrim(str, chars) {
|
|
9
|
+
const pattern = chars ? new RegExp(`[${chars.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}]+$`, 'g') : /(\s)+$/g;
|
|
10
|
+
return `${str}`.replace(pattern, '');
|
|
11
|
+
},
|
|
12
|
+
|
|
13
|
+
trim(str, chars) {
|
|
14
|
+
return self.rtrim(self.ltrim(`${str}`, chars), chars);
|
|
15
|
+
},
|
|
16
|
+
/*end helpers from https://github.com/validatorjs/validator.js*/
|
|
17
|
+
|
|
18
|
+
urlencode(str) {
|
|
19
|
+
return encodeURIComponent(str);
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
slug(str) {
|
|
23
|
+
str = str.replace(/^\s+|\s+$/g, ''); // trim
|
|
24
|
+
str = str.toLowerCase();
|
|
25
|
+
|
|
26
|
+
// remove accents, swap ñ for n, etc
|
|
27
|
+
var from = "àáãäâèéëêìíïîòóöôùúüûñç·/_,:;";
|
|
28
|
+
var to = "aaaaaeeeeiiiioooouuuunc------";
|
|
29
|
+
|
|
30
|
+
for (var i=0, l=from.length ; i<l ; i++) {
|
|
31
|
+
str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
str = str.replace(/[^a-z0-9 -]/g, '') // remove invalid chars
|
|
35
|
+
.replace(/\s+/g, '-') // collapse whitespace and replace by -
|
|
36
|
+
.replace(/-+/g, '-'); // collapse dashes
|
|
37
|
+
|
|
38
|
+
return str;
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
dash(str) {
|
|
42
|
+
return str.split('').map((letter, idx) => {
|
|
43
|
+
return letter.toUpperCase() === letter
|
|
44
|
+
? `${idx !== 0 ? '-' : ''}${letter.toLowerCase()}`
|
|
45
|
+
: letter;
|
|
46
|
+
}).join('');
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
snake(string) {
|
|
50
|
+
return string
|
|
51
|
+
.replace(/\s+(?=\d)/g, '')
|
|
52
|
+
.replace(/\s+/g, '_')
|
|
53
|
+
.replace(/([a-z])([A-Z])/g, '$1_$2')
|
|
54
|
+
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2')
|
|
55
|
+
.toLowerCase();
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
camel(str) {
|
|
59
|
+
return str.replace(/-/g, ' ').replace(/_/g, ' ').replace(/(^([a-zA-Z\p{M}]))|([ -][a-zA-Z\p{M}])/g,function(s) {
|
|
60
|
+
return s.toUpperCase();
|
|
61
|
+
}).replace(/\s+/g, '');
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
pascal(str) {
|
|
65
|
+
return `${str}`
|
|
66
|
+
.toLowerCase()
|
|
67
|
+
.replace(new RegExp(/[-_]+/, 'g'), ' ')
|
|
68
|
+
.replace(new RegExp(/[^\w\s]/, 'g'), '')
|
|
69
|
+
.replace(new RegExp(/\s+(.)(\w*)/, 'g'), ($1, $2, $3) => `${$2.toUpperCase() + $3}`)
|
|
70
|
+
.replace(new RegExp(/\w/), s => s.toUpperCase());
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
kebab(str) {
|
|
74
|
+
return `${str}`.replace(/([a-z])([A-Z])/g, "$1-$2")
|
|
75
|
+
.replace(/[\s_]+/g, '-')
|
|
76
|
+
.toLowerCase();
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
camel2space(str) {
|
|
80
|
+
if ( !str ) {
|
|
81
|
+
return '';
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return str.split('').map((letter, idx) => {
|
|
85
|
+
return letter.toUpperCase() === letter
|
|
86
|
+
? `${idx !== 0 ? ' ' : ''}${letter}`
|
|
87
|
+
: letter;
|
|
88
|
+
}).join('');
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
ucfirst(string) {
|
|
92
|
+
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
ucwords(str) {
|
|
96
|
+
if ( !str ) {
|
|
97
|
+
str = '';
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
//ensure string
|
|
101
|
+
str = str + '';
|
|
102
|
+
|
|
103
|
+
return str.replace(/-/g, ' ').replace(/_/g, ' ').replace(/(^([a-zA-Z\p{M}]))|([ -][a-zA-Z\p{M}])/g,function(s) {
|
|
104
|
+
return s.toUpperCase();
|
|
105
|
+
});
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
ordinal_suffix(i) {
|
|
109
|
+
var j = i % 10,
|
|
110
|
+
k = i % 100;
|
|
111
|
+
if (j == 1 && k != 11) {
|
|
112
|
+
return i + "st";
|
|
113
|
+
}
|
|
114
|
+
if (j == 2 && k != 12) {
|
|
115
|
+
return i + "nd";
|
|
116
|
+
}
|
|
117
|
+
if (j == 3 && k != 13) {
|
|
118
|
+
return i + "rd";
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return i + "th";
|
|
122
|
+
},
|
|
123
|
+
|
|
124
|
+
number_to_month(number) {
|
|
125
|
+
let months = {
|
|
126
|
+
1: 'January',
|
|
127
|
+
2: 'February',
|
|
128
|
+
3: 'March',
|
|
129
|
+
4: 'April',
|
|
130
|
+
5: 'May',
|
|
131
|
+
6: 'June',
|
|
132
|
+
7: 'July',
|
|
133
|
+
8: 'August',
|
|
134
|
+
9: 'September',
|
|
135
|
+
10: 'October',
|
|
136
|
+
11: 'November',
|
|
137
|
+
12: 'December',
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
return months[`${number}`.replace(/^0/, '')];
|
|
141
|
+
},
|
|
142
|
+
|
|
143
|
+
nl2br(str) {
|
|
144
|
+
if ( !str || !str.length ) {
|
|
145
|
+
return '';
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return str.replace(/(\r\n|\n\r|\r|\n)/g, '<br/>' + '$1');
|
|
149
|
+
},
|
|
150
|
+
|
|
151
|
+
strip_tags(str) {
|
|
152
|
+
var div = document.createElement("div");
|
|
153
|
+
div.innerHTML = str;
|
|
154
|
+
var text = div.textContent || div.innerText || "";
|
|
155
|
+
return text;
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
ensure_https(string) {
|
|
159
|
+
if (!string.match(/^[a-zA-Z]+:\/\//)) {
|
|
160
|
+
string = 'https://' + string;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return string;
|
|
164
|
+
},
|
|
165
|
+
|
|
166
|
+
add_commas(number) {
|
|
167
|
+
if ( number === undefined || number === null ) {
|
|
168
|
+
return '';
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
number = parseFloat(number).toFixed(2).toLocaleString('en-US');
|
|
172
|
+
|
|
173
|
+
return number;
|
|
174
|
+
},
|
|
175
|
+
|
|
176
|
+
leading_zero(number) {
|
|
177
|
+
return number < 10 ? `0${number}` : number;
|
|
178
|
+
},
|
|
179
|
+
|
|
180
|
+
to_percetange(number) {
|
|
181
|
+
if ( number === undefined || !number ) {
|
|
182
|
+
return '0%';
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return (number / 10)+'%';
|
|
186
|
+
},
|
|
187
|
+
|
|
188
|
+
plural(str) {
|
|
189
|
+
if ( str.match(/y$/) ) {
|
|
190
|
+
return str.replace(/y$/, 'ies');
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if ( str.match(/s$/) ) {
|
|
194
|
+
return `${str}es`;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return `${str}s`;
|
|
198
|
+
},
|
|
199
|
+
|
|
200
|
+
truncate(str, length) {
|
|
201
|
+
if (str.length > length) {
|
|
202
|
+
return str.slice(0, length) + '...';
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return str;
|
|
206
|
+
},
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export default self;
|
package/src/Tray.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
let TrayActions = {};
|
|
2
|
+
let context = import.meta.glob('/app/Tray/**/*.js');
|
|
3
|
+
let inited = false;
|
|
4
|
+
|
|
5
|
+
//load context menu files
|
|
6
|
+
const loadModules = async () => {
|
|
7
|
+
const files = Object.keys(context);
|
|
8
|
+
|
|
9
|
+
for ( let i = 0; i < files.length; i++ ) {
|
|
10
|
+
let split = files[i].split('/');
|
|
11
|
+
let name = split[split.length - 1].replace('.js', '');
|
|
12
|
+
let module = await context[files[i]]();
|
|
13
|
+
TrayActions[name] = module.default;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default async (tray) => {
|
|
18
|
+
if ( tray.for_window != WINDOW_TYPE ) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if ( !inited ) {
|
|
23
|
+
await loadModules();
|
|
24
|
+
|
|
25
|
+
for ( let item of tray.menuItems ) {
|
|
26
|
+
if ( !item.id ) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let split = item.id.split('/');
|
|
31
|
+
if ( !TrayActions[split[0]] ) {
|
|
32
|
+
throw `Tray Action "${item.id}" not found.`;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
Neutralino.events.on('trayMenuItemClicked', (e) => {
|
|
37
|
+
let split = e.detail.id.split('/');
|
|
38
|
+
let action_name = split[0];
|
|
39
|
+
split.shift();
|
|
40
|
+
TrayActions[action_name].run.apply(this, split);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
inited = true;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
Neutralino.os.setTray(tray);
|
|
47
|
+
};
|
package/src/Validator.js
CHANGED
package/src/Models.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
let Model = {};
|
|
2
|
-
let context = import.meta.glob('/app/Models/**/*.js');
|
|
3
|
-
|
|
4
|
-
//load model files
|
|
5
|
-
const loadModules = async () => {
|
|
6
|
-
const files = Object.keys(context);
|
|
7
|
-
|
|
8
|
-
for ( let i = 0; i < files.length; i++ ) {
|
|
9
|
-
let split = files[i].split('/');
|
|
10
|
-
let name = split[split.length - 1].replace('.js', '');
|
|
11
|
-
let module = await context[files[i]]();
|
|
12
|
-
Model[name] = module.default;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export default async () => {
|
|
17
|
-
await loadModules();
|
|
18
|
-
return Model;
|
|
19
|
-
};
|
|
File without changes
|