Compare commits
6 Commits
main
...
github-fet
Author | SHA1 | Date | |
---|---|---|---|
|
15867de64d | ||
|
3dbc1d7fa5 | ||
228e7d8aa6 | |||
3285770d97 | |||
62846d51e8 | |||
749e8b43d5 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,6 +5,7 @@ npm-debug.log*
|
|||||||
yarn-debug.log*
|
yarn-debug.log*
|
||||||
yarn-error.log*
|
yarn-error.log*
|
||||||
lerna-debug.log*
|
lerna-debug.log*
|
||||||
|
config
|
||||||
|
|
||||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||||
|
42
github.js
Normal file
42
github.js
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
const { Octokit, App } = require("octokit");
|
||||||
|
const {token} = require("./config/gittoken.json");
|
||||||
|
|
||||||
|
// Create a personal access token at https://github.com/settings/tokens/new?scopes=repo
|
||||||
|
var octokit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* initializes githubs octokit to handle interactions with the github api
|
||||||
|
* @param {Electron.BrowserWindow} mainWindow the main window for error handling
|
||||||
|
*/
|
||||||
|
let initGithub = async (mainWindow) => {
|
||||||
|
|
||||||
|
octokit = new Octokit({auth: token});
|
||||||
|
|
||||||
|
mainWindow.webContents.send("github-lookup", "logging in...");
|
||||||
|
|
||||||
|
const { data: { login }, } = await octokit.rest.users.getAuthenticated().catch(async err => {
|
||||||
|
if (err) {
|
||||||
|
console.log(err);
|
||||||
|
mainWindow.webContents.send("error-message", {label: "authentication failed", err: err})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fetches the latest release on a set repository
|
||||||
|
* @param {Electron.BrowserWindow} mainWindow the main window for error handling
|
||||||
|
*/
|
||||||
|
let fetchLatest = async (mainWindow, repo) => {
|
||||||
|
let releases = await octokit.rest.repos.getLatestRelease(repo).catch(async err => {
|
||||||
|
mainWindow.webContents.send("github-lookup", "no releases found");
|
||||||
|
});
|
||||||
|
|
||||||
|
if (releases != undefined) {
|
||||||
|
console.log(releases.data.tag_name);
|
||||||
|
if (releases.data.tag_name != "0.0.0") {
|
||||||
|
mainWindow.webContents.send("github-update", {"tag": releases.data.tag_name});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {initGithub, fetchLatest}
|
@ -11,21 +11,20 @@
|
|||||||
<body>
|
<body>
|
||||||
<div class="titlebar">NCOS Companion</div>
|
<div class="titlebar">NCOS Companion</div>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<h1 class="centered">Latest Version: V<span id="latest">0.0.0</span></h1>
|
<h1 class="centered">Latest Version: <span id="latest">0.0.0</span></h1>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-5">
|
<div class="col-5">
|
||||||
<h4 class="centered">Installed: V<span id="installed">0.0.0</span></h4>
|
<h4 class="centered">Installed: <span id="installed">0.0.0</span></h4>
|
||||||
<button class="download" id="download">Update to V<span id="latest">0.0.0</span></button>
|
<button class="download" id="download">Update to V<span id="latest">0.0.0</span></button>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-7" id="download-section">
|
<div class="col-7" id="download-section">
|
||||||
<h4 class="centered" id="progress-step">Downloading...</h4>
|
<h4 class="centered" id="progress-step">idling<h4>
|
||||||
<div id="progress-bar"><span id="progress-label">100%</span></div>
|
<div id="progress-bar"><span id="progress-label">0%</span></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- You can also require other files to run in this process -->
|
<!-- You can also require other files to run in this process -->
|
||||||
<script src="./render.js"></script>
|
<script src="./render.js"></script>
|
||||||
<script src="./renderer.js"></script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
34
index.js
34
index.js
@ -1,23 +1,15 @@
|
|||||||
// Modules to control application life and create native browser window
|
// Modules to control application life and create native browser window
|
||||||
const { app, BrowserWindow } = require('electron')
|
const { app, BrowserWindow, webContents, ipcRenderer } = require('electron')
|
||||||
const { Octokit, App } = require("octokit");
|
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const {githubtoken} = require("./package.json");
|
const {initGithub, fetchLatest} = require("./github")
|
||||||
|
|
||||||
// Create a personal access token at https://github.com/settings/tokens/new?scopes=repo
|
|
||||||
const octokit = new Octokit({ auth: });
|
|
||||||
|
|
||||||
// Compare: https://docs.github.com/en/rest/reference/users#get-the-authenticated-user
|
|
||||||
const { data: { login } } = await octokit.rest.users.getAuthenticated({auth: githubtoken});
|
|
||||||
console.log("Hello, %s", login);
|
|
||||||
|
|
||||||
|
var mainWindow;
|
||||||
const createWindow = () => {
|
const createWindow = () => {
|
||||||
// Create the browser window.
|
// Create the browser window.
|
||||||
const mainWindow = new BrowserWindow({
|
mainWindow = new BrowserWindow({
|
||||||
width: 600,
|
width: 600,
|
||||||
height: 300,
|
height: 300,
|
||||||
backgroundColor: '#2f3241',
|
backgroundColor: '#2f3241',
|
||||||
symbolColor: '#74b1be',
|
|
||||||
resizable: false,
|
resizable: false,
|
||||||
titleBarStyle: 'hidden',
|
titleBarStyle: 'hidden',
|
||||||
titleBarOverlay: true,
|
titleBarOverlay: true,
|
||||||
@ -34,20 +26,30 @@ const createWindow = () => {
|
|||||||
// and load the index.html of the app.
|
// and load the index.html of the app.
|
||||||
mainWindow.loadFile('index.html')
|
mainWindow.loadFile('index.html')
|
||||||
|
|
||||||
|
mainWindow.on("ready-to-show", async () => {
|
||||||
|
initGithub(mainWindow);
|
||||||
|
fetchLatest(mainWindow, {
|
||||||
|
owner: "Vortex-Dynamics",
|
||||||
|
repo: "NervUpdaterClient"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// Open the DevTools.
|
// Open the DevTools.
|
||||||
// mainWindow.webContents.openDevTools()
|
mainWindow.webContents.openDevTools()
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method will be called when Electron has finished
|
// This method will be called when Electron has finished
|
||||||
// initialization and is ready to create browser windows.
|
// initialization and is ready to create browser windows.
|
||||||
// Some APIs can only be used after this event occurs.
|
// Some APIs can only be used after this event occurs.
|
||||||
app.whenReady().then(() => {
|
app.whenReady().then(async () => {
|
||||||
createWindow()
|
createWindow()
|
||||||
|
|
||||||
app.on('activate', () => {
|
app.on('activate', async () => {
|
||||||
// On macOS it's common to re-create a window in the app when the
|
// 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.
|
// dock icon is clicked and there are no other windows open.
|
||||||
if (BrowserWindow.getAllWindows().length === 0) createWindow()
|
if (BrowserWindow.getAllWindows().length === 0) {
|
||||||
|
createWindow();
|
||||||
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "update companion for ncos dvised",
|
"description": "update companion for ncos dvised",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"githubtoken": "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",
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "electron ."
|
"start": "electron ."
|
||||||
},
|
},
|
||||||
|
10
preload.js
10
preload.js
@ -1,5 +1,13 @@
|
|||||||
// All the Node.js APIs are available in the preload process.
|
// All the Node.js APIs are available in the preload process.
|
||||||
// It has the same sandbox as a Chrome extension.
|
// It has the same sandbox as a Chrome extension.
|
||||||
|
const { contextBridge, ipcRenderer } = require('electron')
|
||||||
|
|
||||||
|
contextBridge.exposeInMainWorld('electronAPI', {
|
||||||
|
handleError: (callback) => ipcRenderer.on("error-message", callback),
|
||||||
|
updateProgress: (callback) => ipcRenderer.on('github-lookup', callback),
|
||||||
|
updateFound: (callback) => ipcRenderer.on('github-update', callback)
|
||||||
|
});
|
||||||
|
|
||||||
window.addEventListener('DOMContentLoaded', () => {
|
window.addEventListener('DOMContentLoaded', () => {
|
||||||
const replaceText = (selector, text) => {
|
const replaceText = (selector, text) => {
|
||||||
const element = document.getElementById(selector)
|
const element = document.getElementById(selector)
|
||||||
@ -9,4 +17,4 @@ window.addEventListener('DOMContentLoaded', () => {
|
|||||||
for (const dependency of ['chrome', 'node', 'electron']) {
|
for (const dependency of ['chrome', 'node', 'electron']) {
|
||||||
replaceText(`${dependency}-version`, process.versions[dependency])
|
replaceText(`${dependency}-version`, process.versions[dependency])
|
||||||
}
|
}
|
||||||
})
|
});
|
35
render.js
35
render.js
@ -1,3 +1,38 @@
|
|||||||
|
window.electronAPI.updateProgress((_event, value) => {
|
||||||
|
updateProgressStep(value);
|
||||||
|
});
|
||||||
|
|
||||||
|
window.electronAPI.updateFound((_event, value) => {
|
||||||
|
toggleDownloadButton(true);
|
||||||
|
updateLatestHeader(value.tag);
|
||||||
|
});
|
||||||
|
|
||||||
|
window.electronAPI.handleError((_event, value) => {
|
||||||
|
let error = `
|
||||||
|
<div class="titlebar">NCOS Companion</div>
|
||||||
|
<div class="content">
|
||||||
|
<h1 class="centered">An Error Occured</h1>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
<h4 class="centered">${value.label}</h4>
|
||||||
|
<h4 class="centered">pleas report this to <a class="link" target="_blank" href="https://github.com/Vortex-Dynamics/NervUpdaterClient/issues">us</a></h4>
|
||||||
|
<pre class="centered">${value.err}</pre>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
document.querySelector("body").innerHTML = error;
|
||||||
|
});
|
||||||
|
|
||||||
|
function updateLatestHeader(version) {
|
||||||
|
document.getElementById("latest").innerHTML = version;
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateCurrentHeader(version) {
|
||||||
|
document.getElementById("installed").innerHTML = version;
|
||||||
|
}
|
||||||
|
|
||||||
function updateProgressBar(progress){
|
function updateProgressBar(progress){
|
||||||
document.getElementById("progress-bar").style.width = progress + "%";
|
document.getElementById("progress-bar").style.width = progress + "%";
|
||||||
document.getElementById("progress-label").textContent = progress + "%";
|
document.getElementById("progress-label").textContent = progress + "%";
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
// You can also put expose this code to the renderer
|
|
||||||
// process with the `contextBridge` API
|
|
||||||
const { ipcRenderer } = require('electron')
|
|
||||||
|
|
||||||
// render proccess receiver for github api data
|
|
||||||
ipcRenderer.on('github-lookup', (_event, arg) => {
|
|
||||||
console.log(arg) // prints "pong" in the DevTools console
|
|
||||||
});
|
|
15
style.css
15
style.css
@ -13,6 +13,13 @@ h4 {
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pre {
|
||||||
|
border: 1px solid #74b1be;
|
||||||
|
border-radius: 5px;
|
||||||
|
padding: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
.content {
|
.content {
|
||||||
padding-left: 15.5%;
|
padding-left: 15.5%;
|
||||||
padding-right: 15.5%;
|
padding-right: 15.5%;
|
||||||
@ -35,6 +42,7 @@ h4 {
|
|||||||
width: 90%;
|
width: 90%;
|
||||||
font-size: 15px;
|
font-size: 15px;
|
||||||
height: 33px;
|
height: 33px;
|
||||||
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.download:hover {
|
.download:hover {
|
||||||
@ -45,6 +53,7 @@ h4 {
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
border: 1px solid #74b1be;
|
border: 1px solid #74b1be;
|
||||||
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
#progress-bar {
|
#progress-bar {
|
||||||
@ -52,18 +61,24 @@ h4 {
|
|||||||
height: 33px;
|
height: 33px;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
background-color: #74b1be;
|
background-color: #74b1be;
|
||||||
|
display:none;
|
||||||
}
|
}
|
||||||
|
|
||||||
#progress-label {
|
#progress-label {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
color: white;
|
color: white;
|
||||||
padding: 1.5%;
|
padding: 1.5%;
|
||||||
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
div[class^=col-] {
|
div[class^=col-] {
|
||||||
padding: 1rem 0
|
padding: 1rem 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.link {
|
||||||
|
color: #74b1be;
|
||||||
|
}
|
||||||
|
|
||||||
.row {
|
.row {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-wrap: wrap
|
flex-wrap: wrap
|
||||||
|
Reference in New Issue
Block a user