Skip to content
This repository has been archived by the owner on Aug 24, 2024. It is now read-only.

Commit

Permalink
feat(settings): add button for manual update
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitamet committed Aug 26, 2023
1 parent 6d73771 commit 327d7af
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 3 deletions.
24 changes: 23 additions & 1 deletion app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"github.com/Nitamet/geemo/backend"
"github.com/Nitamet/geemo/backend/lcu"
"github.com/sanbornm/go-selfupdate/selfupdate"
"github.com/wailsapp/wails/v2/pkg/runtime"
"golang.org/x/exp/slices"
"log"
Expand All @@ -18,6 +19,7 @@ type App struct {
ctx context.Context
LCU *lcu.Client
Settings backend.Settings
updater *selfupdate.Updater
}

// NewApp creates a new App application struct
Expand All @@ -30,10 +32,12 @@ func (a *App) startup(ctx context.Context) {
a.ctx = ctx
backend.BindContext(ctx)

a.updater = setupUpdater()

if a.Settings.AutoUpdate {
log.Println("Setup updater...")

setupUpdater()
autoUpdate(a.updater)
}
}

Expand Down Expand Up @@ -304,3 +308,21 @@ func (a *App) SetActiveSources(sources []string) {
a.Settings.ActiveSources = sources
a.Settings.Save()
}

func (a *App) IsUpdateAvailable() bool {
newVersion, err := a.updater.UpdateAvailable()

if err != nil {
log.Println("Error occurred while checking for updates: ", err)
return false
}

return newVersion != ""
}

func (a *App) Update() {
err := a.updater.Update()
if err != nil {
log.Println("Error occurred during update: ", err)
}
}
21 changes: 20 additions & 1 deletion frontend/src/components/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,19 @@

<q-dialog v-model="showSettings">
<q-card style="width: 500px" class="settings q-pa-md column">
<span>{{ $t('appVersion') }}: {{ version }}</span>
<div>
{{ $t('appVersion') }}: {{ version }}
<q-btn
class="button"
v-if="isUpdateAvailable"
:label="$t('update')"
size="md"
color="primary"
padding="sm"
push
@click="Update()"
/>
</div>
<div>
{{ $t('appSettings') }}:
<q-checkbox
Expand Down Expand Up @@ -63,11 +75,13 @@ import {
GetCurrentVersion,
GetLanguage,
GetShowNativeTitleBarSetting,
IsUpdateAvailable,
SetActiveSources,
SetAutoImportSetting,
SetAutoUpdateSetting,
SetLanguage,
SetShowNativeTitleBarSetting,
Update,
} from 'app/wailsjs/go/main/App';
import { storeToRefs } from 'pinia';
import { useSettingsStore } from 'stores/settings-store';
Expand Down Expand Up @@ -105,11 +119,14 @@ const localeOptions = [
watch(locale, async (value) => {
language.value = value;
await SetLanguage(value);
});
const allSources = ref<{ label: string; value: string }[]>([]);
const isUpdateAvailable = ref(false);
onBeforeMount(async () => {
autoImport.value = await GetAutoImportSetting();
showNativeTitleBar.value = await GetShowNativeTitleBarSetting();
Expand All @@ -126,6 +143,8 @@ onBeforeMount(async () => {
if (activeSources.value.length === 0) {
activeSources.value = sources.map((source) => source.slug);
}
isUpdateAvailable.value = await IsUpdateAvailable();
});
</script>

Expand Down
1 change: 1 addition & 0 deletions frontend/src/i18n/en-US/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ export default {
activeSources: 'Active Sources',
other: 'Other',
appSettings: 'App Settings',
update: 'Update',
};
1 change: 1 addition & 0 deletions frontend/src/i18n/ru-RU/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ export default {
activeSources: 'Активные источники',
other: 'Другое',
appSettings: 'Настройки приложения',
update: 'Обновить',
};
4 changes: 4 additions & 0 deletions frontend/wailsjs/go/main/App.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export function GetState():Promise<string>;

export function GetSummoner():Promise<lcu.Summoner>;

export function IsUpdateAvailable():Promise<boolean>;

export function Maximize():Promise<void>;

export function Minimize():Promise<void>;
Expand All @@ -49,3 +51,5 @@ export function SetAutoUpdateSetting(arg1:boolean):Promise<void>;
export function SetLanguage(arg1:string):Promise<void>;

export function SetShowNativeTitleBarSetting(arg1:boolean):Promise<void>;

export function Update():Promise<void>;
8 changes: 8 additions & 0 deletions frontend/wailsjs/go/main/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ export function GetSummoner() {
return window['go']['main']['App']['GetSummoner']();
}

export function IsUpdateAvailable() {
return window['go']['main']['App']['IsUpdateAvailable']();
}

export function Maximize() {
return window['go']['main']['App']['Maximize']();
}
Expand Down Expand Up @@ -97,3 +101,7 @@ export function SetLanguage(arg1) {
export function SetShowNativeTitleBarSetting(arg1) {
return window['go']['main']['App']['SetShowNativeTitleBarSetting'](arg1);
}

export function Update() {
return window['go']['main']['App']['Update']();
}
7 changes: 6 additions & 1 deletion updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
const version = "v0.2.1"
const updaterURL = "https://geemo.app/"

func setupUpdater() {
func setupUpdater() *selfupdate.Updater {
updater := &selfupdate.Updater{
CurrentVersion: version, // the current version of your app used to determine if an update is necessary
ApiURL: updaterURL,
Expand All @@ -22,10 +22,15 @@ func setupUpdater() {
},
}

return updater
}

func autoUpdate(updater *selfupdate.Updater) {
go func() {
err := updater.BackgroundRun()
if err != nil {
log.Println("Error occurred while updating: ", err)
}
}()

}

0 comments on commit 327d7af

Please sign in to comment.