Skip to content

Commit 1acc84c

Browse files
committed
Add auto updater
1 parent a92f134 commit 1acc84c

File tree

12 files changed

+117
-105
lines changed

12 files changed

+117
-105
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"dependencies": {
1515
"@tauri-apps/api": "^1.2.0",
1616
"@vueuse/core": "^9.12.0",
17-
"compare-versions": "6.0.0-rc.1",
1817
"dayjs": "^1.11.7",
1918
"p-all": "^4.0.0",
2019
"pinia": "^2.0.29",

pnpm-lock.yaml

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ tauri-build = { version = "1.2", features = [] }
1616
[dependencies]
1717
serde_json = "1.0"
1818
serde = { version = "1.0", features = ["derive"] }
19-
tauri = { version = "1.2.4", features = ["dialog-confirm", "http-request", "icon-ico", "icon-png", "macos-private-api", "notification-all", "os-all", "process-exit", "shell-open", "system-tray", "updater"] }
19+
tauri = { version = "1.2.4", features = ["dialog-confirm", "http-request", "icon-ico", "icon-png", "macos-private-api", "notification-all", "os-all", "process-exit", "process-relaunch", "shell-open", "system-tray", "updater"] }
2020
window-vibrancy = "0.3.2"
2121
tiny_http = "0.12.0"
2222
ascii = "1.1.0"

src-tauri/tauri.conf.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"scope": ["https://github.com/*", "https://api.github.com/*", "http://localhost:23846/*", "http://localhost:15830/*", "http://localhost:12840/*"]
2626
},
2727
"process": {
28-
"exit": true
28+
"exit": true,
29+
"relaunch": true
2930
},
3031
"notification": {
3132
"all": true

src/api/releases.ts

Lines changed: 0 additions & 73 deletions
This file was deleted.

src/components/AppButton.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function handleClick(e: MouseEvent) {
7272
&,
7373
&-icon {
7474
vertical-align: middle;
75-
display: flex;
75+
display: inline-flex;
7676
align-items: center;
7777
}
7878

src/components/AppSidebar.vue

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { open } from '@tauri-apps/api/shell'
33
import { exit } from '@tauri-apps/api/process'
44
import { computed } from 'vue'
5-
import { Page, REPO_LINK, REPO_RELEASES_LINK } from '../constants'
5+
import { Page, REPO_LINK } from '../constants'
66
import { useStore } from '../stores/store'
77
import { AppStorage } from '../storage'
88
import { useKey } from '../composables/useKey'
@@ -12,6 +12,7 @@ import Popover from './Popover.vue'
1212
import MenuItems, { menuItem } from './MenuItems.vue'
1313
import Tooltip from './Tooltip.vue'
1414
import SlotRef from './SlotRef.vue'
15+
import PopoverContentInstallUpdate from './PopoverContentInstallUpdate.vue'
1516
1617
const store = useStore()
1718
@@ -76,10 +77,7 @@ useKey('r', () => {
7677
<div class="lower">
7778
<SlotRef v-if="store.newRelease != null">
7879
<template #default>
79-
<SidebarButton
80-
highlight
81-
@click="open(`${REPO_RELEASES_LINK}/tag/${store.newRelease!.tag_name}`)"
82-
>
80+
<SidebarButton highlight>
8381
<Icons.Download16 />
8482
</SidebarButton>
8583
</template>
@@ -90,6 +88,17 @@ useKey('r', () => {
9088
position="right"
9189
text="A new version is available"
9290
/>
91+
92+
<Popover
93+
:target="el"
94+
:wowerlayOptions="{ position: 'right-end' }"
95+
>
96+
<PopoverContentInstallUpdate
97+
:loading="store.installingUpate"
98+
:manifest="store.newRelease"
99+
@install="store.updateAndRestart()"
100+
/>
101+
</Popover>
93102
</template>
94103
</SlotRef>
95104

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<script lang="ts" setup>
2+
import type { UpdateManifest } from '@tauri-apps/api/updater'
3+
import AppButton from './AppButton.vue'
4+
import EmptyState from './EmptyState.vue'
5+
6+
interface Props {
7+
manifest: UpdateManifest
8+
loading?: boolean
9+
}
10+
11+
defineProps<Props>()
12+
13+
defineEmits<{ (e: 'install'): void }>()
14+
15+
const appVersion = __APP_VERSION__
16+
</script>
17+
18+
<template>
19+
<div class="install-update">
20+
<EmptyState :description="`Gitification ${manifest.version} is available!`">
21+
<template #icon>
22+
<img
23+
style="border-radius: 50%;"
24+
width="50"
25+
draggable="false"
26+
height="50"
27+
src="/src/assets/img/icon.png"
28+
>
29+
</template>
30+
31+
<template #footer>
32+
<p class="pharagraph">
33+
Current version is <b>{{ appVersion }}</b>
34+
</p>
35+
36+
<AppButton
37+
:loading="loading"
38+
@click="$emit('install')"
39+
>
40+
Install
41+
</AppButton>
42+
</template>
43+
</EmptyState>
44+
</div>
45+
</template>
46+
47+
<style lang="scss" scoped>
48+
.install-update {
49+
.pharagraph {
50+
color: var(--text-faded);
51+
font-size: 12px;
52+
margin-bottom: 15px;
53+
}
54+
}
55+
56+
:deep(.header) {
57+
font-size: 16px;
58+
}
59+
60+
.empty-state {
61+
padding: 15px;
62+
63+
:deep(.empty-state-footer) {
64+
margin-top: 5px
65+
}
66+
}
67+
</style>

src/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export const notificationApiMutex = new Mutex()
1818

1919
export const REPOSITORY_PATH = 'Gitification-App/gitification'
2020
export const REPO_LINK = `https://github.com/${REPOSITORY_PATH}` as const
21-
export const REPO_RELEASES_LINK = `https://github.com/${REPOSITORY_PATH}/releases` as const
2221
export const FETCH_INTERVAL_DURATION = 60000
2322
export const SERVER_PORTS = [23846, 15830, 12840]
2423

src/main.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ import { isEnabled as isAutostartEnabled } from 'tauri-plugin-autostart-api'
88
import dayjs from 'dayjs'
99
import relativeTime from 'dayjs/plugin/relativeTime'
1010
import { isPermissionGranted } from '@tauri-apps/api/notification'
11+
import { checkUpdate } from '@tauri-apps/api/updater'
1112
import App from './App.vue'
1213
import { AppStorage, cacheStorageFromDisk } from './storage'
1314
import { useStore } from './stores/store'
1415
import { Page } from './constants'
15-
import { getReleases } from './api/releases'
16-
import { getNewRelease } from './utils/getNewRelease'
1716
import { initDevtools } from './utils/initDevtools'
1817
import { useKey } from './composables/useKey'
1918

@@ -49,9 +48,14 @@ async function main() {
4948
store.fetchNotifications(true)
5049
}
5150

52-
{
53-
const releases = await getReleases(AppStorage.get('accessToken'))
54-
store.newRelease = getNewRelease(releases)
51+
try {
52+
const { shouldUpdate, manifest } = await checkUpdate()
53+
54+
if (shouldUpdate)
55+
store.newRelease = manifest!
56+
}
57+
catch (error) {
58+
console.error(error)
5559
}
5660

5761
app.mount('#app')

0 commit comments

Comments
 (0)