Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add auto-update workflow #786

Merged
merged 27 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c3f8562
Add auto-update workflow
garrettmflynn May 20, 2024
6e1d109
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 20, 2024
5078d88
Intelligently render bytes
garrettmflynn May 20, 2024
3aa665f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 20, 2024
dc25d64
Merge branch 'main' into autoupdate
garrettmflynn May 20, 2024
60d9e73
Merge branch 'main' into autoupdate
CodyCBakerPhD May 21, 2024
c5d237f
attempt to resolve conflict
CodyCBakerPhD May 29, 2024
bacbce8
Merge branch 'main' into autoupdate
CodyCBakerPhD May 29, 2024
1ed277b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 29, 2024
230e491
fix improper conflicts
CodyCBakerPhD May 29, 2024
8f2ec90
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 29, 2024
ea768a9
remove getting started page; correct relative path to assets
CodyCBakerPhD May 29, 2024
6e2c586
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 29, 2024
c52f4d6
swap to base 10
CodyCBakerPhD May 29, 2024
b093a70
Merge branch 'autoupdate' of https://github.com/neurodatawithoutborde…
CodyCBakerPhD May 29, 2024
c45b055
fix relative paths again
CodyCBakerPhD May 29, 2024
96d5c89
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 29, 2024
c36b461
fix relative paths again
CodyCBakerPhD May 29, 2024
391bca4
fix relative paths again
CodyCBakerPhD May 29, 2024
d6cd1b7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 29, 2024
be5a4eb
Merge branch 'main' into autoupdate
garrettmflynn May 29, 2024
a78b4d7
Update SettingsPage.js
garrettmflynn May 29, 2024
43b1ed6
Update SettingsPage.js
garrettmflynn May 29, 2024
4aa5384
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 29, 2024
de0dd02
Merge branch 'main' into autoupdate
CodyCBakerPhD May 29, 2024
e28a5e7
Merge branch 'main' into autoupdate
CodyCBakerPhD May 29, 2024
d0f90ad
Merge branch 'main' into autoupdate
CodyCBakerPhD May 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 58 additions & 6 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,24 @@ import icon from '../renderer/assets/img/logo-guide-draft.png?asset'
import splashHTML from './splash-screen.html?asset'
import preloadUrl from './../preload/preload.js?asset'

import devUpdateConfig from './dev-app-update.yml?asset'


import { autoUpdater } from 'electron-updater';


const runByTestSuite = !!process.env.VITEST

// Configure AutoUpdater
autoUpdater.autoDownload = false; // Disable auto download of updates
autoUpdater.channel = "latest";

// Enable remote debugging port for Vitest
if (runByTestSuite) {
app.commandLine.appendSwitch('remote-debugging-port', `${8315}`) // Mirrors the global electronDebugPort variable
app.commandLine.appendSwitch('remote-allow-origins', '*') // Allow all remote origins
}

// autoUpdater.channel = "latest";

/*************************************************************
* Python Process
*************************************************************/
Expand Down Expand Up @@ -215,8 +223,6 @@ const killAllPreviousProcesses = async () => {
} else console.error('Cannot kill previous processes because fetch is not defined in this version of Node.js')
};

let updatechecked = false;

let hasBeenOpened = false;

function initialize() {
Expand Down Expand Up @@ -352,15 +358,16 @@ function initialize() {
win.show();
createWindow();

// autoUpdater.checkForUpdatesAndNotify();
updatechecked = true;
// Check for updates
autoUpdater.checkForUpdates();

// Clear ready queue
readyQueue.forEach(f => onWindowReady(f))
readyQueue = []

}, hasBeenOpened ? 100 : 1000);
});

}


Expand Down Expand Up @@ -515,3 +522,48 @@ ipcMain.on("get-server-file-path", (event) => {
ipcMain.on("python.status", (event) => {
if (globals.python.sent) ((globals.python.status) ? pythonIsOpen : pythonIsClosed)(true); // Force send
});

// Add auto-updater events

ipcMain.on('download-update', () => {
autoUpdater.downloadUpdate()
})

autoUpdater.on('update-available', (info) => {
onWindowReady((win) => send.call(win, 'update-available', info))
});

autoUpdater.on('update-not-available', () => {
onWindowReady((win) => send.call(win, 'update-available', false))
});

autoUpdater.on('error', (err) => {
onWindowReady((win) => send.call(win, 'update-error', err))
});

autoUpdater.on('download-progress', (progressObj) => {
onWindowReady((win) => send.call(win, 'update-progress', {
n: progressObj.transferred,
total: progressObj.total,
rate: progressObj.bytesPerSecond,
}))
});

autoUpdater.on('update-downloaded', (info) => {

onWindowReady((win) => {
send.call(win, 'update-complete', info)

// Prompt user to install update
dialog
.showMessageBox(win, {
type: 'info',
buttons: ['Restart', 'Later'],
title: 'Update available',
message: 'A new version has been downloaded. Restart now to install the update?',
})
.then((result) => {
if (result.response === 0) autoUpdater.quitAndInstall();
});
})
});
51 changes: 51 additions & 0 deletions src/renderer/assets/css/custom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* Update Notification Box */
#update-available:not(:empty) {
margin-top: 15px;
background-color: #ffe5d2;
color: black;
padding: 15px 10px;
border: 1px solid #f6c39c;
border-radius: 5px;
}

#update-available .update-container {
display: flex;
align-items: center;
gap: 15px;
}

#update-available .update-container::before {
content: "";
width: 6px;
height: 6px;
margin-left: 5px;
background-color: #d17128;
border-radius: 50%;
}

#update-available .header {
display: flex;
align-items: center;
gap: 5px;
}

#update-available h4 {
margin: 0;
}

#update-available span {
color: gray;
font-size: 80%;
}

#update-available .header svg {
height: 15px;
width: auto;
cursor: pointer;
}

#update-available .controls {
margin-left: auto;
display: flex;
gap: 10px;
}
19 changes: 17 additions & 2 deletions src/renderer/assets/css/nav.css
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,10 @@ a[data-toggle="collapse"] {

#main-nav .sidebar-body a {
font-size: 14px;
display: block;
line-height: 45px;
display: flex;
align-items: center;
position: relative;
padding: 15px 0px;
padding-left: 20px;
margin-bottom: 5px;
text-align: left;
Expand All @@ -170,6 +172,19 @@ a[data-toggle="collapse"] {
border-left: 4px solid transparent;
}

[data-update-available] [data-id="settings"] > div {
display: flex;
flex-direction: column;
}

[data-update-available] [data-id="settings"] > div::after {
content: "Update Available";
color: gray;
font-size: 70%;
font-weight: normal;
line-height: 1.5;
}

#main-nav .sidebar-body svg {
fill: #000;
}
Expand Down
35 changes: 35 additions & 0 deletions src/renderer/src/electron/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,32 @@ export let path = null;
export let log = null;
export let crypto = null;

let updateAvailable = false;
const updateAvailableCallbacks = [];
export const onUpdateAvailable = (callback) => {
if (updateAvailable) callback(updateAvailable);
else updateAvailableCallbacks.push(callback);
};

let updateProgress = null;

const updateProgressCallbacks = [];
export const onUpdateProgress = (callback) => {
if (updateProgress) callback(updateProgress);
else updateProgressCallbacks.push(callback);
};

export const registerUpdateProgress = (info) => {
updateProgress = info;
updateProgressCallbacks.forEach((cb) => cb(info));
};

const registerUpdate = (info) => {
updateAvailable = info;
document.body.setAttribute("data-update-available", JSON.stringify(info));
updateAvailableCallbacks.forEach((cb) => cb(info));
};

// Used in tests
try {
crypto = require("crypto");
Expand All @@ -39,6 +65,15 @@ if (isElectron) {
electron.ipcRenderer.on(`console.${method}`, (_, ...args) => console[method](`[main-process]:`, ...args))
);

electron.ipcRenderer.on(`checking-for-update`, (_, ...args) => console.log(`[Update]:`, ...args));

electron.ipcRenderer.on(`update-available`, (_, info) => (info ? registerUpdate(info) : ""));

electron.ipcRenderer.on(`update-progress`, (_, info) => registerUpdateProgress(info));
electron.ipcRenderer.on(`update-complete`, (_, ...args) => console.log(`[Update]:`, ...args));

electron.ipcRenderer.on(`update-error`, (_, ...args) => console.log(`[Update]:`, ...args));

port = electron.ipcRenderer.sendSync("get-port");
console.log("User OS:", os.type(), os.platform(), "version:", os.release());

Expand Down
6 changes: 3 additions & 3 deletions src/renderer/src/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const guidedIcon = `
fill="white"
class="bi bi-compass-fill"
viewBox="0 0 16 16"
style="margin-right: 30px; margin-bottom: -5px"
style="margin-right: 30px;"
>
<path
d="M8 16.016a7.5 7.5 0 0 0 1.962-14.74A1 1 0 0 0 9 0H7a1 1 0 0 0-.962 1.276A7.5 7.5 0 0 0 8 16.016zm6.5-7.5a6.5 6.5 0 1 1-13 0 6.5 6.5 0 0 1 13 0z"
Expand All @@ -60,7 +60,7 @@ const documentationIcon = `
viewBox="0 0 448 512"
height="20px"
width="20px"
style="margin-right: 30px; margin-bottom: -5px"
style="margin-right: 30px;"
>
<path
d="M448 336v-288C448 21.49 426.5 0 400 0H96C42.98 0 0 42.98 0 96v320c0 53.02 42.98 96 96 96h320c17.67 0 32-14.33 32-31.1c0-11.72-6.607-21.52-16-27.1v-81.36C441.8 362.8 448 350.2 448 336zM143.1 128h192C344.8 128 352 135.2 352 144C352 152.8 344.8 160 336 160H143.1C135.2 160 128 152.8 128 144C128 135.2 135.2 128 143.1 128zM143.1 192h192C344.8 192 352 199.2 352 208C352 216.8 344.8 224 336 224H143.1C135.2 224 128 216.8 128 208C128 199.2 135.2 192 143.1 192zM384 448H96c-17.67 0-32-14.33-32-32c0-17.67 14.33-32 32-32h288V448z"
Expand All @@ -73,7 +73,7 @@ xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 512 512"
height="20px"
width="20px"
style="margin-right: 30px; margin-bottom: -5px"
style="margin-right: 30px;"
> <path
d="M511.1 63.1v287.1c0 35.25-28.75 63.1-64 63.1h-144l-124.9 93.68c-7.875 5.75-19.12 .0497-19.12-9.7v-83.98h-96c-35.25 0-64-28.75-64-63.1V63.1c0-35.25 28.75-63.1 64-63.1h384C483.2 0 511.1 28.75 511.1 63.1z"
></path></svg>
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/src/stories/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { Main, checkIfPageIsSkipped } from "./Main.js";
import { Sidebar } from "./sidebar.js";
import { NavigationSidebar } from "./NavigationSidebar.js";

import "../../assets/css/custom.css"; // Defined by Garrett late in GUIDE development to clearly separate global styles unrelated to SODA (May 20th, 2024)

// Global styles to apply with the dashboard
import "../../assets/css/variables.css";
import "../../assets/css/nativize.css";
Expand Down
43 changes: 40 additions & 3 deletions src/renderer/src/stories/ProgressBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,37 @@ import { LitElement, html, css, unsafeCSS } from 'lit';
export type ProgressProps = {
size?: string,

isBytes?: boolean,

format?: {
n: number,
total: number,
[key: string]: any,
},
}
}

export function humanReadableBytes(size: number | string) {

// Define the units
const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];

// Initialize the index to 0
let index = 0;

// Convert the size to a floating point number
size = parseFloat(size);

// Loop until the size is less than 1024 and increment the unit
while (size >= 1024 && index < units.length - 1) {
CodyCBakerPhD marked this conversation as resolved.
Show resolved Hide resolved
size /= 1024;
index += 1;
}

// Return the size formatted with 2 decimal places and the appropriate unit
return `${size.toFixed(2)} ${units[index]}`;
}


const animationDuration = 500 // ms

export class ProgressBar extends LitElement {
Expand Down Expand Up @@ -88,12 +112,14 @@ export class ProgressBar extends LitElement {

declare format: any
declare size: string
declare isBytes: boolean


constructor(props: ProgressProps = {}) {
super();
this.size = props.size ?? 'medium'
this.format = props.format ?? {}
this.isBytes = props.isBytes ?? false
if (!('n' in this.format)) this.format.n = 0
if (!('total' in this.format)) this.format.total = 0
}
Expand All @@ -103,6 +129,17 @@ export class ProgressBar extends LitElement {
const percent = this.format.total ? 100 * (this.format.n / this.format.total) : 0;
const remaining = this.format.rate && this.format.total ? (this.format.total - this.format.n) / this.format.rate : 0; // Seconds

const numerator = this.isBytes ? humanReadableBytes(this.format.n) : this.format.n
const denominator = this.isBytes ? humanReadableBytes(this.format.total) : this.format.total


const elapsed = this.format.elapsed

let subMessage = ''
if ('elapsed' in this.format && 'rate' in this.format) subMessage = `${elapsed?.toFixed(1)}s elapsed, ${remaining.toFixed(1)}s remaining`
else if ('elapsed' in this.format) subMessage = `${elapsed?.toFixed(1)}s elapsed`
else if ('rate' in this.format) subMessage = `${remaining.toFixed(1)}s remaining`

return html`
<div class="bar">
${this.format.prefix ? html`<div>
Expand All @@ -112,10 +149,10 @@ export class ProgressBar extends LitElement {
<div class="progress">
<div style="width: ${percent}%"></div>
</div>
<small>${this.format.n} / ${this.format.total} (${percent.toFixed(1)}%)</small>
<small>${numerator} / ${denominator} (${percent.toFixed(1)}%)</small>
</div>
<div>
${'elapsed' in this.format && 'rate' in this.format ? html`<small>${this.format.elapsed?.toFixed(1)}s elapsed, ${remaining.toFixed(1)}s remaining</small>` : ''}
${subMessage ? html`<small>${subMessage}</small>` : ''}
</div>
</div>
`;
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/stories/assets/dandi.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/renderer/src/stories/assets/download.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/renderer/src/stories/assets/exploration.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/renderer/src/stories/assets/info.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/renderer/src/stories/assets/inspect.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/renderer/src/stories/assets/neurosift-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading