-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbackground.js
More file actions
194 lines (161 loc) · 5.11 KB
/
background.js
File metadata and controls
194 lines (161 loc) · 5.11 KB
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
'use strict'
import { app, protocol, BrowserWindow } from 'electron'
import { createProtocol } from 'vue-cli-plugin-electron-builder/lib'
import installExtension, { VUEJS_DEVTOOLS } from 'electron-devtools-installer'
const fixPath = require('fix-path');
import { rootPath } from 'electron-root-path';
const isDevelopment = process.env.NODE_ENV !== 'production'
const { exec } = require("child_process");
const cors = require('cors');
import path from 'path'
import { platform } from 'os';
import e from 'cors';
const express = require('express');
const exp = express();
const port = 2000;
exp.listen(port, () => console.log("app listening on port ", port));
var kill = require('tree-kill');
var cmd = "ipfs daemon"
// Scheme must be registered before the app is ready
protocol.registerSchemesAsPrivileged([
{ scheme: 'app', privileges: { secure: true, standard: true } }
])
if (process.platform == "win32") {
cmd = "cmd /c ipfs daemon"
}
exec(cmd, (error, data, getter) => {
if (error) {
console.log("error", error.message);
return;
}
if (getter) {
console.log("data", data);
return;
}
console.log("data", data);
});
const root = rootPath;
console.log("root path")
console.log(root)
// const binariesPath = path.join(root, './resources');
// export const jarPath = path.resolve(path.join(binariesPath, './rubix_api.jar'));
// var jarPath = __dirname + '/resources/app.asar.unpacked/rubix_api.jar';
fixPath();
const dirPath = __dirname.replace('app.asar', 'app.asar.unpacked');
console.log(dirPath)
if (process.platform == 'macos') {
jarPath.concat('/')
}
var jarPath = dirPath + '/rubix.jar';
// var jarPath = path.join(app.getAppPath(), '/rubix_api.jar')
// var jarPath = path.resolve(`${process.resourcesPath}/../bin/rubix_api.jar`);
// var jarPath = 'app://./rubix_api.jar'
// var jarPathProd = 'app://./resources/app.asar.unpacked/rubix_api.jar';
console.log("final jarpath here")
console.log(jarPath)
var child;
var jarProcesssPID=0;
function startJar(){
child = require('child_process').spawn(
'java', ['-jar', jarPath, '']
);
jarProcesssPID=child.pid
console.log("process ID of JAR")
console.log(jarProcesssPID)
console.log(child.pid)
child.stdout.on('data', (d) => {
console.log(d.toString())
})
}
startJar();
const nativeImage = require('electron').nativeImage;
var image = nativeImage.createFromPath(__dirname + '/build/icon.png');
image.setTemplateImage(true);
async function createWindow() {
console.log("Static path")
//console.log(__static)
// Create the browser window.
const win = new BrowserWindow({
width: 1410,
height: 1000,
title: "Rubix Wallet",
icon: image,
webPreferences: {
// Use pluginOptions.nodeIntegration, leave this alone
// See nklayman.github.io/vue-cli-plugin-electron-builder/guide/security.html#node-integration for more info
nodeIntegration: true,
defaultEncoding: 'UTF-8',
contextIsolation: false
}
})
if (process.env.WEBPACK_DEV_SERVER_URL) {
// Load the url of the dev server if in development mode
await win.loadURL(process.env.WEBPACK_DEV_SERVER_URL)
if (!process.env.IS_TEST) win.webContents.openDevTools()
} else {
createProtocol('app')
// Load the index.html when not in development
win.loadURL('app://./index.html')
}
}
app.on('window-all-closed', () => {
kill(jarProcesssPID);
app.quit()
})
app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
app.on('ready', async () => {
if (isDevelopment && !process.env.IS_TEST) {
// Install Vue Devtools
try {
await installExtension(VUEJS_DEVTOOLS)
} catch (e) {
console.error('Vue Devtools failed to install:', e.toString())
}
}
createWindow()
})
// Exit cleanly on request from parent process in development mode.
if (isDevelopment) {
if (process.platform === 'win32') {
process.on('message', (data) => {
if (data === 'graceful-exit') {
app.quit()
}
})
} else {
process.on('SIGTERM', () => {
app.quit()
})
}
}exp.get("/checkipfs", function (req, res) {
res.set({
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "*",
"Access-Control-Allow-Headers": "'Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token'",
});
const plat = process.platform
const cmd = plat == 'win32' ? 'tasklist | findstr ipfs.exe' : (plat == 'mac' ? 'ps -e | grep ipfs' : (plat == 'linux' ? 'ps -e | grep ipfs' : ''))
const proc = plat == 'win32' ? 'win' : (plat == 'darwin' ? 'mac' : (plat == 'linux' ? 'linux' : ''))
exec(cmd, (err, data) => {
if(data.includes('ipfs')){
res.status(200).send("TRUE")
}
else{
res.status(400).send("FALSE")
}
})
})
exp.get("/reset",function(req,res) {
res.set({
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "*",
"Access-Control-Allow-Headers": "'Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token'",
});
kill(jarProcesssPID);
res.status(200).send("TRUE")
startJar();
})