-
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.
Manual Startup Startup and daily
- Loading branch information
Showing
68 changed files
with
701 additions
and
5,917 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
owner: brimdata | ||
repo: zui | ||
provider: github | ||
updaterCacheDirName: zui-dev-updater |
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,19 @@ | ||
import React, {useEffect, useState} from "react" | ||
import {AppProvider} from "src/app/core/context" | ||
import initialize from "src/js/initializers/initialize" | ||
import {UpdateWindow} from "src/views/update-window" | ||
|
||
export default function Update() { | ||
const [app, setApp] = useState(null) | ||
|
||
useEffect(() => { | ||
initialize().then((app) => setApp(app)) | ||
}, []) | ||
|
||
if (!app) return null | ||
return ( | ||
<AppProvider store={app.store} api={app.api}> | ||
<UpdateWindow /> | ||
</AppProvider> | ||
) | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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 electronLog from "electron-log" | ||
|
||
export const info = electronLog.info | ||
export const debug = electronLog.debug | ||
export const error = electronLog.error |
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,22 @@ | ||
import {Selector} from "@reduxjs/toolkit" | ||
import {Store} from "src/js/state/types" | ||
|
||
export function onStateChange( | ||
store: Store, | ||
selector: Selector, | ||
onChange: (value: any) => void | ||
) { | ||
let current = undefined | ||
|
||
function listener() { | ||
const next = selector(store.getState()) | ||
if (next !== current) { | ||
current = next | ||
onChange(current) | ||
} | ||
} | ||
|
||
const unsubscribe = store.subscribe(listener) | ||
listener() | ||
return unsubscribe | ||
} |
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
Empty file.
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,45 @@ | ||
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" | ||
import {getMainObject} from "src/core/main" | ||
|
||
export class LinuxUpdater implements Updater { | ||
async check() { | ||
const latest = await this.latest() | ||
const current = app.getVersion() | ||
if (semver.lt(current, latest)) { | ||
return latest | ||
} else { | ||
return null | ||
} | ||
} | ||
|
||
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 = getMainObject().appMeta.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.repository + "/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,43 @@ | ||
import {autoUpdater} from "electron-updater" | ||
import {Updater} from "./types" | ||
import semver from "semver" | ||
import {app} from "electron" | ||
import {getMainObject} from "src/core/main" | ||
|
||
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.lt(current, latest)) { | ||
return latest | ||
} else { | ||
return null | ||
} | ||
} | ||
|
||
async install(onProgress) { | ||
const progress = (r) => { | ||
onProgress(r.percent / 100) | ||
} | ||
autoUpdater.on("error", (e) => { | ||
throw e | ||
}) | ||
autoUpdater.on("download-progress", progress) | ||
|
||
return new Promise((resolve, reject) => { | ||
autoUpdater.on("update-downloaded", resolve) | ||
autoUpdater.on("error", reject) | ||
autoUpdater.downloadUpdate() | ||
}).then(() => { | ||
// `autoUpdater.quitAndInstall()` will close all application windows first and only emit `before-quit` event on `app` after that. | ||
// We have some logic when closing windows that checks to see if we are quitting or not. | ||
// So we call onBeforeQuit manually here to tell the main object we are quitting | ||
getMainObject().onBeforeQuit() | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import * as operations from "./operations" | ||
|
||
export type UpdatesOperations = { | ||
"updates.open": typeof operations.open | ||
"updates.check": typeof operations.check | ||
"updates.install": typeof operations.install | ||
} |
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,50 @@ | ||
import {createOperation} from "src/core/operations" | ||
import {updater} from "./updater" | ||
import Updates from "src/js/state/Updates" | ||
import {errorToString} from "src/util/error-to-string" | ||
import {info} from "src/core/log" | ||
|
||
export const open = createOperation("updates.open", ({main}) => { | ||
check() | ||
main.windows.activate("update") | ||
}) | ||
|
||
export const check = createOperation( | ||
"updates.check", | ||
async ({main, dispatch}) => { | ||
try { | ||
info("Checking for Updates...") | ||
dispatch(Updates.setIsChecking(true)) | ||
const newVersion = await updater.check() | ||
if (newVersion) { | ||
info("New Version Found: " + newVersion) | ||
dispatch(Updates.setNextVersion(newVersion)) | ||
main.windows.activate("update") | ||
} | ||
} catch (e) { | ||
info("Error Checking for Update: " + errorToString(e)) | ||
dispatch(Updates.setError(errorToString(e))) | ||
} finally { | ||
dispatch(Updates.setIsChecking(false)) | ||
} | ||
} | ||
) | ||
|
||
export const install = createOperation( | ||
"updates.install", | ||
async ({dispatch, main}) => { | ||
info("Installing Update") | ||
const onProgress = (n: number) => dispatch(Updates.setDownloadProgress(n)) | ||
try { | ||
dispatch(Updates.setIsDownloading(true)) | ||
dispatch(Updates.setDownloadProgress(0)) | ||
await updater.install(onProgress) | ||
main.windows.byName("update").forEach((w) => w.close()) | ||
} catch (e) { | ||
info("Error Installing") | ||
dispatch(Updates.setError(errorToString(e))) | ||
} finally { | ||
dispatch(Updates.setIsDownloading(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import {UpdateMode} from "./types" | ||
|
||
export class Scheduler { | ||
static interval = 1000 * 60 * 60 * 24 // 1 day | ||
|
||
start(mode: UpdateMode, check: () => any, args: {delay?: number} = {}) { | ||
switch (mode) { | ||
case "default": | ||
this.delay(check, args.delay) | ||
this.schedule(check) | ||
break | ||
case "startup": | ||
this.delay(check, args.delay) | ||
} | ||
} | ||
|
||
private delayedId: any | ||
private delay(check, ms = 0) { | ||
this.delayedId = setTimeout(check, ms) | ||
} | ||
|
||
private scheduleId: any | ||
private schedule(check: () => any) { | ||
this.scheduleId = setTimeout(() => { | ||
check() | ||
this.schedule(check) | ||
}, Scheduler.interval) | ||
} | ||
|
||
stop() { | ||
clearTimeout(this.delayedId) | ||
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 = "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.