-
Notifications
You must be signed in to change notification settings - Fork 50
feat(spx-gui): reminder for mobile devices and old browsers #2819
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
cn0809
wants to merge
5
commits into
goplus:dev
Choose a base branch
from
cn0809:issue-2650
base: dev
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
5 commits
Select commit
Hold shift + click to select a range
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,99 @@ | ||
| <template> | ||
| <UIDialog | ||
| type="warning" | ||
| size="small" | ||
| :title="$t({ en: 'Browser Version Unsupported', zh: '浏览器版本不支持' })" | ||
| :visible="visible" | ||
| :mask-closable="true" | ||
| @update:visible="visible = $event" | ||
| > | ||
| <div>{{ $t(content) }}</div> | ||
| <footer class="footer"> | ||
| <UIButton | ||
| v-radar="{ | ||
| name: 'Do not show again button', | ||
| desc: 'Click to close browser version reminder modal and suppress it show again.' | ||
| }" | ||
| color="boring" | ||
| @click="handleDoNotShowAgain" | ||
| > | ||
| {{ $t({ en: 'Do not show again', zh: '不再提示' }) }} | ||
| </UIButton> | ||
| <UIButton | ||
| v-radar="{ name: 'Confirm button', desc: 'Click to close browser version reminder modal' }" | ||
| color="primary" | ||
| @click="handleConfirm" | ||
| > | ||
| {{ $t({ en: 'Got it', zh: '我知道了' }) }} | ||
| </UIButton> | ||
| </footer> | ||
| </UIDialog> | ||
| </template> | ||
|
|
||
| <script setup lang="ts"> | ||
| import { onMounted, ref } from 'vue' | ||
| import { checkBrowserVersion } from '@/utils/ua' | ||
| import { type LocaleMessage } from '@/utils/i18n' | ||
| import UIDialog from '@/components/ui/dialog/UIDialog.vue' | ||
| import UIButton from '../ui/UIButton.vue' | ||
|
|
||
| const fallbackMessage: LocaleMessage = { | ||
| en: 'Your browser version may not support all features. Please update your browser for the best experience.', | ||
| zh: '您的浏览器版本可能无法支持全部功能,建议更新浏览器以获得最佳体验。' | ||
| } | ||
|
|
||
| const visible = ref(false) | ||
cn0809 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const content = ref(fallbackMessage) | ||
|
|
||
| const localStorageKey = 'spx-gui-browser-version-reminder-ignored' | ||
|
|
||
| function handleDoNotShowAgain() { | ||
| visible.value = false | ||
| try { | ||
| localStorage.setItem(localStorageKey, 'true') | ||
| } catch (e) { | ||
| console.warn('Failed to save preference:', e) | ||
| } | ||
| } | ||
|
|
||
| function handleConfirm() { | ||
| visible.value = false | ||
| } | ||
|
|
||
| onMounted(() => { | ||
| let isIgnored = false | ||
| try { | ||
| isIgnored = localStorage.getItem(localStorageKey) === 'true' | ||
| } catch (e) { | ||
| console.warn('Failed to read localStorage:', e) | ||
| } | ||
| if (isIgnored) return | ||
|
|
||
| const checkResult = checkBrowserVersion() | ||
| if (checkResult.ok) return | ||
|
|
||
| if (checkResult.browserName == null) { | ||
| const { recommendedBrowser, recommendedVersion } = checkResult | ||
| content.value = { | ||
| en: `Your browser may not support all features. For the best experience, please use ${recommendedBrowser} (version ${recommendedVersion} or later).`, | ||
| zh: `您的浏览器可能无法支持全部功能,建议使用 ${recommendedBrowser}(${recommendedVersion} 或更高版本)以获得最佳体验。` | ||
| } | ||
| } else { | ||
| const { recommendedVersion } = checkResult | ||
| content.value = { | ||
| en: `Your browser version may not support all features. Please update to version ${recommendedVersion} or later for the best experience.`, | ||
| zh: `您的浏览器版本可能无法支持全部功能,建议更新到 ${recommendedVersion} 或更高版本以获得最佳体验。` | ||
| } | ||
| } | ||
| visible.value = true | ||
| }) | ||
| </script> | ||
|
|
||
| <style scoped lang="scss"> | ||
| .footer { | ||
| display: flex; | ||
| justify-content: flex-end; | ||
| gap: 12px; | ||
| margin-top: 24px; | ||
| } | ||
| </style> | ||
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,81 @@ | ||
| <template> | ||
| <div class="mobile-reminder"> | ||
| <div class="guide-img"> | ||
| <img :src="imgDesktopRequired" alt="Desktop Required Image" /> | ||
| </div> | ||
| <div class="guide-text"> | ||
| <h1>{{ t({ en: 'Desktop Required', zh: '访问限制' }) }}</h1> | ||
| <p> | ||
| {{ | ||
| t({ | ||
| en: 'This application is not supported on mobile devices. Please access it from a desktop.', | ||
| zh: '该应用暂不支持移动端,请使用电脑访问' | ||
| }) | ||
| }} | ||
| </p> | ||
| </div> | ||
| <UIButton | ||
| v-if="isClipboardSupported" | ||
| v-radar="{ name: 'Copy Access URL', desc: 'Button to copy the access URL' }" | ||
| size="large" | ||
| icon="copy" | ||
| @click="handleCopy" | ||
| > | ||
| {{ t({ en: 'Copy Access URL', zh: '复制访问地址' }) }} | ||
| </UIButton> | ||
| </div> | ||
| </template> | ||
|
|
||
| <script setup lang="ts"> | ||
| import { useI18n } from '@/utils/i18n' | ||
| import imgDesktopRequired from './desktop-required.png' | ||
| import { UIButton } from '@/components/ui' | ||
| import { useMessageHandle } from '@/utils/exception' | ||
|
|
||
| const { t } = useI18n() | ||
|
|
||
| const isClipboardSupported = !!navigator.clipboard | ||
|
|
||
| const handleCopy = useMessageHandle( | ||
| () => navigator.clipboard.writeText(window.location.href), | ||
| { en: 'Failed to copy URL to clipboard', zh: '复制到剪贴板失败' }, | ||
| { en: 'Copied to clipboard', zh: '已复制到剪贴板' } | ||
| ).fn | ||
| </script> | ||
|
|
||
| <style lang="scss" scoped> | ||
| .mobile-reminder { | ||
| min-height: 100vh; | ||
| display: flex; | ||
| flex-direction: column; | ||
| align-items: center; | ||
| justify-content: center; | ||
| padding: 40px 60px; | ||
|
|
||
| .guide-img { | ||
| margin-bottom: 48px; | ||
| img { | ||
| width: 240px; | ||
| height: auto; | ||
| } | ||
| } | ||
|
|
||
| .guide-text { | ||
| margin-bottom: 40px; | ||
| text-align: center; | ||
|
|
||
| h1 { | ||
| font-size: 20px; | ||
| font-weight: 600; | ||
| color: var(--ui-color-grey-1000); | ||
| margin-bottom: 12px; | ||
| } | ||
|
|
||
| p { | ||
| font-size: 14px; | ||
| line-height: 22px; | ||
| color: var(--ui-color-grey-900); | ||
| } | ||
| } | ||
| } | ||
| </style> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,48 @@ | ||
| import { describe, it, expect } from 'vitest' | ||
| import { compareVersions } from './ua' | ||
|
|
||
| describe('compareVersions', () => { | ||
| it('should compare major versions correctly', () => { | ||
| expect(compareVersions('2.0', '1.0')).toBeGreaterThan(0) | ||
| expect(compareVersions('1.0', '2.0')).toBeLessThan(0) | ||
| expect(compareVersions('111', '110')).toBeGreaterThan(0) | ||
| expect(compareVersions('110', '111')).toBeLessThan(0) | ||
| }) | ||
|
|
||
| it('should compare minor versions correctly', () => { | ||
| expect(compareVersions('1.10', '1.4')).toBeGreaterThan(0) | ||
| expect(compareVersions('1.4', '1.10')).toBeLessThan(0) | ||
| expect(compareVersions('16.10', '16.4')).toBeGreaterThan(0) | ||
| expect(compareVersions('16.4', '16.10')).toBeLessThan(0) | ||
| }) | ||
|
|
||
| it('should return 0 for equal versions', () => { | ||
| expect(compareVersions('1.0', '1.0')).toBe(0) | ||
| expect(compareVersions('1.10', '1.10')).toBe(0) | ||
| expect(compareVersions('111', '111')).toBe(0) | ||
| expect(compareVersions('16.4', '16.4')).toBe(0) | ||
| }) | ||
|
|
||
| it('should handle versions without minor part', () => { | ||
| expect(compareVersions('111', '111.0')).toBe(0) | ||
| expect(compareVersions('111.0', '111')).toBe(0) | ||
| expect(compareVersions('112', '111')).toBeGreaterThan(0) | ||
| expect(compareVersions('111', '112')).toBeLessThan(0) | ||
| }) | ||
|
|
||
| it('should handle real-world browser versions', () => { | ||
| expect(compareVersions('111.0', '111')).toBe(0) | ||
| expect(compareVersions('111.0.5563.146', '111')).toBe(0) | ||
| expect(compareVersions('113.0', '113')).toBe(0) | ||
| expect(compareVersions('16.4', '16.4')).toBe(0) | ||
| expect(compareVersions('120.0', '111')).toBeGreaterThan(0) | ||
| expect(compareVersions('110.0', '111')).toBeLessThan(0) | ||
| }) | ||
|
|
||
| it('should handle edge cases', () => { | ||
| expect(compareVersions('0', '0')).toBe(0) | ||
| expect(compareVersions('0.0', '0.0')).toBe(0) | ||
| expect(compareVersions('1', '0')).toBeGreaterThan(0) | ||
| expect(compareVersions('0', '1')).toBeLessThan(0) | ||
| }) | ||
| }) |
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.
Uh oh!
There was an error while loading. Please reload this page.