From e862f8deec171e46d2813a63572dcdfd96320129 Mon Sep 17 00:00:00 2001 From: nite Date: Thu, 5 Feb 2026 00:00:29 +0800 Subject: [PATCH] add: settings page --- .vscode/launch.json | 3 +- .vscode/tasks.json | 14 ++ README.md | 7 +- .../mesh-drop/internal/config/config.ts | 28 ++++ .../mesh-drop/internal/discovery/models.ts | 8 -- .../mesh-drop/internal/discovery/service.ts | 4 - .../mesh-drop/internal/transfer/service.ts | 8 ++ frontend/src/App.vue | 7 +- frontend/src/components/MainLayout.vue | 122 ++++++++++++++++-- frontend/src/components/PeerCard.vue | 16 +-- frontend/src/components/TransferItem.vue | 27 +--- internal/config/config.go | 90 +++++++++++-- internal/discovery/model.go | 3 - internal/discovery/service.go | 45 ++----- internal/transfer/client.go | 6 +- internal/transfer/history.go | 45 +++++++ internal/transfer/server.go | 19 ++- main.go | 14 +- 18 files changed, 345 insertions(+), 121 deletions(-) create mode 100644 .vscode/tasks.json create mode 100644 internal/transfer/history.go diff --git a/.vscode/launch.json b/.vscode/launch.json index d9da52a..eaccc38 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,7 +9,8 @@ "type": "go", "request": "launch", "mode": "auto", - "program": "${workspaceFolder}/main.go" + "program": "${workspaceFolder}/main.go", + "preLaunchTask": "build frontend" } ] } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..7c5e063 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,14 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "npm", + "script": "build:dev", + "path": "frontend", + "group": "build", + "problemMatcher": [], + "label": "build frontend", + "detail": "vite build" + } + ] +} \ No newline at end of file diff --git a/README.md b/README.md index 76d953f..1417504 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,9 @@ TODO - [x] 取消传输 - [x] 多文件发送 - [ ] 加密传输 -- [ ] 设置页面:默认保存路径 \ No newline at end of file +- [x] 设置页面 + - [x] 默认保存路径 + - [x] 设置主机名 + - [x] 保存历史 + - [x] 自动接收 + - [ ] 传输加密 diff --git a/frontend/bindings/mesh-drop/internal/config/config.ts b/frontend/bindings/mesh-drop/internal/config/config.ts index b7ed0e9..3c17c76 100644 --- a/frontend/bindings/mesh-drop/internal/config/config.ts +++ b/frontend/bindings/mesh-drop/internal/config/config.ts @@ -5,6 +5,22 @@ // @ts-ignore: Unused imports import { Call as $Call, CancellablePromise as $CancellablePromise, Create as $Create } from "@wailsio/runtime"; +export function GetAutoAccept(): $CancellablePromise { + return $Call.ByID(2605668438); +} + +export function GetHostName(): $CancellablePromise { + return $Call.ByID(972342140); +} + +export function GetID(): $CancellablePromise { + return $Call.ByID(4240411568); +} + +export function GetSaveHistory(): $CancellablePromise { + return $Call.ByID(2178923392); +} + export function GetSavePath(): $CancellablePromise { return $Call.ByID(4081533263); } @@ -16,6 +32,18 @@ export function Save(): $CancellablePromise { return $Call.ByID(3089450934); } +export function SetAutoAccept(autoAccept: boolean): $CancellablePromise { + return $Call.ByID(3371961138, autoAccept); +} + +export function SetHostName(hostName: string): $CancellablePromise { + return $Call.ByID(1580131496, hostName); +} + +export function SetSaveHistory(saveHistory: boolean): $CancellablePromise { + return $Call.ByID(3779587628, saveHistory); +} + /** * SetSavePath 修改配置 */ diff --git a/frontend/bindings/mesh-drop/internal/discovery/models.ts b/frontend/bindings/mesh-drop/internal/discovery/models.ts index 2fd7499..88e0c3d 100644 --- a/frontend/bindings/mesh-drop/internal/discovery/models.ts +++ b/frontend/bindings/mesh-drop/internal/discovery/models.ts @@ -46,11 +46,6 @@ export class Peer { * Port 是文件传输服务的监听端口。 */ "port": number; - - /** - * IsOnline 标记该端点当前是否活跃 (UI 渲染用)。 - */ - "is_online": boolean; "os": OS; /** Creates a new Peer instance. */ @@ -67,9 +62,6 @@ export class Peer { if (!("port" in $$source)) { this["port"] = 0; } - if (!("is_online" in $$source)) { - this["is_online"] = false; - } if (!("os" in $$source)) { this["os"] = OS.$zero; } diff --git a/frontend/bindings/mesh-drop/internal/discovery/service.ts b/frontend/bindings/mesh-drop/internal/discovery/service.ts index 24784db..7df7db1 100644 --- a/frontend/bindings/mesh-drop/internal/discovery/service.ts +++ b/frontend/bindings/mesh-drop/internal/discovery/service.ts @@ -13,10 +13,6 @@ export function GetID(): $CancellablePromise { return $Call.ByID(1539451205); } -export function GetName(): $CancellablePromise { - return $Call.ByID(1578367131); -} - export function GetPeerByIP(ip: string): $CancellablePromise<$models.Peer | null> { return $Call.ByID(1626825408, ip).then(($result: any) => { return $$createType1($result); diff --git a/frontend/bindings/mesh-drop/internal/transfer/service.ts b/frontend/bindings/mesh-drop/internal/transfer/service.ts index c5c4116..e8123bf 100644 --- a/frontend/bindings/mesh-drop/internal/transfer/service.ts +++ b/frontend/bindings/mesh-drop/internal/transfer/service.ts @@ -45,6 +45,10 @@ export function GetTransferList(): $CancellablePromise<($models.Transfer | null) }); } +export function LoadHistory(): $CancellablePromise { + return $Call.ByID(2987999795); +} + export function NotifyTransferListUpdate(): $CancellablePromise { return $Call.ByID(1220032142); } @@ -57,6 +61,10 @@ export function ResolvePendingRequest(id: string, accept: boolean, savePath: str return $Call.ByID(207902967, id, accept, savePath); } +export function SaveHistory(): $CancellablePromise { + return $Call.ByID(713135400); +} + export function SendFile(target: discovery$0.Peer | null, targetIP: string, filePath: string): $CancellablePromise { return $Call.ByID(2954589433, target, targetIP, filePath); } diff --git a/frontend/src/App.vue b/frontend/src/App.vue index f11457f..97724aa 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -8,9 +8,4 @@ import MainLayout from "./components/MainLayout.vue"; - + diff --git a/frontend/src/components/MainLayout.vue b/frontend/src/components/MainLayout.vue index 5771c03..25cdea6 100644 --- a/frontend/src/components/MainLayout.vue +++ b/frontend/src/components/MainLayout.vue @@ -7,11 +7,22 @@ import { Transfer } from "../../bindings/mesh-drop/internal/transfer"; import { GetPeers } from "../../bindings/mesh-drop/internal/discovery/service"; import { Events } from "@wailsio/runtime"; import { GetTransferList } from "../../bindings/mesh-drop/internal/transfer/service"; +import { + GetSavePath, + SetSavePath, + GetHostName, + SetHostName, + GetAutoAccept, + SetAutoAccept, + GetSaveHistory, + SetSaveHistory, +} from "../../bindings/mesh-drop/internal/config/config"; +import { Dialogs } from "@wailsio/runtime"; const peers = ref([]); const transferList = ref([]); const activeKey = ref("discover"); -const drawer = ref(true); // Control drawer visibility +const drawer = ref(true); const isMobile = ref(false); // 监听窗口大小变化更新 isMobile @@ -26,6 +37,12 @@ onMounted(async () => { if (isMobile.value) { drawer.value = false; } + + // 加载配置 + savePath.value = await GetSavePath(); + hostName.value = await GetHostName(); + autoAccept.value = await GetAutoAccept(); + saveHistory.value = await GetSaveHistory(); }); const checkMobile = () => { @@ -73,8 +90,34 @@ const menuItems = computed(() => [ icon: "mdi-inbox", badge: pendingCount.value > 0 ? pendingCount.value : null, }, + { + title: "Settings", + value: "settings", + icon: "mdi-cog", + }, ]); +// --- 设置 --- +const savePath = ref(""); + +const changeSavePath = async () => { + const opts: Dialogs.OpenFileDialogOptions = { + Title: "Select Save Path", + CanChooseDirectories: true, + CanChooseFiles: false, + AllowsMultipleSelection: false, + }; + const path = await Dialogs.OpenFile(opts); + if (path && typeof path === "string") { + await SetSavePath(path); + savePath.value = path; + } +}; + +const hostName = ref(""); +const autoAccept = ref(false); +const saveHistory = ref(false); + // --- 操作 --- const handleMenuClick = (key: string) => { @@ -87,17 +130,17 @@ const handleMenuClick = (key: string) => {