fix(stage-tamagotchi): polyfill tauri platform

This commit is contained in:
Neko Ayaka
2025-06-28 01:24:43 +08:00
parent 9f30407fc7
commit 4c05962f26
7 changed files with 65 additions and 17 deletions
-1
View File
@@ -30,7 +30,6 @@
"@stdlib/string-base-kebabcase": "^0.2.2",
"@tauri-apps/api": "^2.6.0",
"@tauri-apps/plugin-global-shortcut": "^2.3.0",
"@tauri-apps/plugin-os": "~2.3.0",
"@tresjs/cientos": "^4.3.1",
"@tresjs/core": "^4.3.6",
"@vueuse/core": "^13.4.0",
+3 -2
View File
@@ -1,8 +1,8 @@
<script setup lang="ts">
import { useAppRuntime } from '@proj-airi/stage-ui/composables'
import { useMcpStore, useSettings } from '@proj-airi/stage-ui/stores'
import { listen } from '@tauri-apps/api/event'
import { Window } from '@tauri-apps/api/window'
import { platform } from '@tauri-apps/plugin-os'
import { useEventListener } from '@vueuse/core'
import { storeToRefs } from 'pinia'
import { computed, onMounted, watch } from 'vue'
@@ -15,6 +15,7 @@ const { language, themeColorsHue, themeColorsHueDynamic, allowVisibleOnAllWorksp
const i18n = useI18n()
const windowControlStore = useWindowControlStore()
const mcpStore = useMcpStore()
const { platform } = useAppRuntime()
useEventListener(window, 'resize', () => {
windowControlStore.size.width = window.innerWidth
@@ -41,7 +42,7 @@ listen('mcp_plugin_destroyed', () => {
mcpStore.connected = false
})
const isMac = computed(() => platform() === 'macos')
const isMac = computed(() => platform.value === 'macos')
if (isMac.value) {
watch(allowVisibleOnAllWorkspaces, async (value) => {
@@ -1,10 +1,12 @@
<script setup lang="ts">
import { platform } from '@tauri-apps/plugin-os'
import { useAppRuntime } from '@proj-airi/stage-ui/composables'
defineProps<{
title: string
icon: string
}>()
const { platform } = useAppRuntime()
</script>
<template>
@@ -13,7 +15,7 @@ defineProps<{
top="0"
data-tauri-drag-region fixed z-100 w-full select-none py-2 pr-4
:class="[
platform() === 'macos' ? 'pl-20' : 'pl-4',
platform === 'macos' ? 'pl-20' : 'pl-4',
]"
>
<div data-tauri-drag-region flex>
+3 -2
View File
@@ -1,10 +1,10 @@
<script setup lang="ts">
import { WidgetStage } from '@proj-airi/stage-ui/components'
import { useAppRuntime } from '@proj-airi/stage-ui/composables'
import { useMcpStore } from '@proj-airi/stage-ui/stores'
import { connectServer } from '@proj-airi/tauri-plugin-mcp'
import { invoke } from '@tauri-apps/api/core'
import { listen } from '@tauri-apps/api/event'
import { platform } from '@tauri-apps/plugin-os'
import { storeToRefs } from 'pinia'
import { computed, onMounted, onUnmounted, ref } from 'vue'
@@ -13,6 +13,7 @@ import { useWindowControlStore } from '../stores/window-controls'
import { WindowControlMode } from '../types/window-controls'
import { startClickThrough, stopClickThrough } from '../utils/windows'
const { platform } = useAppRuntime()
const windowStore = useWindowControlStore()
useWindowShortcuts()
const isCursorInside = ref(false)
@@ -78,7 +79,7 @@ function onTauriPositionCursorAndWindowFrameEvent(event: { payload: [Point, Wind
const [mouseLocation, windowFrame] = event.payload
isCursorInside.value = mouseLocation.x >= windowFrame.origin.x && mouseLocation.x <= windowFrame.origin.x + windowFrame.size.width && mouseLocation.y >= windowFrame.origin.y && mouseLocation.y <= windowFrame.origin.y + windowFrame.size.height
if (platform() === 'macos') {
if (platform.value === 'macos') {
live2dFocusAt.value = {
x: mouseLocation.x - windowFrame.origin.x,
y: windowFrame.size.height - mouseLocation.y + windowFrame.origin.y,
@@ -3,5 +3,6 @@ export * from './markdown'
export * from './micvad'
export * from './queue'
export * from './queues'
export * from './runtime'
export * from './vrm'
export * from './whisper'
@@ -0,0 +1,54 @@
import { computed } from 'vue'
export function useTauri() {
const isTauri = computed(() => {
if ('window' in globalThis && globalThis.window != null) {
if ('__TAURI__' in globalThis.window && globalThis.window.__TAURI__ != null) {
return true
}
}
return false
})
return {
isTauri,
isWeb: computed(() => !isTauri.value),
}
}
export function useAppRuntime() {
const { isTauri, isWeb } = useTauri()
const platform = computed(() => {
if (isTauri.value) {
if ('window' in globalThis && globalThis.window != null) {
// https://github.com/tauri-apps/plugins-workspace/blob/fe01894e7f32a2a615081f62f612b755ea79f1c8/plugins/os/guest-js/index.ts#L66-L81
if ('__TAURI_OS_PLUGIN_INTERNALS__' in globalThis.window && globalThis.window.__TAURI_OS_PLUGIN_INTERNALS__ != null) {
const internal = globalThis.window.__TAURI_OS_PLUGIN_INTERNALS__ as Record<string, unknown>
return internal.platform || 'unknown'
}
}
}
return 'web'
})
const runtime = computed(() => {
if (isTauri.value) {
return 'tauri'
}
else if (isWeb.value) {
return 'web'
}
else {
return 'unknown'
}
})
return {
isTauri,
isWeb,
platform,
runtime,
}
}
-10
View File
@@ -306,9 +306,6 @@ importers:
'@tauri-apps/plugin-global-shortcut':
specifier: ^2.3.0
version: 2.3.0
'@tauri-apps/plugin-os':
specifier: ~2.3.0
version: 2.3.0
'@tresjs/cientos':
specifier: ^4.3.1
version: 4.3.1(@tresjs/core@4.3.6(three@0.177.0)(typescript@5.8.3)(vue@3.5.17(typescript@5.8.3)))(@types/three@0.177.0)(react@18.3.1)(three@0.177.0)(typescript@5.8.3)(vue@3.5.17(typescript@5.8.3))
@@ -4793,9 +4790,6 @@ packages:
'@tauri-apps/plugin-global-shortcut@2.3.0':
resolution: {integrity: sha512-WbAz0ElhpP+0kzQZRScdCC7UQ7OPH8PAn//fsBNu7+ywihsnVSVOg1L9YhieAtLNtAlnmFI69Yl5AGaA3ge5IQ==}
'@tauri-apps/plugin-os@2.3.0':
resolution: {integrity: sha512-dm3bDsMuUngpIQdJ1jaMkMfyQpHyDcaTIKTFaAMHoKeUd+Is3UHO2uzhElr6ZZkfytIIyQtSVnCWdW2Kc58f3g==}
'@tokenizer/token@0.3.0':
resolution: {integrity: sha512-OvjF+z51L3ov0OyAU0duzsYuvO01PH7x4t6DJx+guahgTnBHkhJdG7soQeTSFLWN3efnHyibZ4Z8l2EuWwJN3A==}
@@ -15365,10 +15359,6 @@ snapshots:
dependencies:
'@tauri-apps/api': 2.6.0
'@tauri-apps/plugin-os@2.3.0':
dependencies:
'@tauri-apps/api': 2.6.0
'@tokenizer/token@0.3.0': {}
'@tresjs/cientos@4.3.1(@tresjs/core@4.3.6(three@0.177.0)(typescript@5.8.3)(vue@3.5.17(typescript@5.8.3)))(@types/three@0.177.0)(react@18.3.1)(three@0.177.0)(typescript@5.8.3)(vue@3.5.17(typescript@5.8.3))':