refactor: remove tauri module/integration (#3377)
Some checks are pending
ci / ci (push) Waiting to run
build & push docker container / docker (push) Waiting to run

This commit is contained in:
Daniel Roe 2025-09-08 12:00:45 +01:00 committed by GitHub
parent 6f7806fa95
commit 4e96759f8c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 16 additions and 262 deletions

View file

@ -1,68 +0,0 @@
import { rm } from 'node:fs/promises'
import { addImports, addImportsSources, addPlugin, createResolver, defineNuxtModule, useNuxt } from '@nuxt/kit'
import { resolveModulePath } from 'exsolve'
const mockProxy = resolveModulePath('mocked-exports/proxy', { from: import.meta.url })
export default defineNuxtModule({
meta: {
name: 'tauri',
},
setup() {
const nuxt = useNuxt()
const { resolve } = createResolver(import.meta.url)
if (!process.env.TAURI_PLATFORM)
return
if (nuxt.options.dev)
nuxt.options.ssr = false
nuxt.options.pwa.disable = true
nuxt.options.sourcemap.client = false
nuxt.options.alias = {
...nuxt.options.alias,
'unstorage/drivers/fs': mockProxy,
'unstorage/drivers/cloudflare-kv-http': mockProxy,
'#storage-config': resolve('./runtime/storage-config'),
'node:events': 'unenv/runtime/node/events/index',
'#build-info': resolve('./runtime/build-info'),
}
nuxt.hook('vite:extend', ({ config }) => {
config.build!.target = ['chrome100', 'safari15']
config.envPrefix = [...config.envPrefix || [], 'VITE_', 'TAURI_']
})
// prevent creation of server routes
nuxt.hook('nitro:config', (config) => {
config.srcDir = './_nonexistent'
config.scanDirs = []
})
addImportsSources({
from: 'h3',
imports: ['defineEventHandler', 'getQuery', 'getRouterParams', 'readBody', 'sendRedirect'] as Array<keyof typeof import('h3')>,
})
nuxt.options.imports.dirs = nuxt.options.imports.dirs || []
nuxt.options.imports.dirs.push(resolve('../../server/utils'))
addImports({ name: 'useStorage', from: resolve('./runtime/storage') })
addPlugin(resolve('./runtime/logging.client'))
addPlugin(resolve('./runtime/nitro.client'))
// cleanup files copied from the public folder that we don't need
nuxt.hook('close', async () => {
await rm('.output/public/_redirects')
await rm('.output/public/apple-touch-icon.png')
await rm('.output/public/elk-og.png')
await rm('.output/public/favicon.ico')
await rm('.output/public/pwa-192x192.png')
await rm('.output/public/pwa-512x512.png')
await rm('.output/public/robots.txt')
})
},
})

View file

@ -1 +0,0 @@
export const env = useAppConfig().env

View file

@ -1,18 +0,0 @@
import * as log from 'tauri-plugin-log-api'
// When running inside Tauri, catch all logs from 3rd party packages and direct them to the unified logging stream
export default defineNuxtPlugin(() => {
// eslint-disable-next-line no-global-assign
console = {
...console,
trace: log.trace,
debug: log.debug,
log: log.info,
warn: log.warn,
error: log.error,
}
window.addEventListener('unhandledrejection', err =>
log.error(err.reason))
window.addEventListener('error', err => log.error(err.error), true)
})

View file

@ -1,73 +0,0 @@
import type { FetchResponse } from 'ofetch'
import {
createApp,
createRouter,
defineLazyEventHandler,
toNodeListener,
} from 'h3'
import { fetchNodeRequestHandler } from 'node-mock-http'
import { createFetch } from 'ofetch'
const handlers = [
{
route: '/api/:server/oauth',
handler: defineLazyEventHandler(() => import('~~/server/api/[server]/oauth/[origin]').then(r => r.default || r)),
},
{
route: '/api/:server/login',
handler: defineLazyEventHandler(() => import('~~/server/api/[server]/login').then(r => r.default || r)),
},
{
route: '/api/list-servers',
handler: defineLazyEventHandler(() => import('~~/server/api/list-servers').then(r => r.default || r)),
},
]
// @ts-expect-error undeclared global window property
window.__NUXT__.config = {
// @ts-expect-error undeclared global window property
...window.__NUXT__.config,
storage: {},
}
export default defineNuxtPlugin(async () => {
const config = useRuntimeConfig()
const h3App = createApp({
debug: import.meta.dev,
// TODO: add global error handler
// onError: (err, event) => {
// console.log({ err, event })
// },
})
const router = createRouter()
for (const h of handlers)
router.use(h.route, h.handler)
// @ts-expect-error TODO: fix
h3App.use(config.app.baseURL, router)
const nodeHandler = toNodeListener(h3App)
const localFetch: typeof fetch = async (input, init) => {
if (!input.toString().startsWith('/')) {
return globalThis.fetch(input.toString(), init)
}
return await fetchNodeRequestHandler(nodeHandler, input.toString(), init)
}
// @ts-expect-error error types are subtly different here in a future nitro version
globalThis.$fetch = createFetch({
fetch: localFetch,
Headers,
defaults: { baseURL: config.app.baseURL },
})
const route = useRoute()
if (route.path.startsWith('/api')) {
const result = (await ($fetch.raw as any)(route.fullPath)) as FetchResponse<unknown>
if (result.headers.get('location'))
location.href = result.headers.get('location')!
}
})

View file

@ -1,2 +0,0 @@
export const driver = undefined
export const fsBase = ''

View file

@ -1,29 +0,0 @@
import { Store } from 'tauri-plugin-store-api'
import { createStorage } from 'unstorage'
const store = new Store('.servers.dat')
const storage = createStorage()
storage.mount('servers', {
getKeys() {
return store.keys()
},
async removeItem(key: string) {
await store.delete(key)
},
clear() {
return store.clear()
},
hasItem(key: string) {
return store.has(key)
},
setItem(key: string, value: any) {
return store.set(key, value)
},
getItem(key: string) {
return store.get(key)
},
})
export function useStorage() {
return storage
}