Skip to content

Commit

Permalink
add required update system
Browse files Browse the repository at this point in the history
  • Loading branch information
zenoxs committed Jul 22, 2022
1 parent b1ae781 commit 6a767e0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
3 changes: 2 additions & 1 deletion packages/i18n/en/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const en: BaseTranslation = {
updater: {
title: 'New version available {version: string}',
message: 'A new version ({version: string}) of Lindo is available. Do you want to update?',
download: 'Download on github',
messageRequired: 'A required update ({version: string}) of Lindo is available, you must download it on GitHub.',
download: 'Download on GitHub',
ignore: 'Ignore'
},
gameMenu: {
Expand Down
2 changes: 2 additions & 0 deletions packages/i18n/fr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const fr: Translation = {
updater: {
title: 'Nouvelle version disponible {version}',
message: 'Une nouvelle version ({version}) de Lindo est disponible. Voulez-vous télécharger la mis à jour?',
messageRequired:
'Une nouvelle version ({version}) obligatoire de Lindo est disponible, vous pouvez la télécharger sur GitHub.',
download: 'Télécharger sur github',
ignore: 'Ignorer'
},
Expand Down
13 changes: 11 additions & 2 deletions packages/i18n/i18n-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ type RootTranslation = {
*/
message: RequiredParams<'version'>
/**
* Download on github
* A required update ({version}) of Lindo is available, you must download it on GitHub.
* @param {string} version
*/
messageRequired: RequiredParams<'version'>
/**
* Download on GitHub
*/
download: string
/**
Expand Down Expand Up @@ -1084,7 +1089,11 @@ export type TranslationFunctions = {
*/
message: (arg: { version: string }) => LocalizedString
/**
* Download on github
* A required update ({version}) of Lindo is available, you must download it on GitHub.
*/
messageRequired: (arg: { version: string }) => LocalizedString
/**
* Download on GitHub
*/
download: () => LocalizedString
/**
Expand Down
15 changes: 11 additions & 4 deletions packages/main/updater/app-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,28 @@ export class AppUpdater {
repo: 'lindo'
})
.then((res) => {
console.log(res)
const latestVersion = res.data.tag_name.replaceAll('v', '')
const required = res.data.body?.includes('__update:required__') ?? false
logger.info({ latestVersion, currentVersion })
if (compareVersions(latestVersion, currentVersion) === 1) {
this._showUpdateDialog(latestVersion)
this._showUpdateDialog(latestVersion, required)
}
})
}

private _showUpdateDialog(newVersion: string) {
const buttons: Array<string> = [this._i18n.LL.main.updater.download(), this._i18n.LL.main.updater.ignore()]
private _showUpdateDialog(newVersion: string, required: boolean) {
const buttons: Array<string> = [this._i18n.LL.main.updater.download()]
if (!required) {
buttons.push(this._i18n.LL.main.updater.ignore())
}
return dialog
.showMessageBox({
type: 'info',
title: this._i18n.LL.main.updater.title({ version: newVersion }),
message: this._i18n.LL.main.updater.message({ version: newVersion }),
message: required
? this._i18n.LL.main.updater.messageRequired({ version: newVersion })
: this._i18n.LL.main.updater.message({ version: newVersion }),
buttons
})
.then((returnValue) => {
Expand Down

0 comments on commit 6a767e0

Please sign in to comment.