diff --git a/src/main/paths.ts b/src/main/paths.ts index 054e2d0..8439b27 100644 --- a/src/main/paths.ts +++ b/src/main/paths.ts @@ -13,25 +13,37 @@ export const appResourcesPath = (): string => { return resourcesPath } +export const platform = (): NodeJS.Platform => { + let platform = os.platform() + if (process.env.KEYS_PLATFORM) { + platform = process.env.KEYS_PLATFORM as NodeJS.Platform + } + return platform +} + export const appSupportPath = (): string => { - const appName: string = getAppName() + const appName = getAppName() let supportDir - if (os.platform() == 'linux') { - if (process.env.XDG_DATA_HOME) { - supportDir = process.env.XDG_DATA_HOME - } else { - const homeDir = os.homedir() - supportDir = path.join(homeDir, '.local', 'share') - } - } else if (os.platform() == 'win32') { - if (process.env.LOCALAPPDATA) { - supportDir = process.env.LOCALAPPDATA - } else { - const homeDir = os.homedir() - supportDir = path.join(homeDir, 'AppData', 'Roaming') - } - } else { - supportDir = app.getPath('appData') + switch (platform()) { + case 'linux': + if (process.env.XDG_DATA_HOME) { + supportDir = process.env.XDG_DATA_HOME + } else { + const homeDir = os.homedir() + supportDir = path.join(homeDir, '.local', 'share') + } + break + case 'win32': + if (process.env.LOCALAPPDATA) { + supportDir = process.env.LOCALAPPDATA + } else { + const homeDir = os.homedir() + supportDir = path.join(homeDir, 'AppData', 'Roaming') + } + break + default: + supportDir = app.getPath('appData') + break } const p = path.join(supportDir, appName) @@ -60,7 +72,7 @@ export const appPath = (): string => { // Path to an executable export const binPath = (name: string): string => { const resourcesPath = appResourcesPath() - if (os.platform() == 'win32') { + if (platform() == 'win32') { name = name + '.exe' } return path.join(resourcesPath, 'bin', name) diff --git a/src/main/updater.ts b/src/main/updater.ts index 4891335..2931e58 100644 --- a/src/main/updater.ts +++ b/src/main/updater.ts @@ -4,7 +4,7 @@ import {app} from 'electron' import {appPath, appSupportPath} from './paths' import * as fs from 'fs' import * as path from 'path' -import * as os from 'os' +import {platform} from './paths' import {keysStop} from './service' import ElectronStore from 'electron-store' @@ -77,7 +77,7 @@ export const update = (version: string, apply: boolean): Promise = console.log('Apply:', applyPath) relaunch = true - if (os.platform() == 'win32') { + if (platform() == 'win32') { // Copy updater to support path, so we can update over the installed version. const updaterDest = path.join(appSupportPath(), 'updater.exe') if (fs.existsSync(updaterDest)) { diff --git a/src/renderer/env.ts b/src/renderer/env.ts new file mode 100644 index 0000000..6b0ba26 --- /dev/null +++ b/src/renderer/env.ts @@ -0,0 +1,9 @@ +import * as os from 'os' + +export const platform = (): NodeJS.Platform => { + let platform = os.platform() + if (process.env.KEYS_PLATFORM) { + platform = process.env.KEYS_PLATFORM as NodeJS.Platform + } + return platform +} diff --git a/src/renderer/views/root.tsx b/src/renderer/views/root.tsx index 735f939..385a038 100644 --- a/src/renderer/views/root.tsx +++ b/src/renderer/views/root.tsx @@ -164,6 +164,7 @@ export default (_: {}) => { + ) diff --git a/src/renderer/views/update/alert.tsx b/src/renderer/views/update/alert.tsx index f7c6c62..e5c8e8c 100644 --- a/src/renderer/views/update/alert.tsx +++ b/src/renderer/views/update/alert.tsx @@ -5,9 +5,9 @@ import {Box, Snackbar, Typography} from '@material-ui/core' import {Link} from '../../components' import Alert from '@material-ui/lab/Alert' - +import {platform} from '../../env' import {store} from '../../store' -import {ipcRenderer} from 'electron' +import {ipcRenderer, shell} from 'electron' export default (props: {}) => { const setUpdating = () => { @@ -34,6 +34,7 @@ class UpdateAlert extends React.Component { } componentDidMount() { + console.log('UpdateAlert mount') ipcRenderer.on('update-needed', (event, update) => { console.log('Update:', update) if (update.needUpdate) { @@ -56,6 +57,7 @@ class UpdateAlert extends React.Component { } componentWillUnmount() { + console.log('UpdateAlert unmount') ipcRenderer.removeAllListeners('update-needed') ipcRenderer.removeAllListeners('update-check-err') ipcRenderer.removeAllListeners('update-apply-err') @@ -77,35 +79,60 @@ class UpdateAlert extends React.Component { this.props.setUpdating() } + openReleases = () => { + shell.openExternal('https://github.com/keys-pub/app/releases') + } + render() { + let action + let actionLabel + + switch (platform()) { + case 'darwin': + action = this.apply + actionLabel = 'Download & Restart' + break + case 'win32': + action = this.apply + actionLabel = 'Download & Restart' + break + default: + action = this.openReleases + actionLabel = 'View Releases' + break + } + return ( ) } } -const UpdateAlertView = (props: {open: boolean; close: () => void; version: string; apply: () => void}) => { +type UpdateAlertProps = { + open: boolean + version: string + close: () => void + action: () => void + actionLabel: string +} + +const UpdateAlertView = (props: UpdateAlertProps) => { return ( {}} // Alert must be closed manually (not via clickaway or timeout) anchorOrigin={{vertical: 'bottom', horizontal: 'left'}} > - + There is a an update available ({props.version}). - Download & Restart + {props.actionLabel}