feat: 增加设置页和托盘,登录后关闭窗口留在托盘
This commit is contained in:
+3
-1
@@ -4,7 +4,9 @@
|
||||
|
||||
## 打开方式
|
||||
|
||||
先进入登录页。登录成功后才出现功能导航。下载分组里有「栅格下载」和「下载管理」。
|
||||
先进入登录页。登录成功后才出现功能导航。数据下载里有「栅格下载」,旁边是「下载管理」。侧栏底部可以打开设置。
|
||||
|
||||
登录后默认显示托盘图标。关闭窗口会留在托盘,用托盘菜单里的退出才结束程序。未登录时关闭窗口会退出。设置里可以关掉托盘图标,或改回关闭窗口即退出。设置里也可以移除本机保存的账号。
|
||||
|
||||
退出只结束当前会话,本机已保存的登录会保留,下次可以直接进入。
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import logging
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import threading
|
||||
import time
|
||||
from collections.abc import AsyncIterator
|
||||
from concurrent.futures import Future
|
||||
@@ -340,25 +341,65 @@ def _new_job_id() -> str:
|
||||
return candidate
|
||||
|
||||
|
||||
def load_task_limit() -> int:
|
||||
_SETTINGS_LOCK = threading.Lock()
|
||||
|
||||
|
||||
def _read_settings() -> dict:
|
||||
try:
|
||||
data = json.loads(SETTINGS_PATH.read_text(encoding="utf-8"))
|
||||
return min(8, max(1, int(data.get("maxConcurrentJobs") or 2)))
|
||||
except (OSError, json.JSONDecodeError, TypeError, ValueError):
|
||||
return 2
|
||||
return {}
|
||||
return data if isinstance(data, dict) else {}
|
||||
|
||||
|
||||
def _write_settings(data: dict) -> None:
|
||||
SETTINGS_PATH.parent.mkdir(parents=True, exist_ok=True)
|
||||
payload = json.dumps(data, ensure_ascii=False, indent=2).encode("utf-8")
|
||||
write_atomic(SETTINGS_PATH, payload)
|
||||
|
||||
|
||||
def load_task_limit() -> int:
|
||||
with _SETTINGS_LOCK:
|
||||
try:
|
||||
return min(8, max(1, int(_read_settings().get("maxConcurrentJobs") or 2)))
|
||||
except (TypeError, ValueError):
|
||||
return 2
|
||||
|
||||
|
||||
def store_task_limit(value: int) -> int:
|
||||
limit = min(8, max(1, int(value)))
|
||||
data = json.dumps({"maxConcurrentJobs": limit}, ensure_ascii=False, indent=2).encode("utf-8")
|
||||
try:
|
||||
SETTINGS_PATH.parent.mkdir(parents=True, exist_ok=True)
|
||||
write_atomic(SETTINGS_PATH, data)
|
||||
except OSError as exc:
|
||||
raise NqiError(explain_os_error(exc) or "设置保存失败,请稍后重试") from exc
|
||||
with _SETTINGS_LOCK:
|
||||
data = _read_settings()
|
||||
data["maxConcurrentJobs"] = limit
|
||||
try:
|
||||
_write_settings(data)
|
||||
except OSError as exc:
|
||||
raise NqiError(explain_os_error(exc) or "设置保存失败,请稍后重试") from exc
|
||||
return limit
|
||||
|
||||
|
||||
def app_settings() -> dict:
|
||||
"""未写过的项用默认值:显示托盘,关闭窗口时留在托盘。"""
|
||||
with _SETTINGS_LOCK:
|
||||
data = _read_settings()
|
||||
return {
|
||||
"showTray": data.get("showTray") is not False,
|
||||
"closeToTray": data.get("closeToTray") is not False,
|
||||
}
|
||||
|
||||
|
||||
def store_app_settings(show_tray: bool, close_to_tray: bool) -> dict:
|
||||
with _SETTINGS_LOCK:
|
||||
data = _read_settings()
|
||||
data["showTray"] = bool(show_tray)
|
||||
data["closeToTray"] = bool(close_to_tray)
|
||||
try:
|
||||
_write_settings(data)
|
||||
except OSError as exc:
|
||||
raise NqiError(explain_os_error(exc) or "设置保存失败,请稍后重试") from exc
|
||||
return app_settings()
|
||||
|
||||
|
||||
class JobManager:
|
||||
def __init__(self) -> None:
|
||||
self.jobs: dict[str, DownloadJob] = {}
|
||||
|
||||
@@ -14,7 +14,7 @@ from fastapi import APIRouter, Body, File, Form, HTTPException, UploadFile
|
||||
|
||||
from app.features.download.fields import IDENTITY, NETWORKS, cell_columns, columns_for, grid_spec, meta_groups
|
||||
from app.features.download.ids import parse_upload
|
||||
from app.features.download.jobs import _write_ids, ensure_output_dir, run_download
|
||||
from app.features.download.jobs import _write_ids, app_settings, ensure_output_dir, run_download, store_app_settings
|
||||
from app.features.download.journal import explain_os_error
|
||||
from app.platform.client import NqiError
|
||||
from app.platform.constants import CITIES
|
||||
@@ -62,6 +62,21 @@ def fill_slots() -> None:
|
||||
_spawn(waiting[0])
|
||||
|
||||
|
||||
@router.get("/settings/app")
|
||||
async def read_app_settings() -> dict:
|
||||
return app_settings()
|
||||
|
||||
|
||||
@router.put("/settings/app")
|
||||
async def write_app_settings(body: Any = Body(default=None)) -> dict:
|
||||
if not isinstance(body, dict):
|
||||
raise _bad("参数格式不正确")
|
||||
try:
|
||||
return store_app_settings(bool(body.get("showTray")), bool(body.get("closeToTray")))
|
||||
except NqiError as exc:
|
||||
raise _bad(str(exc)) from exc
|
||||
|
||||
|
||||
@router.get("/meta")
|
||||
async def meta() -> dict:
|
||||
return {
|
||||
|
||||
@@ -10,7 +10,7 @@ import uuid
|
||||
from fastapi import APIRouter, HTTPException
|
||||
|
||||
from app.platform.client import NqiError, needs_captcha
|
||||
from app.platform.sessions import available_accounts, remember_account, resume
|
||||
from app.platform.sessions import available_accounts, clear_accounts, forget_account, list_local_accounts, remember_account, resume
|
||||
from app.shared.state import state
|
||||
|
||||
logger = logging.getLogger("nqi.auth")
|
||||
@@ -166,6 +166,29 @@ async def saved() -> dict:
|
||||
return {"accounts": await available_accounts()}
|
||||
|
||||
|
||||
@router.get("/accounts")
|
||||
async def accounts() -> dict:
|
||||
state.require_client()
|
||||
return {"accounts": list_local_accounts()}
|
||||
|
||||
|
||||
@router.delete("/accounts/{login_id}")
|
||||
async def remove_account(login_id: str) -> dict:
|
||||
state.require_client()
|
||||
await forget_account(login_id)
|
||||
return {"accounts": list_local_accounts()}
|
||||
|
||||
|
||||
@router.delete("/accounts")
|
||||
async def remove_accounts() -> dict:
|
||||
state.require_client()
|
||||
try:
|
||||
await clear_accounts()
|
||||
except NqiError as exc:
|
||||
raise _bad(str(exc)) from exc
|
||||
return {"accounts": []}
|
||||
|
||||
|
||||
@router.post("/resume")
|
||||
async def resume_saved(body: dict) -> dict:
|
||||
login_id = str(body.get("loginId") or "").strip()
|
||||
|
||||
@@ -83,6 +83,20 @@ async def forget_account(login_id: str) -> None:
|
||||
logger.warning("登录记录暂时写不进去: %s", exc)
|
||||
|
||||
|
||||
def list_local_accounts() -> list[dict]:
|
||||
"""本机保存的账号,不访问平台。"""
|
||||
return [public_view(item) for item in _read()]
|
||||
|
||||
|
||||
async def clear_accounts() -> None:
|
||||
async with _write_lock:
|
||||
try:
|
||||
_write([])
|
||||
except OSError as exc:
|
||||
logger.warning("登录记录暂时写不进去: %s", exc)
|
||||
raise NqiError("登录记录暂时无法清除") from exc
|
||||
|
||||
|
||||
def public_view(item: dict) -> dict:
|
||||
return {
|
||||
"loginId": item.get("loginId") or "",
|
||||
|
||||
@@ -23,7 +23,7 @@ crate-type = ["staticlib", "cdylib", "rlib"]
|
||||
tauri-build = { version = "2", features = [] }
|
||||
|
||||
[dependencies]
|
||||
tauri = { version = "2", features = [] }
|
||||
tauri = { version = "2", features = ["tray-icon"] }
|
||||
tauri-plugin-opener = "2"
|
||||
tauri-plugin-dialog = "2"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
|
||||
@@ -9,6 +9,7 @@ use tauri::{Emitter, Manager};
|
||||
|
||||
#[cfg(windows)]
|
||||
mod job;
|
||||
mod tray;
|
||||
|
||||
const LOG_LIMIT: u64 = 5 * 1024 * 1024;
|
||||
const CLOSE_GRACE: Duration = Duration::from_secs(10);
|
||||
@@ -37,8 +38,8 @@ static BACKEND: Mutex<BackendState> = Mutex::new(BackendState {
|
||||
error: None,
|
||||
download_dir: PathBuf::new(),
|
||||
});
|
||||
static ACTIVE: AtomicU32 = AtomicU32::new(0);
|
||||
static ALLOW_CLOSE: AtomicBool = AtomicBool::new(false);
|
||||
pub(crate) static ACTIVE: AtomicU32 = AtomicU32::new(0);
|
||||
pub(crate) static ALLOW_CLOSE: AtomicBool = AtomicBool::new(false);
|
||||
static PROMPTED_AT: Mutex<Option<Instant>> = Mutex::new(None);
|
||||
|
||||
#[derive(Clone, serde::Serialize)]
|
||||
@@ -50,7 +51,7 @@ struct BackendInfo {
|
||||
}
|
||||
|
||||
#[derive(Clone, serde::Serialize)]
|
||||
struct CloseRequested {
|
||||
pub(crate) struct CloseRequested {
|
||||
active: u32,
|
||||
}
|
||||
|
||||
@@ -361,7 +362,7 @@ fn ensure_started(app: &tauri::AppHandle) {
|
||||
spawn_child(app, &mut state);
|
||||
}
|
||||
|
||||
fn focus_existing(app: &tauri::AppHandle) {
|
||||
pub(crate) fn focus_existing(app: &tauri::AppHandle) {
|
||||
let Some(window) = app.get_webview_window("main") else {
|
||||
return;
|
||||
};
|
||||
@@ -386,11 +387,17 @@ fn install_close_guard(app: &tauri::AppHandle) {
|
||||
return;
|
||||
};
|
||||
let app = app.clone();
|
||||
let window_handle = window.clone();
|
||||
window.on_window_event(move |event| {
|
||||
if let tauri::WindowEvent::CloseRequested { api, .. } = event {
|
||||
if ALLOW_CLOSE.load(Ordering::SeqCst) {
|
||||
return;
|
||||
}
|
||||
if tray::should_hide_on_close() {
|
||||
api.prevent_close();
|
||||
let _ = window_handle.hide();
|
||||
return;
|
||||
}
|
||||
let active = ACTIVE.load(Ordering::SeqCst);
|
||||
if active == 0 {
|
||||
return;
|
||||
@@ -434,11 +441,15 @@ pub fn run() {
|
||||
restart_backend,
|
||||
set_close_guard,
|
||||
close_app,
|
||||
write_sample_csv
|
||||
write_sample_csv,
|
||||
tray::set_shell_mode
|
||||
])
|
||||
.setup(|app| {
|
||||
let handle = app.handle().clone();
|
||||
install_close_guard(&handle);
|
||||
if let Err(error) = tray::install(&handle) {
|
||||
eprintln!("托盘图标没有创建:{error}");
|
||||
}
|
||||
{
|
||||
let _guard = lock_launch();
|
||||
let mut state = lock_backend();
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
|
||||
use tauri::menu::{Menu, MenuItem, PredefinedMenuItem};
|
||||
use tauri::tray::{MouseButton, MouseButtonState, TrayIconBuilder, TrayIconEvent};
|
||||
use tauri::{Emitter, Manager};
|
||||
|
||||
use crate::{focus_existing, CloseRequested, ACTIVE, ALLOW_CLOSE};
|
||||
|
||||
static LOGGED_IN: AtomicBool = AtomicBool::new(false);
|
||||
static SHOW_TRAY: AtomicBool = AtomicBool::new(true);
|
||||
static CLOSE_TO_TRAY: AtomicBool = AtomicBool::new(true);
|
||||
|
||||
pub fn should_hide_on_close() -> bool {
|
||||
LOGGED_IN.load(Ordering::SeqCst)
|
||||
&& SHOW_TRAY.load(Ordering::SeqCst)
|
||||
&& CLOSE_TO_TRAY.load(Ordering::SeqCst)
|
||||
}
|
||||
|
||||
pub fn install(app: &tauri::AppHandle) -> tauri::Result<()> {
|
||||
let show = MenuItem::with_id(app, "show", "显示界面", true, None::<&str>)?;
|
||||
let hide = MenuItem::with_id(app, "hide", "隐藏界面", true, None::<&str>)?;
|
||||
let quit = MenuItem::with_id(app, "quit", "退出", true, None::<&str>)?;
|
||||
let separator = PredefinedMenuItem::separator(app)?;
|
||||
let menu = Menu::with_items(app, &[&show, &hide, &separator, &quit])?;
|
||||
let mut builder = TrayIconBuilder::with_id("main")
|
||||
.menu(&menu)
|
||||
.tooltip("NqiTools")
|
||||
.show_menu_on_left_click(false)
|
||||
.on_menu_event(|app, event| match event.id.as_ref() {
|
||||
"show" => focus_existing(app),
|
||||
"hide" => hide_main(app),
|
||||
"quit" => request_quit(app),
|
||||
_ => {}
|
||||
})
|
||||
.on_tray_icon_event(|tray, event| {
|
||||
if let TrayIconEvent::Click {
|
||||
button: MouseButton::Left,
|
||||
button_state: MouseButtonState::Up,
|
||||
..
|
||||
} = event
|
||||
{
|
||||
toggle_main(tray.app_handle());
|
||||
}
|
||||
});
|
||||
if let Some(icon) = app.default_window_icon() {
|
||||
builder = builder.icon(icon.clone());
|
||||
}
|
||||
let tray = builder.build(app)?;
|
||||
let _ = tray.set_visible(true);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn set_shell_mode(app: tauri::AppHandle, logged_in: bool, show_tray: bool, close_to_tray: bool) {
|
||||
LOGGED_IN.store(logged_in, Ordering::SeqCst);
|
||||
SHOW_TRAY.store(show_tray, Ordering::SeqCst);
|
||||
CLOSE_TO_TRAY.store(close_to_tray, Ordering::SeqCst);
|
||||
if let Some(tray) = app.tray_by_id("main") {
|
||||
let _ = tray.set_visible(show_tray);
|
||||
}
|
||||
if !show_tray {
|
||||
focus_existing(&app);
|
||||
}
|
||||
}
|
||||
|
||||
fn hide_main(app: &tauri::AppHandle) {
|
||||
if let Some(window) = app.get_webview_window("main") {
|
||||
let _ = window.hide();
|
||||
}
|
||||
}
|
||||
|
||||
fn toggle_main(app: &tauri::AppHandle) {
|
||||
let Some(window) = app.get_webview_window("main") else {
|
||||
return;
|
||||
};
|
||||
match window.is_visible() {
|
||||
Ok(true) => hide_main(app),
|
||||
_ => focus_existing(app),
|
||||
}
|
||||
}
|
||||
|
||||
fn request_quit(app: &tauri::AppHandle) {
|
||||
let active = ACTIVE.load(Ordering::SeqCst);
|
||||
if active > 0 {
|
||||
focus_existing(app);
|
||||
let _ = app.emit("nqi://close-requested", CloseRequested { active });
|
||||
return;
|
||||
}
|
||||
ALLOW_CLOSE.store(true, Ordering::SeqCst);
|
||||
if let Some(window) = app.get_webview_window("main") {
|
||||
let _ = window.close();
|
||||
} else {
|
||||
app.exit(0);
|
||||
}
|
||||
}
|
||||
+6
-1
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import { ref, watch } from "vue";
|
||||
import { darkTheme, NConfigProvider, NDialogProvider, NMessageProvider, zhCN, dateZhCN } from "naive-ui";
|
||||
import LoginView from "./features/auth/LoginView.vue";
|
||||
import Shell from "./shell/Shell.vue";
|
||||
@@ -7,6 +7,7 @@ import CloseGuard from "./shell/CloseGuard.vue";
|
||||
import type { UserInfo } from "./features/auth/api";
|
||||
import { isDark, themeOverrides } from "./shared/theme";
|
||||
import { clearUnauthorized, setUnauthorizedHandler } from "./shared/http";
|
||||
import { applyShellMode } from "./shared/shellMode";
|
||||
|
||||
const user = ref<UserInfo | null>(null);
|
||||
const authNotice = ref("");
|
||||
@@ -22,6 +23,10 @@ function onSuccess(next: UserInfo) {
|
||||
clearUnauthorized();
|
||||
user.value = next;
|
||||
}
|
||||
|
||||
watch(user, (value) => {
|
||||
void applyShellMode(Boolean(value));
|
||||
}, { immediate: true });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -42,6 +42,18 @@ export function loadSaved() {
|
||||
return api<{ accounts: UserInfo[] }>("/api/auth/saved");
|
||||
}
|
||||
|
||||
export function loadAccounts() {
|
||||
return api<{ accounts: UserInfo[] }>("/api/auth/accounts");
|
||||
}
|
||||
|
||||
export function removeAccount(loginId: string) {
|
||||
return api<{ accounts: UserInfo[] }>(`/api/auth/accounts/${encodeURIComponent(loginId)}`, { method: "DELETE" });
|
||||
}
|
||||
|
||||
export function clearAccounts() {
|
||||
return api<{ accounts: UserInfo[] }>("/api/auth/accounts", { method: "DELETE" });
|
||||
}
|
||||
|
||||
export function resumeSaved(loginId: string) {
|
||||
return api<{ status: string; user?: UserInfo }>("/api/auth/resume", {
|
||||
method: "POST",
|
||||
|
||||
@@ -82,6 +82,22 @@ export function deleteJob(id: string, files: boolean) {
|
||||
return api<unknown>(`/api/download/jobs/${encodeURIComponent(id)}?files=${flag}`, { method: "DELETE" });
|
||||
}
|
||||
|
||||
export interface AppSettings {
|
||||
showTray: boolean;
|
||||
closeToTray: boolean;
|
||||
}
|
||||
|
||||
export function loadAppSettings() {
|
||||
return api<AppSettings>("/api/download/settings/app");
|
||||
}
|
||||
|
||||
export function saveAppSettings(settings: AppSettings) {
|
||||
return api<AppSettings>("/api/download/settings/app", {
|
||||
method: "PUT",
|
||||
body: JSON.stringify(settings),
|
||||
});
|
||||
}
|
||||
|
||||
export function loadDownloadSettings() {
|
||||
return api<{ maxConcurrentJobs: number }>("/api/download/settings");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from "vue";
|
||||
import { NButton, NCheckbox, NEmpty, NIcon, NTooltip, useDialog, useMessage } from "naive-ui";
|
||||
import { HelpCircleOutline } from "@vicons/ionicons5";
|
||||
import { clearAccounts, loadAccounts, removeAccount, type UserInfo } from "../auth/api";
|
||||
import { loadAppSettings, saveAppSettings } from "../download/api";
|
||||
import { ApiError } from "../../shared/http";
|
||||
import { applyShellMode } from "../../shared/shellMode";
|
||||
|
||||
const message = useMessage();
|
||||
const dialog = useDialog();
|
||||
const accounts = ref<UserInfo[]>([]);
|
||||
const showTray = ref(true);
|
||||
const closeToTray = ref(true);
|
||||
const saving = ref(false);
|
||||
const clearing = ref(false);
|
||||
|
||||
onMounted(() => {
|
||||
void refresh();
|
||||
});
|
||||
|
||||
async function refresh() {
|
||||
try {
|
||||
const [settings, saved] = await Promise.all([loadAppSettings(), loadAccounts()]);
|
||||
showTray.value = settings.showTray;
|
||||
closeToTray.value = settings.closeToTray;
|
||||
accounts.value = saved.accounts;
|
||||
} catch (error) {
|
||||
message.error(error instanceof ApiError ? error.message : "设置读取失败");
|
||||
}
|
||||
}
|
||||
|
||||
function saveTray(checked: boolean) {
|
||||
showTray.value = checked;
|
||||
void persist();
|
||||
}
|
||||
|
||||
function saveClose(checked: boolean) {
|
||||
closeToTray.value = checked;
|
||||
void persist();
|
||||
}
|
||||
|
||||
async function persist() {
|
||||
if (saving.value) return;
|
||||
saving.value = true;
|
||||
try {
|
||||
const saved = await saveAppSettings({ showTray: showTray.value, closeToTray: closeToTray.value });
|
||||
showTray.value = saved.showTray;
|
||||
closeToTray.value = saved.closeToTray;
|
||||
await applyShellMode(true, saved);
|
||||
} catch (error) {
|
||||
message.error(error instanceof ApiError ? error.message : "设置保存失败");
|
||||
await refresh();
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function accountName(account: UserInfo) {
|
||||
const name = account.userName || account.loginId;
|
||||
return account.cityName ? `${name} · ${account.cityName}` : name;
|
||||
}
|
||||
|
||||
async function remove(account: UserInfo) {
|
||||
try {
|
||||
const result = await removeAccount(account.loginId);
|
||||
accounts.value = result.accounts;
|
||||
message.success("已移除这个账号");
|
||||
} catch (error) {
|
||||
message.error(error instanceof ApiError ? error.message : "移除失败");
|
||||
}
|
||||
}
|
||||
|
||||
function confirmClear() {
|
||||
dialog.warning({
|
||||
title: "清理登录痕迹",
|
||||
content: "会删除本机保存的全部账号。当前这次登录还在,退出后就不能直接进入了。",
|
||||
positiveText: "清理",
|
||||
negativeText: "取消",
|
||||
maskClosable: false,
|
||||
onPositiveClick: () => {
|
||||
void clearAll();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async function clearAll() {
|
||||
clearing.value = true;
|
||||
try {
|
||||
const result = await clearAccounts();
|
||||
accounts.value = result.accounts;
|
||||
message.success("已清理登录痕迹");
|
||||
} catch (error) {
|
||||
message.error(error instanceof ApiError ? error.message : "清理失败");
|
||||
} finally {
|
||||
clearing.value = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="page">
|
||||
<header class="page-head">
|
||||
<div class="head-title">
|
||||
<h2>设置</h2>
|
||||
</div>
|
||||
</header>
|
||||
<div class="page-body">
|
||||
<div class="settings-block">
|
||||
<h3>托盘</h3>
|
||||
<div class="form-row">
|
||||
<label>托盘图标</label>
|
||||
<n-checkbox :checked="showTray" :disabled="saving" @update:checked="(checked) => saveTray(checked)">显示在任务栏托盘</n-checkbox>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label>
|
||||
关闭窗口
|
||||
<n-tooltip>
|
||||
<template #trigger>
|
||||
<n-icon class="hint" :size="15"><HelpCircleOutline /></n-icon>
|
||||
</template>
|
||||
只在登录后生效。未登录时,关闭窗口会退出程序。
|
||||
</n-tooltip>
|
||||
</label>
|
||||
<n-checkbox :checked="closeToTray" :disabled="saving || !showTray" @update:checked="(checked) => saveClose(checked)">
|
||||
不退出,留在托盘
|
||||
</n-checkbox>
|
||||
</div>
|
||||
</div>
|
||||
<div class="settings-block">
|
||||
<div class="settings-head">
|
||||
<h3>已登录账号</h3>
|
||||
<n-button size="small" :disabled="!accounts.length || clearing" :loading="clearing" @click="confirmClear">
|
||||
清理登录痕迹
|
||||
</n-button>
|
||||
</div>
|
||||
<div v-if="accounts.length" class="account-list">
|
||||
<div v-for="account in accounts" :key="account.loginId" class="account-row">
|
||||
<div>
|
||||
<strong>{{ accountName(account) }}</strong>
|
||||
<span>{{ account.loginId }}</span>
|
||||
</div>
|
||||
<n-button size="small" @click="remove(account)">移除</n-button>
|
||||
</div>
|
||||
</div>
|
||||
<n-empty v-else description="还没有保存的账号" />
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,18 @@
|
||||
import { loadAppSettings, type AppSettings } from "../features/download/api";
|
||||
|
||||
const defaults: AppSettings = { showTray: true, closeToTray: true };
|
||||
|
||||
function inTauri() {
|
||||
return "__TAURI_INTERNALS__" in window;
|
||||
}
|
||||
|
||||
export async function applyShellMode(loggedIn: boolean, settings?: AppSettings) {
|
||||
const next = settings ?? (await loadAppSettings().catch(() => defaults));
|
||||
if (!inTauri()) return;
|
||||
const { invoke } = await import("@tauri-apps/api/core");
|
||||
await invoke("set_shell_mode", {
|
||||
loggedIn,
|
||||
showTray: next.showTray,
|
||||
closeToTray: next.closeToTray,
|
||||
});
|
||||
}
|
||||
+18
-11
@@ -1,7 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import { NButton, NIcon, NLayout, NLayoutSider, NMenu, NTooltip, useDialog } from "naive-ui";
|
||||
import { LogOutOutline, MoonOutline, PersonOutline, SunnyOutline } from "@vicons/ionicons5";
|
||||
import { LogOutOutline, MoonOutline, PersonOutline, SettingsOutline, SunnyOutline } from "@vicons/ionicons5";
|
||||
import { logout, type UserInfo } from "../features/auth/api";
|
||||
import { loadActiveDownloadCount } from "../features/download/api";
|
||||
import { ApiError } from "../shared/http";
|
||||
@@ -9,6 +9,7 @@ import { isDark, toggleTheme } from "../shared/theme";
|
||||
import { navOptions, type PageKey } from "./navigation";
|
||||
import GridDownloadView from "../features/download/GridDownloadView.vue";
|
||||
import DownloadManagerView from "../features/download/DownloadManagerView.vue";
|
||||
import SettingsView from "../features/settings/SettingsView.vue";
|
||||
|
||||
const props = defineProps<{ user: UserInfo }>();
|
||||
const emit = defineEmits<{ logout: [] }>();
|
||||
@@ -87,15 +88,6 @@ async function signOut() {
|
||||
@expand="collapsed = false"
|
||||
>
|
||||
<div class="sider-body">
|
||||
<div class="sider-title" :class="{ compact: collapsed }">
|
||||
<span class="brand-mark sider-mark" aria-hidden="true">
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none">
|
||||
<path d="M4 16.5 12 4l8 12.5" stroke="currentColor" stroke-width="1.8" />
|
||||
<path d="M7.2 16.5h9.6M9.2 13.2h5.6" stroke="currentColor" stroke-width="1.8" />
|
||||
</svg>
|
||||
</span>
|
||||
<span v-if="!collapsed">NqiTools</span>
|
||||
</div>
|
||||
<n-menu
|
||||
v-model:expanded-keys="expanded"
|
||||
:collapsed="collapsed"
|
||||
@@ -105,6 +97,20 @@ async function signOut() {
|
||||
:options="navOptions"
|
||||
@update:value="onMenu"
|
||||
/>
|
||||
<div class="sider-settings" :class="{ compact: collapsed }">
|
||||
<n-tooltip v-if="collapsed">
|
||||
<template #trigger>
|
||||
<n-button quaternary :type="page === 'settings' ? 'primary' : 'default'" aria-label="设置" @click="page = 'settings'">
|
||||
<template #icon><n-icon><SettingsOutline /></n-icon></template>
|
||||
</n-button>
|
||||
</template>
|
||||
设置
|
||||
</n-tooltip>
|
||||
<n-button v-else quaternary :type="page === 'settings' ? 'primary' : 'default'" @click="page = 'settings'">
|
||||
<template #icon><n-icon><SettingsOutline /></n-icon></template>
|
||||
设置
|
||||
</n-button>
|
||||
</div>
|
||||
<div class="sider-user" :class="{ compact: collapsed }">
|
||||
<n-icon :size="18"><PersonOutline /></n-icon>
|
||||
<div v-if="!collapsed" class="who">
|
||||
@@ -132,7 +138,8 @@ async function signOut() {
|
||||
</n-layout-sider>
|
||||
<n-layout class="content">
|
||||
<GridDownloadView v-if="page === 'grid'" :city-name="props.user.cityName" @started="onStarted" />
|
||||
<DownloadManagerView v-else :focus-id="focusId" />
|
||||
<DownloadManagerView v-else-if="page === 'tasks'" :focus-id="focusId" />
|
||||
<SettingsView v-else />
|
||||
</n-layout>
|
||||
</n-layout>
|
||||
</template>
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
import type { Component } from "vue";
|
||||
import { h } from "vue";
|
||||
import { NIcon } from "naive-ui";
|
||||
import { CloudDownloadOutline, GridOutline, ListOutline } from "@vicons/ionicons5";
|
||||
import { CloudDownloadOutline, GridOutline, LayersOutline } from "@vicons/ionicons5";
|
||||
|
||||
function renderIcon(icon: Component) {
|
||||
return () => h(NIcon, null, { default: () => h(icon) });
|
||||
}
|
||||
|
||||
export type PageKey = "grid" | "tasks";
|
||||
export type PageKey = "grid" | "tasks" | "settings";
|
||||
|
||||
export const navOptions = [
|
||||
{
|
||||
label: "下载",
|
||||
label: "数据下载",
|
||||
key: "download",
|
||||
icon: renderIcon(CloudDownloadOutline),
|
||||
icon: renderIcon(LayersOutline),
|
||||
children: [
|
||||
{ label: "栅格下载", key: "grid" as const, icon: renderIcon(GridOutline) },
|
||||
],
|
||||
},
|
||||
{ label: "下载管理", key: "tasks" as const, icon: renderIcon(ListOutline) },
|
||||
{ label: "下载管理", key: "tasks" as const, icon: renderIcon(CloudDownloadOutline) },
|
||||
];
|
||||
|
||||
+57
-17
@@ -201,26 +201,15 @@ select {
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.sider-title {
|
||||
.sider-settings {
|
||||
padding: 8px 12px 0;
|
||||
}
|
||||
|
||||
.sider-settings.compact {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 16px 16px 8px;
|
||||
font-weight: 650;
|
||||
font-size: 16px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.sider-title.compact {
|
||||
justify-content: center;
|
||||
padding-left: 0;
|
||||
padding-right: 0;
|
||||
}
|
||||
|
||||
.sider-mark {
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
border-radius: 8px;
|
||||
padding-left: 0;
|
||||
}
|
||||
|
||||
.sider-user {
|
||||
@@ -503,6 +492,57 @@ select {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.settings-block {
|
||||
margin: 16px 20px;
|
||||
padding: 16px;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 10px;
|
||||
background: var(--panel);
|
||||
}
|
||||
|
||||
.settings-block h3,
|
||||
.settings-head {
|
||||
margin: 0 0 12px;
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
.settings-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.settings-head h3 {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.account-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.account-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.account-row strong,
|
||||
.account-row span {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.account-row span {
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.task-size {
|
||||
flex: none;
|
||||
color: var(--muted);
|
||||
|
||||
Reference in New Issue
Block a user