Skip to content

Commit 5a49bd6

Browse files
committed
fix: fix ua detect issue
1 parent dad84fd commit 5a49bd6

File tree

3 files changed

+7
-21
lines changed

3 files changed

+7
-21
lines changed

plugins/search/plugin-slimsearch/src/client/components/SearchBox.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import {
2-
isIOS,
3-
isMacOS,
4-
isiPad,
5-
useKeys,
6-
useLocale,
7-
} from '@vuepress/helper/client'
1+
import { isIOS, isMacOS, useKeys, useLocale } from '@vuepress/helper/client'
82
import type { VNode } from 'vue'
93
import { computed, defineComponent, h, onMounted, ref } from 'vue'
104

@@ -22,7 +16,7 @@ export default defineComponent({
2216
setup() {
2317
const locale = useLocale(locales)
2418
const [isActive, toggleActive] = useActiveState()
25-
const isMacOSDevice = ref(false)
19+
const isAppleDevice = ref(false)
2620

2721
useKeys(options.hotKeys, () => {
2822
if (!isActive.value) toggleActive()
@@ -32,7 +26,7 @@ export default defineComponent({
3226
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
3327
primaryHotKey
3428
? [
35-
...(isMacOSDevice.value
29+
...(isAppleDevice.value
3630
? ['⌃', '⇧', '⌥', '⌘']
3731
: ['Ctrl', 'Shift', 'Alt', 'Win']
3832
).filter(
@@ -47,10 +41,7 @@ export default defineComponent({
4741
)
4842

4943
onMounted(() => {
50-
const { userAgent } = navigator
51-
52-
isMacOSDevice.value =
53-
isMacOS(userAgent) || isIOS(userAgent) || isiPad(userAgent)
44+
isAppleDevice.value = isMacOS() || isIOS()
5445
})
5546

5647
return (): (VNode | null)[] => [
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isMobile } from '@vuepress/helper/client'
12
import { useSupported } from '@vueuse/core'
23
import type { ComputedRef } from 'vue'
34
import { computed } from 'vue'
@@ -7,9 +8,5 @@ export const useMobile = (): ComputedRef<boolean> => {
78
() => typeof window !== 'undefined' && 'userAgent' in window.navigator,
89
)
910

10-
return computed(
11-
() =>
12-
supportUserAgent.value &&
13-
/\b(?:Android|iPhone)/i.test(navigator.userAgent),
14-
)
11+
return computed(() => supportUserAgent.value && isMobile())
1512
}

tools/shiki-twoslash/src/client/enhanceTwoslash.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ import 'floating-vue/dist/style.css'
2323
* ```
2424
*/
2525
export const enhanceTwoslash = (app: App): void => {
26-
const isMobileDevice = __VUEPRESS_SSR__
27-
? false
28-
: isMobile(navigator.userAgent)
26+
const isMobileDevice = __VUEPRESS_SSR__ ? false : isMobile()
2927

3028
if (!__VUEPRESS_SSR__) {
3129
// Recompute poppers when clicking on a tab

0 commit comments

Comments
 (0)