支持spk命令行参数

spark-store-private/spark-store#15

spark-store-private/spark-store#16
This commit is contained in:
柚子
2025-03-08 01:15:54 +08:00
parent 1495d806aa
commit 12c81e41b3
9 changed files with 163 additions and 3 deletions

View File

@@ -15,6 +15,7 @@
"@kobalte/core": "^0.13.7",
"@solidjs/router": "^0.15.3",
"@tauri-apps/api": "^2",
"@tauri-apps/plugin-cli": "~2",
"@tauri-apps/plugin-clipboard-manager": "^2.2.0",
"@tauri-apps/plugin-opener": "^2",
"@tauri-apps/plugin-window-state": "~2",

111
src-tauri/Cargo.lock generated
View File

@@ -56,6 +56,56 @@ dependencies = [
"libc",
]
[[package]]
name = "anstream"
version = "0.6.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is_terminal_polyfill",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9"
[[package]]
name = "anstyle-parse"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c"
dependencies = [
"windows-sys 0.59.0",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca3534e77181a9cc07539ad51f2141fe32f6c3ffd4df76db8ad92346b003ae4e"
dependencies = [
"anstyle",
"once_cell",
"windows-sys 0.59.0",
]
[[package]]
name = "anyhow"
version = "1.0.95"
@@ -519,6 +569,33 @@ dependencies = [
"windows-targets 0.52.6",
]
[[package]]
name = "clap"
version = "4.5.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "027bb0d98429ae334a8698531da7077bdf906419543a35a55c2cb1b66437d767"
dependencies = [
"clap_builder",
]
[[package]]
name = "clap_builder"
version = "4.5.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5589e0cba072e0f3d23791efac0fd8627b49c829c196a492e88168e6a669d863"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_lex"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6"
[[package]]
name = "clipboard-win"
version = "5.4.0"
@@ -558,6 +635,12 @@ dependencies = [
"objc",
]
[[package]]
name = "colorchoice"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990"
[[package]]
name = "combine"
version = "4.6.7"
@@ -1978,6 +2061,12 @@ dependencies = [
"once_cell",
]
[[package]]
name = "is_terminal_polyfill"
version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
[[package]]
name = "itoa"
version = "0.4.8"
@@ -3751,6 +3840,7 @@ dependencies = [
"serde_json",
"tauri",
"tauri-build",
"tauri-plugin-cli",
"tauri-plugin-clipboard-manager",
"tauri-plugin-opener",
"tauri-plugin-window-state",
@@ -4087,6 +4177,21 @@ dependencies = [
"walkdir",
]
[[package]]
name = "tauri-plugin-cli"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5458ae16eac81bdbe8d9da2a9f3e01e8cdedbc381cc1727c01127542c8a61c5"
dependencies = [
"clap",
"log",
"serde",
"serde_json",
"tauri",
"tauri-plugin",
"thiserror 2.0.11",
]
[[package]]
name = "tauri-plugin-clipboard-manager"
version = "2.2.0"
@@ -4695,6 +4800,12 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
[[package]]
name = "utf8parse"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "uuid"
version = "1.12.0"

View File

@@ -34,4 +34,5 @@ dirs = "6.0.0"
base64 = "0.22.1"
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
tauri-plugin-cli = "2"
tauri-plugin-window-state = "2"

View File

@@ -9,6 +9,7 @@
"main"
],
"permissions": [
"window-state:default"
"window-state:default",
"cli:default"
]
}

View File

@@ -8,6 +8,7 @@ mod utils;
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_cli::init())
.plugin(tauri_plugin_window_state::Builder::new().build())
.plugin(tauri_plugin_opener::init())
.plugin(tauri_plugin_clipboard_manager::init())

View File

@@ -556,7 +556,9 @@ impl DownloadManager {
if output.status.success() {
println!("安装成功完成");
println!("命令输出: {}", String::from_utf8_lossy(&output.stdout));
let _ = self.update_download_count(&task.category, &task.pkgname).await;
let _ = self
.update_download_count(&task.category, &task.pkgname)
.await;
Ok(())
} else {
let error_msg = String::from_utf8_lossy(&output.stderr).to_string();

View File

@@ -39,5 +39,16 @@
"depends": ["aria2"]
}
}
},
"plugins": {
"cli": {
"args": [
{
"name": "spk",
"index": 1,
"takesValue": true
}
]
}
}
}

View File

@@ -1,18 +1,43 @@
import { Component, ParentProps, createSignal } from "solid-js";
import { Component, ParentProps, createSignal, onMount } from "solid-js";
import Sidebar from "./components/Sidebar";
import "./App.css";
import { SidebarProvider, useIsMobile, useSidebar } from "./components/ui/sidebar";
import TitleBar from "./components/TitleBar";
import { Toaster } from "./components/ui/toast";
import { getMatches } from '@tauri-apps/plugin-cli';
import { useNavigate } from "@solidjs/router";
const App: Component = (props: ParentProps) => {
const isMobile = useIsMobile();
const navigate = useNavigate();
const [shouldRefresh, setShouldRefresh] = createSignal(false);
const handleRefresh = () => {
setShouldRefresh(prev => !prev);
};
onMount(async () => {
const matches = await getMatches();
if(typeof matches.args.spk?.value === 'string')
{
if(matches.args.spk.value.startsWith('spk://search/'))
{
// 处理 spk://search/ 协议
const path = matches.args.spk?.value.replace('spk://search/', '');
navigate(`/search?q=${path}`);
}else if(matches.args.spk.value.startsWith('spk://'))
{
// 处理 spk:// 协议
const path = matches.args.spk?.value.replace('spk://', '');
const parts = path.split('/');
const category = parts[parts.length - 2];
const pkgname = parts[parts.length - 1];
navigate(`/app/${category}/${pkgname}`);
}
}
})
return (
<div class="app-layout">
<SidebarProvider>

View File

@@ -688,6 +688,13 @@
"@tauri-apps/cli-win32-ia32-msvc" "2.2.5"
"@tauri-apps/cli-win32-x64-msvc" "2.2.5"
"@tauri-apps/plugin-cli@~2":
version "2.2.0"
resolved "https://registry.npmmirror.com/@tauri-apps/plugin-cli/-/plugin-cli-2.2.0.tgz#59e8c8a8fd313f5d6453c894466df5be122688d8"
integrity sha512-rvNhMog9rHr01Xk+trBFKJ0eZICIvPkm9GX6ogB89/0hROU/lf+a/sb4vC0wtSeR7zrJuCSxwxYuvHCZheaYFA==
dependencies:
"@tauri-apps/api" "^2.0.0"
"@tauri-apps/plugin-clipboard-manager@^2.2.0":
version "2.2.0"
resolved "https://registry.npmmirror.com/@tauri-apps/plugin-clipboard-manager/-/plugin-clipboard-manager-2.2.0.tgz#3d8f60457da3054454d93dd3fb5a3ca10eef0e5b"