Skip to content

Commit

Permalink
refactor(selfupdate): deported updater to an extern library
Browse files Browse the repository at this point in the history
it also now give the choice to the user if update should be applied or not
  • Loading branch information
mJehanno committed Feb 27, 2024
1 parent 9f8d493 commit 9db93a8
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 217 deletions.
194 changes: 0 additions & 194 deletions backend/update/update.go

This file was deleted.

2 changes: 1 addition & 1 deletion backend/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type VersionManager struct {

func NewVersionManager() *VersionManager {
return &VersionManager{
current: "1.0.0",
current: "1.0.1",
}
}

Expand Down
10 changes: 10 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"preview": "vite preview"
},
"dependencies": {
"date-fns": "^3.3.1",
"pinia": "^2.1.7",
"primeflex": "^3.3.1",
"primevue": "^3.48.1",
Expand Down
51 changes: 45 additions & 6 deletions frontend/src/components/Home.vue
Original file line number Diff line number Diff line change
@@ -1,23 +1,62 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import Message from 'primevue/message';
import Button from 'primevue/button';
import {GetCurrentVersion} from '../../wailsjs/go/version/VersionManager'
import {CheckLatest, Update} from '../../wailsjs/go/selfupdater/Updater';
import { BrowserOpenURL} from '../../wailsjs/runtime/runtime';
const version = ref<string|null>(null)
const displayUpdateInfo = ref(false)
const successfulUpdate = ref<boolean | null>(null)
function performUpdate() {
Update().then( _ => {
successfulUpdate.value= true
}).catch(err => {
successfulUpdate.value = false
})
}
function openURL(e: Event) {
e.preventDefault();
BrowserOpenURL(e.target)
}
onMounted(() => {
CheckLatest().then(isLatest => {
displayUpdateInfo.value = !isLatest
})
GetCurrentVersion().then(v => {
version.value=v
})
})
</script>
<template>
<div class="flex flex-column m-8">
<router-link to="/game" class="m-2"><Button label="Start Game" rounded severity="success" @click="$emit('startGame')" /></router-link>
<router-link to="/scores" class="m-2"><Button label="See Scores" rounded severity="info" @click="$emit('startGame')" /></router-link>
</div>
<div class="flex flex-column align-items-center">
<div class="flex flex-column m-8">
<router-link to="/game" class="m-2"><Button label="Start Game" rounded severity="success" @click="$emit('startGame')" /></router-link>
<router-link to="/scores" class="m-2"><Button label="See Scores" rounded severity="info" @click="$emit('startGame')" /></router-link>
</div>

<div>
v{{ version }}
<div>
v{{ version }}
</div>
<div class="fixed bottom-0" v-if="displayUpdateInfo">
<Message severity="warn">
<div class=" p-1 flex flex-column justify-content-start align-content-start align-items-start">
<span>An update is available.</span>
<span>You can either let this app download it (experimental) by clicking the 'selfupdate' button</span>
<span>or you can download it yourself <a @click="openURL($event)" href="https://github.com/mJehanno/op-game/releases">here</a>.</span>
<span>Quick reminder that on windows, your antivirus might block the download.</span>
</div>
<div class="m-1">
<Button label="Self-Update" @click="performUpdate"/>
</div>
</Message>
</div>
</div>
</template>
8 changes: 8 additions & 0 deletions frontend/wailsjs/go/selfupdater/Updater.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT

export function CheckAndUpdate():Promise<void>;

export function CheckLatest():Promise<boolean>;

export function Update():Promise<void>;
15 changes: 15 additions & 0 deletions frontend/wailsjs/go/selfupdater/Updater.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// @ts-check
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT

export function CheckAndUpdate() {
return window['go']['selfupdater']['Updater']['CheckAndUpdate']();
}

export function CheckLatest() {
return window['go']['selfupdater']['Updater']['CheckLatest']();
}

export function Update() {
return window['go']['selfupdater']['Updater']['Update']();
}
8 changes: 5 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
module mult-game

go 1.21
go 1.21.1

require (
github.com/blang/semver v3.5.1+incompatible
github.com/doug-martin/goqu/v9 v9.19.0
github.com/google/go-github/v59 v59.0.1-0.20240217151021-73422173c633
github.com/google/go-github/v59 v59.0.1-0.20240217151021-73422173c633 // indirect
github.com/sirupsen/logrus v1.9.3
github.com/wailsapp/wails/v2 v2.7.1
go.uber.org/fx v1.20.1
modernc.org/sqlite v1.29.1
)

require github.com/mJehanno/ghr-self-updater v1.0.0

require (
github.com/bep/debounce v1.2.1 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
Expand Down Expand Up @@ -45,7 +47,7 @@ require (
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ github.com/leaanthony/u v1.1.1 h1:TUFjwDGlNX+WuwVEzDqQwC2lOv0P4uhTQw7CMFdiK7M=
github.com/leaanthony/u v1.1.1/go.mod h1:9+o6hejoRljvZ3BzdYlVL0JYCwtnAsVuN9pVTQcaRfI=
github.com/lib/pq v1.10.1 h1:6VXZrLU0jHBYyAqrSPa+MgPfnSvTPuMgK+k0o5kVFWo=
github.com/lib/pq v1.10.1/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/mJehanno/ghr-self-updater v1.0.0 h1:teUPLSr/D0XJDiILsb/H1svRnvkUU82npb7+PWQzHUQ=
github.com/mJehanno/ghr-self-updater v1.0.0/go.mod h1:ObkBVt+KX4ylifK4ysxtishKsP1esu/Su6xuXL6wnnk=
github.com/matryer/is v1.4.0 h1:sosSmIWwkYITGrxZ25ULNDeKiMNzFSr4V/eqBQP0PeE=
github.com/matryer/is v1.4.0/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
Expand Down
Loading

0 comments on commit 9db93a8

Please sign in to comment.