Skip to content

Commit 2635fe6

Browse files
committed
Automatic Updates
1 parent e088795 commit 2635fe6

File tree

6 files changed

+243
-8
lines changed

6 files changed

+243
-8
lines changed

package.json

+8-7
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,16 @@
1616
"build-win": "npm run compile-vue && electron-builder --win",
1717
"build-mac": "npm run compile-vue && electron-builder --mac",
1818
"build-docker": "npm run build && sudo docker build -t offs .",
19+
"publish": "build -p onTag",
1920
"docker": "sudo docker run -a STDERR -a STDOUT -p 23402:23402 -p 8200:8200 --name offsystem offs "
2021
},
2122
"author": "Prometheus <[email protected]>",
2223
"license": "GPL-3.0",
23-
"repository": "https://github.com/Prometheus-SCN/js-offs.git",
24+
"repository": "https://github.com/vijayee/js-offs",
2425
"build": {
2526
"productName": "offs",
2627
"appId": "com.prometheus.offsystem",
2728
"publish": "github",
28-
"extraFiles": [
29-
{
30-
"from": "LICENSE.md",
31-
"to": "license.txt"
32-
}
33-
],
3429
"directories": {
3530
"output": "dist"
3631
},
@@ -77,6 +72,12 @@
7772
]
7873
}
7974
],
75+
"extraFiles": [
76+
{
77+
"from": "LICENSE.md",
78+
"to": "license.txt"
79+
}
80+
],
8081
"vendor": "Prometheus",
8182
"synopsis": "The Owner Free File System (OFF System)(OFFS) is the world's first 'brightnet'. It facilitates legal data sharing activity over its network through the use of its ingenious data storage mechanisms. This allows it to perform its operations in the open without divulging the privacy, intent, or security of its network participants. The storage mechanism is unique in that it never stores whole files but instead stores completely random data blocks.",
8283
"description": "The Owner Free File System",

src/electron/views/update/index.html

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html lang="en" style="overflow: hidden !important;">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Off System Update</title>
6+
<link rel="stylesheet" href="../../stylesheets/index.css">
7+
<link rel="stylesheet" href="../../stylesheets/bulma.css"/>
8+
<link rel="stylesheet" href="../../stylesheets/font-awesome.css"/>
9+
<link rel="image_src" href="/images/off-logo.gif"/>
10+
</head>
11+
<script>
12+
const ipcRenderer = require('electron').ipcRenderer
13+
const Updator = require('../../../updator').rendererUpdator
14+
</script>
15+
16+
<body style="overflow: hidden !important;">
17+
<div id="app" style="overflow:hidden;"></div>
18+
<script src="index.js"></script>
19+
</body>
20+
</html>

src/electron/views/update/main.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var Vue = require('vue')
2+
var App = require('./update.vue')
3+
4+
new Vue({
5+
el: '#app',
6+
render: function (createElement) {
7+
return createElement(App)
8+
}
9+
})

src/electron/views/update/update.vue

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
<template>
2+
<div>
3+
<div ref="fileStatus">
4+
<div class="file-status">
5+
<div class="icontainer">
6+
<img :class="error ? 'loader-icon error' : 'loader-icon'" :src="icon">
7+
</div>
8+
<div class="file-info">
9+
<table>
10+
<tr>
11+
<td>
12+
<strong>status:</strong>
13+
{{status}}
14+
</td>
15+
</tr>
16+
<tr>
17+
<td>
18+
<progressbar :error="error" :percent="percent"></progressbar>
19+
</td>
20+
</tr>
21+
</table>
22+
</div>
23+
</div>
24+
</div>
25+
</div>
26+
</template>
27+
<style scoped>
28+
strong {
29+
font-family: Odin;
30+
}
31+
.icontainer {
32+
display: flex;
33+
min-height: 100px;
34+
min-width: 100px;
35+
height: 100px;
36+
width: 100px;
37+
background-color: #f4d8c0;
38+
border-radius: 10px;
39+
margin: 5px;
40+
}
41+
.loader-icon.error {
42+
background-color: transparent;
43+
}
44+
.loader-icon {
45+
background-color: transparent;
46+
border-radius: 10px;
47+
height: 80px;
48+
width: 80px;
49+
margin: 50% 50%;
50+
transform: translate(-50%, -50%);
51+
}
52+
.form-container {
53+
max-height: 128px;
54+
max-width: 500px;
55+
min-height: 128px;
56+
min-width: 500px;
57+
height: 128px;
58+
width: 500px;
59+
}
60+
.file-info {
61+
display: flex;
62+
}
63+
.file-status {
64+
display: flex;
65+
flex-direction: row;
66+
margin: 5px;
67+
}
68+
69+
.download-button {
70+
height: 100%;
71+
width: auto;
72+
min-width: 100px;
73+
font-family: Odin;
74+
background-color: #edf0f2;
75+
padding: 0;
76+
display: flex;
77+
border-color: #878787;
78+
border-style: dotted;
79+
border-width: 10px;
80+
padding: 3px;
81+
color: #878787;
82+
outline: 5px solid #edf0f2;
83+
margin: 5px;
84+
font-family: Odin;
85+
align-self: center;
86+
align-content: center;
87+
justify-content: center;
88+
flex-direction: column;
89+
}
90+
.error {
91+
color: red;
92+
}
93+
</style>
94+
<script>
95+
let progressbar = require('../export/progressbar.vue')
96+
module.exports = {
97+
components: {progressbar},
98+
data () {
99+
return {
100+
error: null,
101+
percent: 0,
102+
icon: '../../images/off-logo-lettered.svg',
103+
status: null,
104+
updator: null
105+
}
106+
},
107+
mounted () {
108+
let onError = (err) => {
109+
this.error = err
110+
}
111+
let onCheckingForUpdate = () => {
112+
this.status = 'Checking for update'
113+
}
114+
let onUpdateAvailable = (info) => {
115+
console.log(info)
116+
this.status = 'Update Found'
117+
}
118+
let onDownloadProgress = (info) => {
119+
this.percent = info.percent
120+
}
121+
let onUpdateNotAvailable = () =>{
122+
this.status = 'Everything Up To Date'
123+
this.percent = 100
124+
}
125+
let onUpdatedDownloaded = (info) => {
126+
this.percent = 100
127+
this.status = 'Update Completed....Restarting'
128+
}
129+
this.updator = new Updator(ipcRenderer, onError, onCheckingForUpdate, onUpdateAvailable, onUpdateNotAvailable, onDownloadProgress, onUpdatedDownloaded)
130+
}
131+
}
132+
</script>

src/index.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const trayIcon = path.join(__dirname, 'electron', 'images', (/^darwin/.test(proc
77
const Exporter = require('./exporter').mainExporter
88
const Connector = require('./connector').mainConnector
99
const Configurator = require('./configurator').mainConfigurator
10+
const Updator = require('./updator').mainUpdator
11+
const {autoUpdater} = require("electron-updater")
1012
const Peer = require('./peer')
1113
const bs58 = require('bs58')
1214
const cmd = require('./command').parse()
@@ -304,8 +306,24 @@ if (process.env.ELECTRON_RUN_AS_NODE || cmd.terminal) {
304306
})
305307
})
306308
}
309+
function createUpdateWindow () {
310+
let updateWin = new BrowserWindow({ width: 425, height: 120, icon: icon, autoHideMenuBar: true, resizable: true , show: false})
311+
let onComplete = () => {
312+
updateWin.close()
313+
createTray()
314+
}
315+
let updator = new Updator(updateWin.webContents, ipcMain, autoUpdater, onComplete)
316+
updateWin.loadURL(`file://${path.join(__dirname, 'electron', 'views', 'update', 'index.html')}`)
317+
updateWin.webContents.on('did-finish-load', function() {
318+
updateWin.show()
319+
updator.checkForUpdatesAndNotify()
320+
})
321+
//updateWin.webContents.openDevTools({})
322+
}
307323

308-
app.on('ready', createTray)
324+
app.on('ready', () =>{
325+
createUpdateWindow()
326+
})
309327

310328
app.on('activate', () => {
311329
// On macOS it's common to re-create a window in the app when the

src/updator.js

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
const responder = require('electron-ipc-responder')
2+
3+
class rendererUpdator extends responder {
4+
constructor (ipcRenderer, onError, onCheckingForUpdate, onUpdateAvailable, onUpdateNotAvailable, onDownloadProgress, onUpdatedDownloaded) {
5+
super(ipcRenderer.send.bind(ipcRenderer), ipcRenderer.on.bind(ipcRenderer))
6+
this.registerTopic('error', async (err) => onError(err))
7+
this.registerTopic('checking-for-update', async () => onCheckingForUpdate())
8+
this.registerTopic('update-available', async (info) => onUpdateAvailable(info))
9+
this.registerTopic('update-not-available', async (info) => onUpdateNotAvailable(info))
10+
this.registerTopic('download-progress', async (info) => onDownloadProgress(info))
11+
this.registerTopic('update-downloaded', async (info) => onUpdatedDownloaded(info))
12+
}
13+
14+
}
15+
let _autoUpdater = new WeakMap()
16+
class mainUpdator extends responder {
17+
constructor (webContents, ipcMain, autoUpdater, onComplete) {
18+
super(webContents.send.bind(webContents), ipcMain.on.bind(ipcMain))
19+
autoUpdater.autoDownload = false
20+
_autoUpdater.set(this, autoUpdater)
21+
autoUpdater.on('checking-for-update', () => {
22+
this.tell('checking-for-update')
23+
})
24+
autoUpdater.on('update-available', (info) => {
25+
console.log(info)
26+
this.tell('update-available', info)
27+
autoUpdater.downloadUpdate()
28+
})
29+
autoUpdater.on('update-not-available', (info) => {
30+
console.log(info)
31+
this.tell('update-not-available', info)
32+
setTimeout(onComplete, 2000)
33+
})
34+
autoUpdater.on('error', (err) => {
35+
this.tell('error', err)
36+
})
37+
autoUpdater.on('download-progress', (progressObj) => {
38+
console.log(progressObj)
39+
this.tell('download-progress', progressObj)
40+
})
41+
autoUpdater.on('update-downloaded', (info) => {
42+
console.log(info)
43+
this.tell('update-downloaded', info)
44+
//setTimeout((() => autoUpdater.quitAndInstall()), 6000)
45+
})
46+
}
47+
checkForUpdatesAndNotify () {
48+
let autoUpdater = _autoUpdater.get(this)
49+
console.log('checking stuff')
50+
autoUpdater.checkForUpdatesAndNotify()
51+
}
52+
}
53+
54+
55+
module.exports= {rendererUpdator, mainUpdator}

0 commit comments

Comments
 (0)