Skip to content

Commit 6c74d96

Browse files
author
linyuan.yang
committed
整理目录结构
1 parent 261aac8 commit 6c74d96

75 files changed

Lines changed: 615 additions & 760 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎packages/app/package.json‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,19 @@
2525
"@tauri-apps/plugin-updater": "^2.10.1",
2626
"@while-coder/tauri-updater-vue": "git+https://github.com/while-coder/tauri-updater-kit.git#main&path:packages/vue",
2727
"vue": "catalog:",
28-
"@sbox/ui": "workspace:*"
28+
"@sbox/ui": "workspace:*",
29+
"@qingfeng346/ui-kit": "link:../../../ui-kit/ui-kit",
30+
"lucide-vue-next": "^1.0.0",
31+
"vue-router": "catalog:",
32+
"jsqr": "^1.4.0"
2933
},
3034
"devDependencies": {
3135
"@tauri-apps/cli": "^2.11.2",
3236
"@vitejs/plugin-vue": "catalog:",
3337
"typescript": "catalog:",
3438
"vite": "catalog:"
39+
},
40+
"ciDependencies": {
41+
"@qingfeng346/ui-kit": "https://github.com/while-coder/ui-kit.git#0.0.1&path:/ui-kit"
3542
}
3643
}

‎packages/app/src/App.vue‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,35 @@
11
<script setup lang="ts">
2+
import { onMounted, onUnmounted, type WatchStopHandle } from 'vue'
3+
import { useRouter } from 'vue-router'
24
import SboxApp from '@sbox/ui/app'
35
import { UpdaterDialog } from '@while-coder/tauri-updater-vue'
6+
import { APP_TOOLS } from './shell/registry'
7+
import { native } from './platform/native'
8+
import { loadSettings } from './shell/settings'
9+
import { setupCloseToTray, applyBossKey, watchBossKey, refreshAutostart } from './shell/system'
10+
import { ensureOverlay } from './tools/media/screenshot/screenshot'
11+
12+
const router = useRouter()
13+
let stopShortcutWatch: WatchStopHandle | undefined
14+
let unlistenClose: (() => void) | undefined
15+
let unlistenOpenSettings: (() => void) | undefined
16+
onMounted(async () => {
17+
loadSettings()
18+
if (native.windowLabel !== 'main') return
19+
void ensureOverlay().catch(error => console.error('初始化截图覆盖层失败:', error))
20+
void refreshAutostart()
21+
unlistenClose = await setupCloseToTray()
22+
await applyBossKey()
23+
stopShortcutWatch = watchBossKey()
24+
unlistenOpenSettings = await native.listen('open-settings', () => router.push('/settings'))
25+
})
26+
onUnmounted(() => {
27+
stopShortcutWatch?.()
28+
unlistenOpenSettings?.()
29+
unlistenClose?.()
30+
})
431
</script>
532

633
<template>
7-
<SboxApp><template #updater><UpdaterDialog /></template></SboxApp>
34+
<SboxApp :tools="APP_TOOLS"><template #updater><UpdaterDialog /></template></SboxApp>
835
</template>

‎packages/app/src/env.d.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@ declare module '@sbox/ui/app' {
1010
const component: DefineComponent
1111
export default component
1212
}
13+
14+
declare module '@sbox/ui/about' {
15+
import type { DefineComponent } from 'vue'
16+
const component: DefineComponent
17+
export default component
18+
}

‎packages/app/src/main.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ async function start(): Promise<void> {
77
const desktop = import.meta.env.MODE !== 'web' && '__TAURI_INTERNALS__' in window
88
if (desktop) {
99
const { NativeRust } = await import('./platform/native_rust')
10-
configureNative(new NativeRust())
10+
const { configureDesktopNative } = await import('./platform/native')
11+
configureDesktopNative(new NativeRust())
1112
const { setupLogger } = await import('./logger')
1213
setupLogger()
1314
} else configureNative(new NativeWeb())
@@ -23,6 +24,7 @@ async function start(): Promise<void> {
2324
desktop ? import('./App.vue') : import('@sbox/ui/app'),
2425
import('@sbox/ui/router'),
2526
])
26-
createApp(App).use(createSboxRouter()).mount('#app')
27+
const options = desktop ? await import('./shell/registry').then(({ APP_TOOLS, APP_ROUTES }) => ({ tools: APP_TOOLS, routes: APP_ROUTES })) : {}
28+
createApp(App).use(createSboxRouter(options)).mount('#app')
2729
}
2830
void start()
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import type { Ref } from 'vue'
2+
import { configureNative as configureSharedNative, type NativePlatform as SharedNative } from '@sbox/ui/native'
3+
import type { Capture } from './screenshot-types'
4+
export type Unlisten = () => void
5+
export interface FileDialogOptions {
6+
title?: string
7+
defaultPath?: string
8+
directory?: boolean
9+
multiple?: boolean
10+
filters?: { name: string; extensions: string[] }[]
11+
}
12+
export interface NativeUpdater {
13+
updateStatus: Ref<string>
14+
updateStatusText: Readonly<Ref<string>>
15+
checkForUpdate(options?: { silent?: boolean }): Promise<unknown>
16+
}
17+
export interface DesktopNative extends SharedNative {
18+
readonly kind: 'rust' | 'web'
19+
readonly windowLabel: string
20+
readonly updater: NativeUpdater
21+
readonly screenshot: Pick<typeof import('../tools/media/screenshot/screenshot'),
22+
'getLatestCapture' | 'getLatestCapturePixels' | 'cropSelectionPixels' | 'saveSelection' |
23+
'clearCapture' | 'ensureOverlay' | 'startScreenshot' | 'finishScreenshot'>
24+
getAppVersion(): Promise<string>
25+
openExternalUrl(url: string): Promise<void>
26+
pickPaths(options?: FileDialogOptions): Promise<string | string[] | null>
27+
selectSavePath(options?: FileDialogOptions): Promise<string | null>
28+
readClipboardText(): Promise<string>
29+
writeClipboardImage(bytes: Uint8Array, width: number, height: number): Promise<void>
30+
listen<T>(event: string, handler: (payload: T) => void): Promise<Unlisten>
31+
onPathDrop(handler: (paths: string[]) => void): Promise<Unlisten>
32+
setOverlayBounds(capture: Capture): Promise<void>
33+
showOverlay(): Promise<void>
34+
getAutostart(): Promise<boolean>
35+
setAutostart(enabled: boolean): Promise<void>
36+
toggleWindow(): Promise<void>
37+
onCloseRequested(shouldHide: () => boolean): Promise<Unlisten>
38+
registerShortcut(key: string, onPressed: () => void): Promise<void>
39+
isShortcutRegistered(key: string): Promise<boolean>
40+
clearShortcuts(): Promise<void>
41+
}
42+
43+
export let native: DesktopNative
44+
/** Configure before importing/mounting the shared app. */
45+
export function configureDesktopNative(platform: DesktopNative): void {
46+
native = platform
47+
configureSharedNative(platform)
48+
}

‎packages/app/src/platform/native_rust.ts‎

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { NativePlatform, NativeTools, FileDialogOptions, Unlisten } from '@sbox/ui/native'
2-
import type { Capture } from '@sbox/ui/screenshot'
1+
import type { DesktopNative, FileDialogOptions, Unlisten } from './native'
2+
import type { Capture } from '../tools/media/screenshot/screenshot'
33
import { invoke } from '@tauri-apps/api/core'
44
import { listen } from '@tauri-apps/api/event'
55
import { getCurrentWindow } from '@tauri-apps/api/window'
@@ -13,22 +13,11 @@ import { register, isRegistered, unregisterAll } from '@tauri-apps/plugin-global
1313
import { useTauriUpdater } from '@while-coder/tauri-updater-vue'
1414
import { rustFiles } from './files'
1515
import * as screenshot from './screenshot'
16-
import * as gdriveLogin from './tools/gdrive-login'
17-
import * as systemInfo from './tools/system-info'
18-
import * as xiaoaiLogin from './tools/xiaoai-login'
19-
import * as envVars from './tools/env-vars'
20-
import * as fileLocks from './tools/file-locks'
21-
import * as portCheck from './tools/port-check'
22-
import * as translator from './tools/translator'
23-
import * as batchRename from './tools/batch-rename'
24-
import * as keystore from './tools/keystore'
25-
import * as sshKeygen from './tools/ssh-keygen'
2616

2717
/** Tauri APIs and Rust command names remain inside the desktop host. */
28-
export class NativeRust implements NativePlatform {
18+
export class NativeRust implements DesktopNative {
2919
readonly kind = 'rust'
3020
get windowLabel() { return getCurrentWindow().label }
31-
readonly tools: NativeTools = { gdriveLogin, systemInfo, xiaoaiLogin, envVars, fileLocks, portCheck, translator, batchRename, keystore, sshKeygen }
3221
readonly updater = useTauriUpdater()
3322
readonly screenshot = {
3423
...screenshot,
File renamed without changes.

‎packages/app/src/platform/screenshot.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import type { UnlistenFn } from '@tauri-apps/api/event'
88
import { WebviewWindow } from '@tauri-apps/api/webviewWindow'
99
import { getCurrentWindow, primaryMonitor } from '@tauri-apps/api/window'
1010
import type { Window } from '@tauri-apps/api/window'
11-
import { settings } from '@sbox/ui/settings'
12-
import { EMPTY_ANNOTATION, CAPTURE_READY } from '@sbox/ui/screenshot'
13-
import type { Capture, CapturePixels, SelectionRect, Annotation } from '@sbox/ui/screenshot'
11+
import { settings } from '../shell/settings'
12+
import { EMPTY_ANNOTATION, CAPTURE_READY } from '../tools/media/screenshot/screenshot'
13+
import type { Capture, CapturePixels, SelectionRect, Annotation } from '../tools/media/screenshot/screenshot'
1414

1515
const OVERLAY_LABEL = 'screenshot-overlay'
1616
const HIDE_CAPTURE_SETTLE_MS = 280

‎packages/app/src/platform/tools/batch-rename.ts‎

Lines changed: 0 additions & 18 deletions
This file was deleted.

‎packages/app/src/platform/tools/env-vars.ts‎

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)