-
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
Open
tdgao
wants to merge
6
commits into
main
Choose a base branch
from
truman/app-update-available-notif-for-linux
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
99c7f39
feat: show update available notif for modrinth app in linux
tdgao af39f8b
remove changelog button
tdgao 8de445c
update copy
tdgao 5aa80b4
pnpm prepr
tdgao c65e0d1
add restart app changelog
tdgao 282d26d
pnpm prepr
tdgao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
apps/app-frontend/src/components/ui/UpdateAvailableToast.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
||
| }, | ||
| 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> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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