-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(updates): display update details and add update and restart butt…
…on (#1550)
- Loading branch information
1 parent
7210e62
commit 6982907
Showing
14 changed files
with
407 additions
and
48 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,11 @@ | ||
import superagent from 'superagent'; | ||
|
||
import { IUpdateInfo } from './UpdatesTypes'; | ||
|
||
export async function getUpdates(): Promise<IUpdateInfo> { | ||
return (await superagent.get(`/api/v1/updates`)).body; | ||
} | ||
|
||
export async function update(): Promise<void> { | ||
await superagent.post('api/v1/updates'); | ||
} |
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,65 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
import { | ||
UPDATES_GET_UPDATES_REQUEST, | ||
UPDATES_GET_UPDATES_ERROR, | ||
UPDATES_GET_UPDATES_SUCCESS, | ||
UPDATES_UPDATE_REQUEST, | ||
UPDATES_UPDATE_ERROR, | ||
UPDATES_UPDATE_SUCCESS | ||
} from './UpdatesTypes'; | ||
|
||
import * as API from './UpdatesAPI'; | ||
|
||
export function getUpdates(): any { | ||
return async (dispatch: any) => { | ||
try { | ||
dispatch({ | ||
payload: {}, | ||
type: UPDATES_GET_UPDATES_REQUEST | ||
}); | ||
|
||
try { | ||
const updateInfo = await API.getUpdates(); | ||
|
||
dispatch({ | ||
payload: updateInfo, | ||
type: UPDATES_GET_UPDATES_SUCCESS | ||
}); | ||
return updateInfo; | ||
} catch (error) { | ||
Sentry.captureException(error); | ||
|
||
dispatch({ | ||
payload: { error }, | ||
type: UPDATES_GET_UPDATES_ERROR | ||
}); | ||
} | ||
} catch (error) {} | ||
}; | ||
} | ||
|
||
export function update(): any { | ||
return async (dispatch: any) => { | ||
try { | ||
dispatch({ | ||
type: UPDATES_UPDATE_REQUEST | ||
}); | ||
|
||
try { | ||
await API.update(); | ||
|
||
dispatch({ | ||
type: UPDATES_UPDATE_SUCCESS | ||
}); | ||
} catch (error) { | ||
Sentry.captureException(error); | ||
|
||
dispatch({ | ||
payload: { error }, | ||
type: UPDATES_UPDATE_ERROR | ||
}); | ||
} | ||
} catch (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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
import { | ||
IUpdatesState, | ||
IUpdatesActionTypes, | ||
UPDATES_GET_UPDATES_SUCCESS | ||
} from './UpdatesTypes'; | ||
|
||
export const initialState: IUpdatesState = { | ||
updateAvailable: false, | ||
checkingForUpdates: false, | ||
updateInfo: { | ||
version: '', | ||
releaseName: '', | ||
releaseNotes: '', | ||
releaseDate: '' | ||
}, | ||
downloadProgress: { | ||
progress: 0, | ||
bytesPersecond: 0, | ||
percent: 0, | ||
total: 0, | ||
transferred: 0 | ||
} | ||
}; | ||
|
||
export default function updatesReducer( | ||
state: IUpdatesState = initialState, | ||
action: IUpdatesActionTypes | ||
): IUpdatesState { | ||
try { | ||
switch (action.type) { | ||
case UPDATES_GET_UPDATES_SUCCESS: | ||
return { | ||
...state, | ||
updateInfo: action.payload | ||
}; | ||
default: | ||
return state; | ||
} | ||
} catch (error) { | ||
Sentry.captureException(error); | ||
return state; | ||
} | ||
} |
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,68 @@ | ||
export interface IState { | ||
updates: IUpdatesState; | ||
} | ||
|
||
export interface IUpdateInfo { | ||
// derived from https://www.electron.build/auto-update#UpdateInfo | ||
version: string; | ||
releaseName: string; | ||
releaseNotes: string; | ||
releaseDate: string; | ||
} | ||
|
||
export interface IUpdatesState { | ||
updateAvailable: boolean; | ||
checkingForUpdates: boolean; | ||
updateInfo: IUpdateInfo; | ||
downloadProgress: { | ||
// dervied from https://www.electron.build/auto-update#event-download-progress | ||
progress: number; | ||
bytesPersecond: number; | ||
percent: number; | ||
total: number; | ||
transferred: number; | ||
}; | ||
} | ||
|
||
export const UPDATES_GET_UPDATES_REQUEST = 'UPDATES_GET_UPDATES_REQUEST'; | ||
export const UPDATES_GET_UPDATES_SUCCESS = 'UPDATES_GET_UPDATES_SUCCESS'; | ||
export const UPDATES_GET_UPDATES_ERROR = 'UPDATES_GET_UPDATES_ERROR'; | ||
|
||
export const UPDATES_UPDATE_REQUEST = 'UPDATES_UPDATE_REQUEST'; | ||
export const UPDATES_UPDATE_SUCCESS = 'UPADTES_UPDATE_SUCCESS'; | ||
export const UPDATES_UPDATE_ERROR = 'UPADTES_UPDATE_ERROR'; | ||
|
||
export interface IUpdateRequestAction { | ||
type: typeof UPDATES_UPDATE_REQUEST; | ||
} | ||
|
||
export interface IUpdateSuccessAction { | ||
type: typeof UPDATES_UPDATE_SUCCESS; | ||
} | ||
export interface IUpdateErrorAction { | ||
type: typeof UPDATES_UPDATE_ERROR; | ||
} | ||
|
||
export interface IGetUpdatesRequestAction { | ||
payload: {}; | ||
type: typeof UPDATES_GET_UPDATES_REQUEST; | ||
} | ||
|
||
export interface IGetUpdatesSuccessAction { | ||
payload: IUpdateInfo; | ||
type: typeof UPDATES_GET_UPDATES_SUCCESS; | ||
} | ||
export interface IGetUpdatesErrorAction { | ||
payload: { | ||
error: string; | ||
}; | ||
type: typeof UPDATES_GET_UPDATES_ERROR; | ||
} | ||
|
||
export type IUpdatesActionTypes = | ||
| IGetUpdatesRequestAction | ||
| IGetUpdatesSuccessAction | ||
| IGetUpdatesErrorAction | ||
| IUpdateErrorAction | ||
| IUpdateRequestAction | ||
| IUpdateSuccessAction; |
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
Oops, something went wrong.