fix(stage-tamagotchi,stage-shared,stage-ui): unify electron-renderer globals and fix env checks in providers (#668)

This commit is contained in:
Makito
2025-10-20 15:09:45 +08:00
committed by GitHub
parent 18c1bdb0ef
commit bcc262a50c
16 changed files with 86 additions and 54 deletions
@@ -74,13 +74,11 @@ export default defineConfig({
plugins: [
{
name: 'proj-airi:define-runtime-environment',
config(ctx) {
if (ctx.mode === 'production') {
return {
define: {
'import.meta.env.RUNTIME_ENVIRONMENT': '\'electron\'',
},
}
config() {
return {
define: {
'import.meta.env.RUNTIME_ENVIRONMENT': '\'electron\'',
},
}
},
},
+1
View File
@@ -127,6 +127,7 @@
"@iconify/utils": "^3.0.2",
"@intlify/unplugin-vue-i18n": "^11.0.1",
"@proj-airi/lobe-icons": "^1.0.13",
"@proj-airi/stage-shared": "workspace:^",
"@proj-airi/ui-transitions": "workspace:^",
"@proj-airi/unplugin-fetch": "^0.1.7",
"@proj-airi/unplugin-live2d-sdk": "^0.1.6",
-9
View File
@@ -1,9 +0,0 @@
import type { ElectronAPI } from '@electron-toolkit/preload'
declare global {
interface Window {
electron: ElectronAPI
platform: NodeJS.Platform
api: unknown
}
}
@@ -20,10 +20,7 @@ if (contextIsolated) {
}
}
else {
// @ts-expect-error (define in dts)
window.electron = electronAPI
// @ts-expect-error (define in dts)
window.platform = platform
// @ts-expect-error (define in dts)
window.api = api
}
@@ -1,8 +0,0 @@
declare global {
interface Window {
electron: import('@electron-toolkit/preload').ElectronAPI
platform: NodeJS.Platform
}
}
export {}
+3 -2
View File
@@ -1,7 +1,8 @@
{
"references": [
{ "path": "./tsconfig.web.json" },
{ "path": "./tsconfig.node.json" }
{ "path": "./tsconfig.preload.json" },
{ "path": "./tsconfig.node.json" },
{ "path": "./tsconfig.web.json" }
],
"files": []
}
-5
View File
@@ -27,11 +27,6 @@
"src/main/**/*.tsx",
"src/main/**/*.vue",
"src/preload/**/*.ts",
"src/preload/**/*.d.ts",
"src/preload/**/*.tsx",
"src/preload/**/*.vue",
"src/shared/**/*.ts",
"src/shared/**/*.d.ts",
"src/shared/**/*.tsx",
@@ -0,0 +1,32 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"composite": true,
"target": "ESNext",
"jsx": "preserve",
"lib": [
"DOM",
"ESNext"
],
"useDefineForClassFields": true,
"resolveJsonModule": true,
"types": [
"vitest",
"vite/client",
"electron-vite/node",
"@proj-airi/stage-shared/electron-renderer"
],
"allowJs": true,
"strict": true,
"skipLibCheck": true
},
"include": [
"vite.config.ts",
"electron.vite.config.ts",
"src/preload/**/*.ts",
"src/preload/**/*.d.ts",
"src/preload/**/*.tsx",
"src/preload/**/*.vue"
]
}
+1 -1
View File
@@ -26,7 +26,7 @@
"unplugin-vue-router/client",
"@types/audioworklet",
"unplugin-info/client",
"./src/renderer/electron-renderer.d.ts"
"@proj-airi/stage-shared/electron-renderer"
],
"allowJs": true,
"strict": true,
+5 -1
View File
@@ -15,9 +15,13 @@
"directory": "packages/stage-shared"
},
"exports": {
".": "./src/index.ts"
".": "./src/index.ts",
"./electron-renderer": "./src/electron-renderer.d.ts"
},
"scripts": {
"typecheck": "tsc --noEmit"
},
"devDependencies": {
"@electron-toolkit/preload": "^3.0.2"
}
}
+5
View File
@@ -0,0 +1,5 @@
import type { ElectronWindow } from './window'
declare global {
interface Window extends ElectronWindow {}
}
+1
View File
@@ -1,2 +1,3 @@
export * from './environment'
export * from './url'
export * from './window'
+13
View File
@@ -0,0 +1,13 @@
import type { ElectronAPI } from '@electron-toolkit/preload'
import { isStageTamagotchi } from './environment'
export interface ElectronWindow {
electron: ElectronAPI
platform: NodeJS.Platform
api: unknown
}
export function isElectronWindow(window: Window): window is (Window & ElectronWindow) {
return isStageTamagotchi() && typeof window === 'object' && window !== null && 'electron' in window
}
+2 -1
View File
@@ -38,6 +38,7 @@
],
"exclude": [
"dist",
"node_modules"
"node_modules",
"src/electron-renderer.d.ts"
]
}
+4 -15
View File
@@ -17,7 +17,7 @@ import type {
VoiceProviderWithExtraOptions,
} from 'unspeech'
import { isUrl } from '@proj-airi/stage-shared'
import { isStageTamagotchi, isUrl } from '@proj-airi/stage-shared'
import { computedAsync, useLocalStorage } from '@vueuse/core'
import {
createAzure,
@@ -214,19 +214,8 @@ export const useProvidersStore = defineStore('providers', () => {
return null
})
async function isTamagotchi() {
if ('window' in globalThis && globalThis.window != null) {
if (('__TAURI_INTERNALS__' in globalThis.window && globalThis.window.__TAURI_INTERNALS__ != null) || location.host === 'tauri.localhost') {
return true
}
}
return false
}
async function isBrowserAndMemoryEnough() {
const isInApp = await isTamagotchi()
if (isInApp)
if (isStageTamagotchi())
return false
const webGPUAvailable = await isWebGPUSupported()
@@ -313,7 +302,7 @@ export const useProvidersStore = defineStore('providers', () => {
description: 'https://github.com/huggingface/candle',
category: 'speech',
tasks: ['text-to-speech', 'tts'],
isAvailableBy: isTamagotchi,
isAvailableBy: isStageTamagotchi,
creator: createOpenAI,
validation: [],
validators: {
@@ -343,7 +332,7 @@ export const useProvidersStore = defineStore('providers', () => {
description: 'https://github.com/huggingface/candle',
category: 'transcription',
tasks: ['speech-to-text', 'automatic-speech-recognition', 'asr', 'stt'],
isAvailableBy: isTamagotchi,
isAvailableBy: isStageTamagotchi,
creator: createOpenAI,
validation: [],
validators: {
+14 -2
View File
@@ -558,6 +558,9 @@ importers:
'@proj-airi/lobe-icons':
specifier: ^1.0.13
version: 1.0.13
'@proj-airi/stage-shared':
specifier: workspace:^
version: link:../../packages/stage-shared
'@proj-airi/ui-transitions':
specifier: workspace:^
version: link:../../packages/ui-transitions
@@ -1311,7 +1314,11 @@ importers:
specifier: ^3.1.1
version: 3.1.1(typescript@5.9.3)
packages/stage-shared: {}
packages/stage-shared:
devDependencies:
'@electron-toolkit/preload':
specifier: ^3.0.2
version: 3.0.2(electron@38.2.2)
packages/stage-ui:
dependencies:
@@ -8029,6 +8036,9 @@ packages:
'@xsai/shared@0.4.0-beta.4':
resolution: {integrity: sha512-BqaX0q1j9m+YgcJuqIvNKXI+/dv5RXZUOjHbnVDfOMLUxaT3SIaA3M5I6PKjvMt6ZRzIHLLU/o5q2kQRAAVBrw==}
'@xsai/shared@0.4.0-beta.5':
resolution: {integrity: sha512-6oLyXkN8WoXoufNuIVFMrJyhJEEkWnGEi44v5SBd2fnBU7Wx4nT9ZRJT0A+Yfvx2pYWYqgHUQ9KVnG+DFT3VxQ==}
'@xsai/stream-text@0.3.5':
resolution: {integrity: sha512-XUyM3/jo9FulWoqmQU6vvHFOoRZzr3rcsTGm0MY8hUXg9HJl91N0voQGb6R5AMlo5XgoSbO3GMFzJ26AVxmRMg==}
@@ -23120,7 +23130,7 @@ snapshots:
'@xsai-ext/shared-providers@0.2.2':
dependencies:
'@xsai/shared': 0.4.0-beta.4
'@xsai/shared': 0.4.0-beta.5
'@xsai-ext/shared-providers@0.4.0-beta.4':
dependencies:
@@ -23212,6 +23222,8 @@ snapshots:
'@xsai/shared@0.4.0-beta.4': {}
'@xsai/shared@0.4.0-beta.5': {}
'@xsai/stream-text@0.3.5':
dependencies:
'@xsai/shared-chat': 0.3.5