Skip to content

Commit 4516129

Browse files
committed
Self-Updater
1 parent a7554b2 commit 4516129

File tree

22 files changed

+600
-142
lines changed

22 files changed

+600
-142
lines changed

.github/workflows/build.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ jobs:
1717
with:
1818
node-version: 16
1919
- run: npm install
20+
21+
- run: npm run svelte-build
2022

2123
- uses: actions/setup-python@v4
2224
with:
@@ -61,6 +63,8 @@ jobs:
6163
node-version: 16
6264
- run: npm install
6365

66+
- run: npm run svelte-build
67+
6468
- uses: actions/setup-python@v4
6569
with:
6670
python-version: '3.10'
@@ -104,6 +108,8 @@ jobs:
104108
node-version: 16
105109
- run: npm install
106110

111+
- run: npm run svelte-build
112+
107113
- uses: actions/setup-python@v4
108114
with:
109115
python-version: '3.10'

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v1.0.1

changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ Added Change Plot.
88
Added Trajectory Plot.
99
added more plots.
1010
added overlay for Orgs.
11-
Release 1.0
11+
Release 1.0
12+
Self-Updater

index.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
const fetch = require('node-fetch');
2+
const fs = require('fs');
3+
const path = require('path');
4+
const semver = require('semver');
5+
const os = require("node:os");
6+
const yauzl = require('yauzl');
7+
const proc = require('child_process');
8+
9+
10+
function toPromise(api) {
11+
return function(...args) {
12+
return new Promise((resolve, reject) => {
13+
api(...args, (error, response) => {
14+
if(error) {
15+
return reject(error);
16+
}
17+
resolve(response);
18+
});
19+
});
20+
}
21+
}
22+
23+
async function decompress(file) {
24+
let yauzlPromise = toPromise(yauzl.open);
25+
let zipfile = await yauzlPromise(file, {lazyEntries: true});
26+
let openReadStream = toPromise(zipfile.openReadStream.bind(zipfile));
27+
zipfile.readEntry();
28+
zipfile.on("entry", async (entry) => {
29+
if(/\/$/.test(entry.fileName)) {
30+
console.log(`Folder?: ${entry.fileName}`)
31+
if(!fs.existsSync(path.join(__dirname, 'dist', entry.fileName))) {
32+
fs.mkdirSync(path.join(__dirname, 'dist', entry.fileName));
33+
}
34+
zipfile.readEntry();
35+
}
36+
else {
37+
const zipStream = fs.createWriteStream(path.join(__dirname, 'dist', entry.fileName));
38+
let stream = await openReadStream(entry);
39+
stream.on("end", () => {
40+
zipfile.readEntry();
41+
});
42+
stream.pipe(zipStream);
43+
zipStream.on("finish", () => {
44+
console.log(`Updated ${entry.fileName}`);
45+
});
46+
}
47+
});
48+
}
49+
50+
async function runMain() {
51+
await decompress(path.join(__dirname, 'dist', 'main2.zip'));
52+
let command = path.join(__dirname, 'dist', 'main', 'main')
53+
let args = []
54+
// if(isDev) {
55+
// console.log("DEV-Build");
56+
// command = 'python';
57+
// args = ['-u','main.py']
58+
// }
59+
//let child = proc.spawn('python', ['-u','main.py']);
60+
console.log(command);
61+
let child = proc.spawn(command, args);
62+
63+
let eel_started = false;
64+
65+
child.stdout.on('data', function(data) {
66+
console.log('stdout: ' + data);
67+
68+
if (data.toString().includes('[eel]: Start')) {
69+
eel_started = true;
70+
}
71+
});
72+
73+
child.stderr.on('data', function(data) {
74+
console.log('stderr: ' + data);
75+
});
76+
}
77+
78+
runMain();

0 commit comments

Comments
 (0)