@radiantabyss/neutralino 1.0.3 → 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 +19 -6
- package/src/Command.js +41 -0
- package/src/Routing/Middleware.js +1 -1
- package/src/Routing/Route.js +3 -3
- package/src/Routing/Router.js +11 -12
- package/src/Support/Config.js +22 -19
- 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/Tray.js +47 -0
- package/src/Validator.js +1 -1
- package/src/Models.js +0 -19
- /package/src/{InvokeData.js → Invoked.js} +0 -0
package/package.json
CHANGED
package/src/Bootstrap.js
CHANGED
|
@@ -3,21 +3,34 @@ 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';
|
|
9
12
|
|
|
10
|
-
window.RA
|
|
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
|
+
}
|
|
11
28
|
|
|
12
|
-
export default () => {
|
|
13
29
|
//helpers
|
|
14
30
|
for ( let key in Helpers ) {
|
|
15
31
|
window[key] = Helpers[key];
|
|
16
32
|
}
|
|
17
33
|
|
|
18
|
-
window.Config = Config;
|
|
19
|
-
window.Env = Env;
|
|
20
|
-
|
|
21
34
|
window.Response = Response;
|
|
22
35
|
window.Invoked = Invoked;
|
|
23
36
|
window.Validator = Validator;
|
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
|
@@ -20,16 +20,16 @@ function addRoute(method, path, action, middleware, name, throw_error) {
|
|
|
20
20
|
|
|
21
21
|
let component;
|
|
22
22
|
try {
|
|
23
|
-
component = getAction(window.RA.
|
|
23
|
+
component = getAction(window.RA.Actions, split[split.length - 1], namespace, action_name);
|
|
24
24
|
}
|
|
25
25
|
catch(e) {
|
|
26
26
|
if ( throw_error ) {
|
|
27
|
-
throw `Action ${action_name} doesn't exist.`;
|
|
27
|
+
throw `Action "${action_name}" doesn't exist.`;
|
|
28
28
|
}
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
window.RA.
|
|
32
|
+
window.RA.RouteFiles[window.RA.__neutralino_route_file].push({
|
|
33
33
|
name: action_name,
|
|
34
34
|
component,
|
|
35
35
|
path,
|
package/src/Routing/Router.js
CHANGED
|
@@ -4,9 +4,9 @@ import RouteFiles from './RouteFiles.js';
|
|
|
4
4
|
import Route from './Route.js';
|
|
5
5
|
import RouteCrud from './RouteCrud.js';
|
|
6
6
|
|
|
7
|
-
window.RA.
|
|
8
|
-
window.RA.
|
|
9
|
-
window.RA.
|
|
7
|
+
window.RA.RouteFiles = RouteFiles;
|
|
8
|
+
window.RA.Route = Route;
|
|
9
|
+
window.RA.RouteCrud = RouteCrud;
|
|
10
10
|
|
|
11
11
|
let Routes = [];
|
|
12
12
|
|
|
@@ -14,22 +14,22 @@ let Routes = [];
|
|
|
14
14
|
let context = import.meta.glob('/app/Routes/**/*.js');
|
|
15
15
|
|
|
16
16
|
const loadModules = async () => {
|
|
17
|
-
window.RA.
|
|
17
|
+
window.RA.Actions = await Actions();
|
|
18
18
|
const files = Object.keys(context);
|
|
19
19
|
|
|
20
20
|
for ( let i = 0; i < files.length; i++ ) {
|
|
21
21
|
let file = files[i].replace('/app/Routes/', '').replace(/\.js$/, '');
|
|
22
|
-
window.RA.
|
|
22
|
+
window.RA.__neutralino_route_file = file;
|
|
23
23
|
|
|
24
|
-
if ( !window.RA.
|
|
25
|
-
window.RA.
|
|
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
|
|
|
@@ -75,7 +75,6 @@ const match = async(args, event) => {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
Invoked.data = args.payload;
|
|
78
|
-
params.push(event);
|
|
79
78
|
|
|
80
79
|
return {
|
|
81
80
|
Route: matched,
|
|
@@ -90,12 +89,12 @@ export default async () => {
|
|
|
90
89
|
await loadModules();
|
|
91
90
|
|
|
92
91
|
//handle route matching
|
|
93
|
-
IPC.handle('invoke', async (
|
|
92
|
+
IPC.handle('invoke', async (args) => {
|
|
94
93
|
args.payload = JSON.parse(args.payload);
|
|
95
94
|
|
|
96
|
-
let matched = await match(args
|
|
95
|
+
let matched = await match(args);
|
|
97
96
|
if ( !matched.Route ) {
|
|
98
|
-
throw `Route ${matched.path} not found.`;
|
|
97
|
+
throw `Route "${matched.path}" not found.`;
|
|
99
98
|
}
|
|
100
99
|
|
|
101
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
|
-
async get(config) {
|
|
11
|
-
return await self.read(config);
|
|
12
|
-
},
|
|
13
|
-
|
|
14
|
-
async getKey(config, key) {
|
|
10
|
+
async get(config, key = null) {
|
|
15
11
|
let data = await self.read(config);
|
|
16
|
-
return data[key];
|
|
17
|
-
},
|
|
18
12
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
if ( key !== null ) {
|
|
14
|
+
return data[key];
|
|
15
|
+
}
|
|
22
16
|
|
|
23
|
-
|
|
24
|
-
let data = await self.read(config);
|
|
25
|
-
data[key] = value;
|
|
26
|
-
await self.write(config, data);
|
|
17
|
+
return data;
|
|
27
18
|
},
|
|
28
19
|
|
|
29
|
-
async
|
|
30
|
-
let data =
|
|
31
|
-
|
|
20
|
+
async set(config, value, key = null) {
|
|
21
|
+
let data = value;
|
|
22
|
+
|
|
23
|
+
if ( key !== null ) {
|
|
24
|
+
data = await self.read(config);
|
|
25
|
+
data[key] = value;
|
|
26
|
+
}
|
|
27
|
+
|
|
32
28
|
await self.write(config, data);
|
|
33
29
|
},
|
|
34
30
|
|
|
35
|
-
async
|
|
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;
|
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
|