-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
234 additions
and
294 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {Selector} from "@reduxjs/toolkit" | ||
import {Store} from "src/js/state/types" | ||
|
||
export function onStateChange( | ||
store: Store, | ||
selector: Selector, | ||
onChange: (value: any) => void | ||
) { | ||
let first = true | ||
let prev = undefined | ||
store.subscribe(() => { | ||
const next = selector(store.getState()) | ||
if (prev !== next || first) onChange(next) | ||
prev = next | ||
first = false | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import {app, shell} from "electron" | ||
import fetch from "node-fetch" | ||
import semver from "semver" | ||
import env from "src/app/core/env" | ||
import links from "src/app/core/links" | ||
import pkg from "src/electron/pkg" | ||
import {Updater} from "./types" | ||
|
||
export class LinuxUpdater implements Updater { | ||
async check() { | ||
const latest = await this.latest() | ||
const current = app.getVersion() | ||
if (semver.gte(current, latest)) { | ||
return null | ||
} else { | ||
return latest | ||
} | ||
} | ||
|
||
async install() { | ||
shell.openExternal(this.downloadUrl()) | ||
} | ||
|
||
private async latest() { | ||
const resp = await fetch(this.latestUrl()) | ||
if (resp.status === 204) return app.getVersion() | ||
const data = await resp.json() | ||
return data.name | ||
} | ||
|
||
private latestUrl() { | ||
const repo = pkg.repo | ||
const platform = "darwin-x64" // If the mac version exists, the linux does too | ||
return `https://update.electronjs.org/${repo}/${platform}/${app.getVersion()}` | ||
} | ||
|
||
private downloadUrl() { | ||
if (env.isInsiders) { | ||
return pkg.repo + "/releases/latest" | ||
} else { | ||
return links.ZUI_DOWNLOAD | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import {autoUpdater} from "electron-updater" | ||
import {Updater} from "./types" | ||
import semver from "semver" | ||
import {app} from "electron" | ||
|
||
autoUpdater.autoDownload = false | ||
autoUpdater.autoInstallOnAppQuit = false | ||
|
||
export class MacWinUpdater implements Updater { | ||
async check() { | ||
const {updateInfo} = await autoUpdater.checkForUpdates() | ||
const latest = updateInfo.version | ||
const current = app.getVersion() | ||
if (semver.lte(current, latest)) { | ||
return latest | ||
} else { | ||
return null | ||
} | ||
} | ||
|
||
async install(onProgress) { | ||
const progress = (r) => { | ||
onProgress(r.percent / 100) | ||
} | ||
|
||
let resolve | ||
let reject | ||
|
||
return new Promise((res, rej) => { | ||
resolve = res | ||
reject = rej | ||
autoUpdater.on("update-downloaded", resolve) | ||
autoUpdater.on("download-progress", progress) | ||
autoUpdater.on("error", reject) | ||
autoUpdater.downloadUpdate() | ||
}) | ||
.finally(() => { | ||
autoUpdater.off("download-progress", onProgress) | ||
autoUpdater.off("update-downloaded", resolve) | ||
autoUpdater.off("error", reject) | ||
}) | ||
.then(() => { | ||
autoUpdater.quitAndInstall() | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,38 @@ | ||
import {createOperation} from "src/core/operations" | ||
import {appUpdater} from "./app-updater" | ||
import {updater} from "./updater" | ||
import Updates from "src/js/state/Updates" | ||
import {errorToString} from "src/util/error-to-string" | ||
|
||
export const open = createOperation("updates.open", ({main}) => { | ||
main.windows.create("update") | ||
}) | ||
// | ||
export const check = createOperation("updates.check", async () => { | ||
appUpdater.check() | ||
main.windows.activate("update") | ||
}) | ||
|
||
export const downloadAndInstall = createOperation( | ||
"updates.downloadAndInstall", | ||
async () => { | ||
export const check = createOperation( | ||
"updates.check", | ||
async ({main, dispatch}) => { | ||
dispatch(Updates.setIsChecking(true)) | ||
const newVersion = await updater.check() | ||
dispatch(Updates.setIsChecking(false)) | ||
|
||
if (newVersion) { | ||
dispatch(Updates.setNextVersion(newVersion)) | ||
main.windows.activate("update") | ||
} | ||
} | ||
) | ||
|
||
export const install = createOperation( | ||
"updates.install", | ||
async ({dispatch}) => { | ||
const onProgress = (n: number) => dispatch(Updates.setDownloadProgress(n)) | ||
try { | ||
await appUpdater.download() | ||
appUpdater.install() | ||
dispatch(Updates.setIsDownloading(true)) | ||
dispatch(Updates.setDownloadProgress(0)) | ||
await updater.install(onProgress) | ||
} catch (e) { | ||
console.log("Error", e) | ||
dispatch(Updates.setError(errorToString(e))) | ||
} finally { | ||
dispatch(Updates.setIsDownloading(false)) | ||
} | ||
} | ||
) | ||
|
||
// MANUAL FLOW | ||
// 1. user click check for updates | ||
// 2. app triggers update check | ||
// 3. app opens update window | ||
|
||
// 4. update window checks state | ||
// 5. renders progress bar if state.isChecking | ||
// 8. renders up to date if state.isUpToDate | ||
// 9. renders new version available if state.newVersionAvailable | ||
// 10. Button to Install | ||
// 11. Button to Cancel | ||
// 12. Note that you can change update settings in Settings | ||
|
||
// AUTO FLOW | ||
// app auto checks on startup, | ||
// app downloads update in the background | ||
// app waits until restart to install | ||
// app udates menu with "New Version Available..." | ||
// when the auu quits it will be updated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import {UpdateMode} from "./types" | ||
|
||
export class Scheduler { | ||
static interval = 1000 * 60 * 60 * 24 // 1 day | ||
|
||
start(mode: UpdateMode, check: () => any) { | ||
switch (mode) { | ||
case "default": | ||
check() | ||
this.schedule(check) | ||
break | ||
case "startup": | ||
check() | ||
} | ||
} | ||
|
||
private scheduleId: any | ||
private schedule(check: () => any) { | ||
this.scheduleId = setTimeout(() => { | ||
check() | ||
this.schedule(check) | ||
}, Scheduler.interval) | ||
} | ||
|
||
stop() { | ||
clearTimeout(this.scheduleId) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export type UpdateMode = "disabled" | "manual" | "startup" | "default" | ||
|
||
export interface Updater { | ||
check(): Promise<string | null> | ||
install(onProgress: (percent: number) => void): Promise<void> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import env from "src/app/core/env" | ||
import {LinuxUpdater} from "./linux-updater" | ||
import {MacWinUpdater} from "./mac-win-updater" | ||
|
||
export const updater = env.isLinux ? new LinuxUpdater() : new MacWinUpdater() |
Oops, something went wrong.