refactor: dynamic import @tauri-apps/plugin-os (#239)
--------- Co-authored-by: Neko Ayaka <neko@ayaka.moe>
This commit is contained in:
co-authored by
Neko Ayaka
parent
6c64dca345
commit
6a0d99fe15
@@ -1,5 +1,4 @@
|
||||
<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'
|
||||
@@ -9,6 +8,7 @@ import { computed, onMounted, watch } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { RouterView } from 'vue-router'
|
||||
|
||||
import { useAppRuntime } from './composables/runtime'
|
||||
import { useWindowControlStore } from './stores/window-controls'
|
||||
|
||||
const { language, themeColorsHue, themeColorsHueDynamic, allowVisibleOnAllWorkspaces } = storeToRefs(useSettings())
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { useAppRuntime } from '@proj-airi/stage-ui/composables'
|
||||
import { useAppRuntime } from '../../composables/runtime'
|
||||
|
||||
defineProps<{
|
||||
title: string
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import { computedAsync } from '@vueuse/core'
|
||||
import { onMounted, ref } from 'vue'
|
||||
|
||||
async function getTauri() {
|
||||
try {
|
||||
const os = await import('@tauri-apps/plugin-os')
|
||||
return os
|
||||
}
|
||||
catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
async function getTauriOSPluginInternal() {
|
||||
const os = await import('@tauri-apps/plugin-os')
|
||||
return os
|
||||
}
|
||||
|
||||
export function useAppRuntime() {
|
||||
const isTauri = ref<boolean>(false)
|
||||
|
||||
const platform = computedAsync(async () => {
|
||||
if (!isTauri.value) {
|
||||
return 'web'
|
||||
}
|
||||
|
||||
return (await getTauriOSPluginInternal())?.platform?.() || 'web'
|
||||
})
|
||||
|
||||
onMounted(async () => {
|
||||
isTauri.value = (await getTauri()) != null
|
||||
})
|
||||
|
||||
return {
|
||||
platform,
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,5 @@ export * from './markdown'
|
||||
export * from './micvad'
|
||||
export * from './queue'
|
||||
export * from './queues'
|
||||
export * from './runtime'
|
||||
export * from './vrm'
|
||||
export * from './whisper'
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
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,
|
||||
}
|
||||
}
|
||||
Generated
+10
@@ -478,6 +478,9 @@ importers:
|
||||
'@tauri-apps/cli':
|
||||
specifier: ^2.6.0
|
||||
version: 2.6.0
|
||||
'@tauri-apps/plugin-os':
|
||||
specifier: ^2.3.0
|
||||
version: 2.3.0
|
||||
'@types/culori':
|
||||
specifier: ^4.0.0
|
||||
version: 4.0.0
|
||||
@@ -4790,6 +4793,9 @@ 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==}
|
||||
|
||||
@@ -15359,6 +15365,10 @@ 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))':
|
||||
|
||||
Reference in New Issue
Block a user