-
Notifications
You must be signed in to change notification settings - Fork 376
feat: show update available notif for modrinth app in linux #5181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
99c7f39
af39f8b
8de445c
5aa80b4
c65e0d1
282d26d
e55610b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| <script setup lang="ts"> | ||
| import { RefreshCwIcon, XIcon } from '@modrinth/assets' | ||
| import { ButtonStyled, commonMessages, defineMessages, useVIntl } from '@modrinth/ui' | ||
| import { getVersion } from '@tauri-apps/api/app' | ||
| import { onMounted, onUnmounted, ref } from 'vue' | ||
| import { restartApp } from '@/helpers/utils' | ||
| const { formatMessage } = useVIntl() | ||
| const dismissed = ref(false) | ||
| const availableUpdate = ref<{ version: string } | null>(null) | ||
| let checkInterval: ReturnType<typeof setInterval> | null = null | ||
| async function checkForUpdate() { | ||
| try { | ||
| const [response, currentVersion] = await Promise.all([ | ||
| fetch('https://launcher-files.modrinth.com/updates.json'), | ||
| getVersion(), | ||
| ]) | ||
| const updates = await response.json() | ||
| const latestVersion = updates?.version | ||
| if (latestVersion && latestVersion !== currentVersion) { | ||
| if (latestVersion !== availableUpdate.value?.version) { | ||
| availableUpdate.value = { version: latestVersion } | ||
| dismissed.value = false | ||
| } | ||
| } | ||
| } catch (e) { | ||
| console.error('Failed to check for updates:', e) | ||
| } | ||
| } | ||
| function dismiss() { | ||
| dismissed.value = true | ||
| } | ||
| onMounted(() => { | ||
| checkForUpdate() | ||
| checkInterval = setInterval(checkForUpdate, 5 * 60 * 1000) | ||
| }) | ||
| onUnmounted(() => { | ||
| if (checkInterval) { | ||
| clearInterval(checkInterval) | ||
| } | ||
| }) | ||
| const messages = defineMessages({ | ||
| title: { | ||
| id: 'app.update-toast.title', | ||
| defaultMessage: 'Update available', | ||
| }, | ||
| body: { | ||
| id: 'app.update-toast.body.linux', | ||
| defaultMessage: | ||
| 'Modrinth App v{version} is ready to install! Restart the app to apply the update once it has been installed by your system.', | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'd suggest the copy: "Modrinth App v{version} is available. Use your package manager to update for the latest features and fixes!" and I'd remove the Restart button because it doesn't really serve a purpose. They would likely need to close the app to update anyway I'd imagine
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @aecsocket any thoughts on this, I know you mentioned we shouldn't say package manager since we're supporting flatpak and it also updates in the background. |
||
| }, | ||
| download: { | ||
| id: 'app.update-toast.download-page', | ||
| defaultMessage: 'Download', | ||
| }, | ||
| changelog: { | ||
| id: 'app.update-toast.changelog', | ||
| defaultMessage: 'Changelog', | ||
| }, | ||
| restart: { | ||
| id: 'app.update-toast.restart', | ||
| defaultMessage: 'Restart app', | ||
| }, | ||
| }) | ||
| </script> | ||
| <template> | ||
| <div | ||
| v-if="availableUpdate && !dismissed" | ||
| class="grid grid-cols-[min-content] fixed card-shadow rounded-2xl top-[--top-bar-height] mt-6 right-6 p-4 z-10 bg-bg-raised border-divider border-solid border-[2px]" | ||
| > | ||
| <div class="flex min-w-[25rem] gap-4"> | ||
| <h2 class="whitespace-nowrap text-base text-contrast font-semibold m-0 grow"> | ||
| {{ formatMessage(messages.title) }} | ||
| </h2> | ||
| <ButtonStyled size="small" circular> | ||
| <button v-tooltip="formatMessage(commonMessages.closeButton)" @click="dismiss"> | ||
| <XIcon /> | ||
| </button> | ||
| </ButtonStyled> | ||
| </div> | ||
| <p class="text-sm mt-2 mb-0"> | ||
| {{ formatMessage(messages.body, { version: availableUpdate.version }) }} | ||
| </p> | ||
| <div class="flex gap-2 mt-4"> | ||
| <ButtonStyled color="brand"> | ||
| <button @click="restartApp()"> | ||
| <RefreshCwIcon /> {{ formatMessage(messages.restart) }} | ||
| </button> | ||
| </ButtonStyled> | ||
| <ButtonStyled> | ||
| <a href="https://modrinth.com/news/changelog?filter=app"> | ||
| {{ formatMessage(messages.changelog) }} <ExternalIcon /> | ||
| </a> | ||
| </ButtonStyled> | ||
| </div> | ||
| </div> | ||
| </template> | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's a specific env var for when updates are disabled and managed by the package manager, should check that instead of just for the OS