forked from dynamiccreator/aliwa
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
202 lines (158 loc) · 6.21 KB
/
main.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
const { app, BrowserWindow} = require('electron');
const path = require('path');
//start tor on windows or mac
if(process.platform == 'darwin' || process.platform == 'win32'){
try {
const fs = require('fs');
const exec = require('child_process').exec;
// var sep_linux = process.cwd().indexOf("/") > -1;
// var sep = sep_linux ? "/" : "\\";
var aliwa_tor_folder = "Tor";
var aliwa_app_data = "";
var aliwa_app_data_tor_DIR = "";
var aliwa_app_data_tor_APP = "";
if (process.platform == 'darwin') {
aliwa_app_data = path.join(process.env.HOME, "Library", 'Application Support', "ALiWa");
aliwa_app_data_tor_DIR = path.join(aliwa_app_data, aliwa_tor_folder);
aliwa_app_data_tor_APP = path.join(aliwa_app_data_tor_DIR, 'tor.real');
}
if(process.platform == 'win32'){
aliwa_app_data=path.join(process.env.APPDATA,"ALiWa");
aliwa_app_data_tor_DIR=path.join(aliwa_app_data,aliwa_tor_folder);
aliwa_app_data_tor_APP=path.join(aliwa_app_data_tor_DIR,'tor.exe');
}
var folder_wait=0;
if ((process.platform == 'darwin' || process.platform == 'win32') && !fs.existsSync(aliwa_app_data)) {folder_wait=2000;}
setTimeout(function () { // wait for the ALiWA folder to be created after first app start
if (!fs.existsSync(aliwa_app_data_tor_DIR)) {
if(process.platform == 'darwin'){
const execute1 = exec("cp -R " +'"'+path.join(__dirname,"..","..","MacOS",aliwa_tor_folder) + '" "' + aliwa_app_data+'"');
execute1.stdout.on('data', (data) => {
console.log(data);
console.error(data);
// do whatever you want here with data
});
execute1.stderr.on('data', (data) => {
console.error(data);
});
}
if(process.platform == 'win32'){
const execute1 = exec('xcopy "'+__dirname+'\\..\\..\\'+aliwa_tor_folder+'" "'+aliwa_app_data+'\\'+aliwa_tor_folder+'\\" /E/H');
execute1.stdout.on('data', (data) => {
console.log(data);
console.error(data);
// do whatever you want here with data
});
execute1.stderr.on('data', (data) => {
console.error(data);
});
}
}},folder_wait);// wait for the ALiWA folder to be created after first app start
if(process.platform == 'darwin'){
setTimeout(function () {
try {
const execute2 = exec("chmod +x "+'"'+aliwa_app_data_tor_APP+'"');
execute2.stdout.on('data', (data) => {
console.log(data);
// do whatever you want here with data
});
execute2.stderr.on('data', (data) => {
console.error(data);
});
} catch (e) {
console.error(e);
}
}, 1000+folder_wait);
}
setTimeout(function () {
try {
if(process.platform == 'darwin'){aliwa_app_data_tor_APP='"'+aliwa_app_data_tor_APP+'"';}
const myShellScript = exec(aliwa_app_data_tor_APP);
myShellScript.stdout.on('data', (data) => {
console.log(data);
// do whatever you want here with data
});
myShellScript.stderr.on('data', (data) => {
console.error(data);
});
} catch (e) {
console.error(e);
}
}, 1500+folder_wait);
} catch (e) {
console.error(e);
}
}
/*setTimeout(function(){
require(path.join(__dirname,"./ipc_communications"))();
},500);*/
require(path.join(__dirname,"./ipc_communications"))();
app.commandLine.appendSwitch("use-cmd-decoder","validating") //prevent graphical glitches (hopefully)
app.commandLine.appendSwitch("use-gl","desktop"); //prevent graphical glitches (hopefully)
function createWindow () {
const win = new BrowserWindow({
width: 400,
height: 750,
// resizable: false,
// frame: false ,
webPreferences: {
enableRemoteModule:false,
preload: path.join(__dirname,'./preload.js'),
nodeIntegration: false,
contextIsolation: true,
allowRunningInsecureContent: false,
sandbox: true,
}/*,
icon: "/view_resources/img/aliwa_icon_256.png" */// crashes on startup | __dirname is not needed here
});
win.loadFile('index.html')
win.setMenu(null)
// win.setIcon(__dirname+"/view_resources/img/aliwa_icon_256.png") // no crash but default icon remains | __dirname is needed here
}
app.whenReady().then(createWindow);
app.on('window-all-closed', async() => {
save_on_exit();
if (process.platform !== 'darwin') {
app.quit();
}
});
//prevent external links
app.on('web-contents-created', (event, contents) => {
contents.on('will-navigate', (event, navigationUrl) => {
event.preventDefault()});
//prevent open new window
contents.on('new-window', function(event, urlToOpen) {
event.defaultPrevented = true;
});
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
// contextBridge.exposeInMainWorld("app", {}
// ipcRenderer_invoke: (channel) => ipcRenderer.invoke("channel",channel)
// );
//
//ipcRenderer_handle: (channel,...params) => ipcRenderer.handle(channel, async (event, ...params) => {
// console.log(event);
// console.log(params);
// }),
// const electron = require('electron'),
// ipc = electron.ipcMain;
// require(".logic/wallet")();
// /* remaining code
// .
// .
// */
//////Receive and reply to synchronous message
////ipc.on('helloSync', (event, args) => {
//// //do something with args
//// event.returnValue = 'Hi, sync reply';
////});
//
////Receive and reply to asynchronous message
// ipc.on('get_overview', (event, args) => {
//// event.sender.send('asynReply', 'Hi, asyn reply');
// console.log("fetch overview....")
// });
});