Skip to content

Commit ae647fe

Browse files
committed
Add update control and button
1 parent 0688af4 commit ae647fe

File tree

15 files changed

+159
-43
lines changed

15 files changed

+159
-43
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"dependencies": {
1414
"@tauri-apps/api": "^1.2.0",
1515
"@vueuse/core": "^9.12.0",
16+
"compare-versions": "6.0.0-rc.1",
1617
"dayjs": "^1.11.7",
1718
"pinia": "^2.0.29",
1819
"redaxios": "^0.5.1",

pnpm-lock.yaml

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

src/api/notifications.ts

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import redaxios from 'redaxios'
22
import type { NotificationReason, NotificationSubject } from '../constants'
33
import { createBaseGithubApiHeaders } from '../utils/api'
4+
import type { User } from './user'
45

56
export interface Thread {
67
id: string
@@ -24,7 +25,7 @@ export interface MinimalRepository {
2425
node_id: string
2526
name: string
2627
full_name: string
27-
owner: SimpleUser
28+
owner: User
2829
private: boolean
2930
html_url: string
3031
description: string | null
@@ -133,35 +134,6 @@ export interface MinimalRepository {
133134
}
134135
} | null
135136
}
136-
/**
137-
* A GitHub user.
138-
*/
139-
export interface SimpleUser {
140-
name?: string | null
141-
email?: string | null
142-
login: string
143-
id: number
144-
node_id: string
145-
avatar_url: string
146-
gravatar_id: string | null
147-
url: string
148-
html_url: string
149-
followers_url: string
150-
following_url: string
151-
gists_url: string
152-
starred_url: string
153-
subscriptions_url: string
154-
organizations_url: string
155-
repos_url: string
156-
events_url: string
157-
received_events_url: string
158-
type: string
159-
site_admin: boolean
160-
starred_at?: string
161-
}
162-
/**
163-
* Code Of Conduct
164-
*/
165137
export interface CodeOfConduct {
166138
key: string
167139
name: string

src/api/releases.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import redaxios from 'redaxios'
2+
import { REPOSITORY_PATH } from '../constants'
3+
import type { AppStorageContext, Option } from '../types'
4+
import { createBaseGithubApiHeaders } from '../utils/api'
5+
import type { User } from './user'
6+
7+
export interface Release {
8+
url: string
9+
html_url: string
10+
assets_url: string
11+
upload_url: string
12+
tarball_url: string | null
13+
zipball_url: string | null
14+
id: number
15+
node_id: string
16+
tag_name: string
17+
target_commitish: string
18+
name: Option<string>
19+
body?: Option<string>
20+
draft: boolean
21+
prerelease: boolean
22+
created_at: string
23+
published_at: Option<string>
24+
author: User
25+
assets: ReleaseAsset[]
26+
body_html?: string
27+
body_text?: string
28+
mentions_count?: number
29+
discussion_url?: string
30+
reactions?: ReactionRollup
31+
}
32+
33+
interface ReleaseAsset {
34+
url: string
35+
browser_download_url: string
36+
id: number
37+
node_id: string
38+
name: string
39+
label: Option<string>
40+
state: 'uploaded' | 'open'
41+
content_type: string
42+
size: number
43+
download_count: number
44+
created_at: string
45+
updated_at: string
46+
uploader: Option<User>
47+
}
48+
49+
export interface ReactionRollup {
50+
url: string
51+
total_count: number
52+
'+1': number
53+
'-1': number
54+
laugh: number
55+
confused: number
56+
heart: number
57+
hooray: number
58+
eyes: number
59+
rocket: number
60+
}
61+
62+
export async function getReleases(accessToken: AppStorageContext['accessToken']): Promise<Release[]> {
63+
try {
64+
const { data } = await redaxios<Release[]>({
65+
url: `https://api.github.com/repos/${REPOSITORY_PATH}/releases`,
66+
headers: createBaseGithubApiHeaders(accessToken),
67+
})
68+
return data
69+
}
70+
catch (error) {
71+
return []
72+
}
73+
}

src/api/user.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,7 @@ interface PrivateUser {
5656
business_plus?: boolean
5757
ldap_dn?: string
5858
}
59-
/**
60-
* Public User
61-
*/
62-
interface PublicUser {
59+
export interface PublicUser {
6360
login: string
6461
id: number
6562
node_id: string

src/components/AppSidebar.vue

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts" setup>
22
import { open } from '@tauri-apps/api/shell'
3-
import { Page, REPO_LINK } from '../constants'
3+
import { Page, REPO_LINK, REPO_RELEASES_LINK } from '../constants'
44
import { useStore } from '../stores/store'
55
import { Icons } from './Icons'
66
import SidebarButton from './SidebarButton.vue'
@@ -23,6 +23,15 @@ const store = useStore()
2323
</button>
2424
</div>
2525
<div class="lower">
26+
<SidebarButton
27+
v-if="store.newRelease != null"
28+
highlight
29+
title="An update is available"
30+
@click="open(`${REPO_RELEASES_LINK}/tag/${store.newRelease!.tag_name}`)"
31+
>
32+
<Icons.Download16 />
33+
</SidebarButton>
34+
2635
<SidebarButton
2736
:disabled="store.currentPage !== Page.Home"
2837
title="Reload notifications"

src/components/Icons.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import QuestionIcon from 'virtual:icons/octicon/question-24'
2424
import MailIcon from 'virtual:icons/octicon/mail-24'
2525
import SignOutIcon16 from 'virtual:icons/octicon/sign-out-16'
2626
import ChevronLeftIcon from 'virtual:icons/octicon/chevron-left'
27+
import DownloadIcon16 from 'virtual:icons/octicon/download-16'
2728

2829
export type IconComponent = typeof Icons[keyof typeof Icons]
2930

@@ -52,4 +53,5 @@ export const Icons = {
5253
Gear16: markRaw(GearIcon16),
5354
Sync16: markRaw(SyncIcon16),
5455
ChevronLeft: markRaw(ChevronLeftIcon),
56+
Download16: markRaw(DownloadIcon16),
5557
}

src/components/SidebarButton.vue

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
<script lang="ts" setup>
22
interface Props {
33
disabled?: boolean
4+
highlight?: boolean
45
}
56
6-
withDefaults(defineProps<Props>(), { disabled: false })
7+
withDefaults(defineProps<Props>(), { disabled: false, highlight: false })
78
</script>
89

910
<template>
1011
<button
1112
class="sidebar-button"
1213
:disabled="disabled || undefined"
13-
:class="{ disabled }"
14+
:class="{
15+
disabled,
16+
'sidebar-button-highlight': highlight,
17+
}"
1418
>
1519
<slot />
1620
</button>
@@ -29,6 +33,20 @@ withDefaults(defineProps<Props>(), { disabled: false })
2933
align-items: center;
3034
justify-content: center;
3135
@include focus-visible;
36+
position: relative;
37+
38+
&-highlight {
39+
&::before {
40+
position: absolute;
41+
width: 5px;
42+
height: 5px;
43+
border-radius: 50%;
44+
background-color: var(--white);
45+
right: 2px;
46+
top: 2px;
47+
content: '';
48+
}
49+
}
3250
3351
&.disabled {
3452
opacity: .3;

src/constants.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { Icons } from './components/Icons'
22

3+
export const REPOSITORY_PATH = 'Gitification-App/gitification'
34
export const SERVER_PORT = 23846
4-
export const REPO_LINK = 'https://github.com/Gitification-App/gitification'
5+
export const REPO_LINK = `https://github.com/${REPOSITORY_PATH}`
6+
export const REPO_RELEASES_LINK = `https://github.com/${REPOSITORY_PATH}/releases`
57
export const FETCH_INTERVAL_DURATION = 60000
68

79
export enum Page {

src/main.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { useStore } from './stores/store'
1212
import { initDevtools } from './utils/initDevtools'
1313
import { useKey } from './composables/useKey'
1414
import { Page } from './constants'
15+
import { getReleases } from './api/releases'
16+
import { getNewRelease } from './utils/getNewRelease'
1517

1618
(async () => {
1719
dayjs.extend(relativeTime)
@@ -35,6 +37,11 @@ import { Page } from './constants'
3537
store.fetchNotifications(true)
3638
}
3739

40+
{
41+
const releases = await getReleases(AppStorage.get('accessToken'))
42+
store.newRelease = getNewRelease(releases)
43+
}
44+
3845
app.mount('#app')
3946
})()
4047

0 commit comments

Comments
 (0)