forked from aspectron/kdx
-
Notifications
You must be signed in to change notification settings - Fork 7
/
nw-app.js
178 lines (156 loc) · 4.44 KB
/
nw-app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
false && chrome.developerPrivate.openDevTools({
renderViewId: -1,
renderProcessId: -1,
extensionId: chrome.runtime.id,
});
const App = require("./app.js");
const fs = require("fs");
const path = require("path");
const { dpc } = require("@aspectron/flow-async");
class NWApp extends App{
constructor(options){
super(options)
}
/**
* Main process
* @return {Promise}
*/
main() {
if(!this.dataFolder)
return Promise.resolve();
return new Promise((resolve, reject) => {
console.log('ControllerModule - init()'.bold);
nw.Window.open('modules/controller/controller.html', {
//new_instance: true,
id: 'karlsen-desktop',
title: 'Karlsen Desktop',
width: 1027,
height: 768,
resizable: true,
frame: false,
transparent: false,
show: true,
icon: 'resources/images/karlsen-desktop-icon.png'
// http://docs.nwjs.io/en/latest/References/Manifest%20Format/#window-subfields
}, (win) => {
console.log("win", win)
resolve();
});
});
}
/**
* initlizing data folder error handler
*/
dataDirInitError(){
console.error(`Please start app with --init=/path/to/data/dir or --init for default (~/.karlsen-desktop/data)`.red);
nw.Window.open('modules/initialize/initialize.html', {
//new_instance: true,
id: 'initialize',
title: 'Karlsen Desktop',
width: 1027,
height: 768,
resizable: true,
frame: true,
transparent: false,
show: true,
icon: 'resources/images/karlsen-desktop-icon.png'
// http://docs.nwjs.io/en/latest/References/Manifest%20Format/#window-subfields
}, (win) => {
});
}
initRPCHooks(){
super.initRPCHooks();
let rpc = this.rpc;
rpc.on("set-invert-terminals", (args)=>{
let {invertTerminals} = args;
if(invertTerminals == undefined)
return
this.setInvertTerminals(invertTerminals);
});
rpc.on("set-run-in-bg", (args)=>{
let {runInBG} = args;
if(runInBG == undefined)
return
this.setRunInBG(runInBG);
});
rpc.on("set-enable-metrics", (args)=>{
let {enableMetrics} = args;
if(enableMetrics == undefined)
return
this.setEnableMetrics(enableMetrics);
});
rpc.on("set-statsd-address", (args)=>{
let {statsdAddress} = args;
if(statsdAddress == undefined)
return
this.setStatsdAddress(statsdAddress);
});
rpc.on("set-statsd-prefix", (args)=>{
let {statsdPrefix} = args;
if(statsdPrefix == undefined)
return
this.setStatsdPrefix(statsdPrefix);
});
rpc.on("set-build-type", (args)=>{
let {build} = args;
if(build == undefined)
return
this.setBuildType(build);
});
rpc.on("set-compounding", ({compounding})=>{
this.config.compounding = compounding;
this.setConfig(this.config);
})
rpc.on("set-modules-config", (args, callback)=>{
let {config} = args;
if(!config)
return callback({error:"Invalid Config"})
this.saveModulesConfig(config);
callback(null, {config:this.getModulesConfig()})
});
rpc.on("get-modules-config", (args, callback)=>{
callback(null, {config:this.getModulesConfig()})
});
rpc.on("remove-datadir", async (args, callback)=>{
let removed = await this.removeDataDir();
callback(null, {removed})
})
rpc.on("set-skip-utxoindex", async (args, callback)=>{
this.setSkipUTXOIndex(args.skipIndex);
let skipUTXOIndex = this.getSkipUTXOIndex();
callback(null, {skipUTXOIndex, config:this.getModulesConfig()})
})
rpc.on("set-config-template", (args, callback)=>{
let { defaults, network } = args;
if(defaults && network)
this.setModulesConfigTemplate(defaults,network);
callback(null, {config:this.config});
});
rpc.on("set-app-data-dir", async (args, callback)=>{
let {dataDir, restartDelay, defaults, network, upnpEnabled } = args;
//return callback({error: "Invalid directory"});
if(defaults && network) {
this.setModulesConfigTemplate(defaults, network, upnpEnabled);
}
if(dataDir === ""){
await this.setDataDir(dataDir, restartDelay||2000);
return
}
if(dataDir == undefined || !fs.existsSync(dataDir))
return callback({error: "Invalid directory"})
fs.stat(dataDir, async(err, stats)=>{
if(err)
return callback(err);
if(!stats.isDirectory())
return callback({error: "Invalid directory"});
await this.setDataDir(dataDir, restartDelay||2000);
})
});
}
async setDataDir(dataDir, restartDelay = 0){
await super.setDataDir(dataDir);
this.rpc.dispatch("disable-ui", {CODE:'DATA-DIR'})
dpc(restartDelay, ()=>this.reload());
}
}
module.exports = NWApp