style: 统一代码格式与字符串引号风格

1.  替换单引号为双引号统一字符串格式
2.  拆分过长的函数调用与条件判断行提升可读性
3.  简化多行console.log调用为单行格式
4.  为侧边栏添加条目计数标签展示功能
This commit is contained in:
2026-07-14 13:59:55 +08:00
parent 750e1d89e4
commit 7420466d92
7 changed files with 100 additions and 56 deletions
+57 -17
View File
@@ -535,15 +535,29 @@ export const registerUpdateCenterIpc = (
const results: { aptss?: string; apm?: string } = {}; const results: { aptss?: string; apm?: string } = {};
const runCommand = (command: string, args: string[]): Promise<{ code: number; stdout: string; stderr: string }> => const runCommand = (
command: string,
args: string[],
): Promise<{ code: number; stdout: string; stderr: string }> =>
new Promise((resolve) => { new Promise((resolve) => {
const child = spawn(command, args, { shell: false, env: process.env }); const child = spawn(command, args, {
shell: false,
env: process.env,
});
let stdout = ""; let stdout = "";
let stderr = ""; let stderr = "";
child.stdout?.on("data", (data) => { stdout += data.toString(); }); child.stdout?.on("data", (data) => {
child.stderr?.on("data", (data) => { stderr += data.toString(); }); stdout += data.toString();
child.on("error", (err) => resolve({ code: -1, stdout, stderr: err.message })); });
child.on("close", (code) => resolve({ code: code ?? -1, stdout, stderr })); child.stderr?.on("data", (data) => {
stderr += data.toString();
});
child.on("error", (err) =>
resolve({ code: -1, stdout, stderr: err.message }),
);
child.on("close", (code) =>
resolve({ code: code ?? -1, stdout, stderr }),
);
}); });
const isSourceEnabled = ( const isSourceEnabled = (
@@ -554,17 +568,31 @@ export const registerUpdateCenterIpc = (
// aptss update — 需要提权 // aptss update — 需要提权
if (isSourceEnabled(storeFilter, "spark")) { if (isSourceEnabled(storeFilter, "spark")) {
const whichResult = await runCommand("which", ["aptss"]); const whichResult = await runCommand("which", ["aptss"]);
const aptssAvailable = whichResult.code === 0 && whichResult.stdout.trim().length > 0; const aptssAvailable =
whichResult.code === 0 && whichResult.stdout.trim().length > 0;
if (aptssAvailable) { if (aptssAvailable) {
console.log("[UpdateCenter] Running: pkexec shell-caller aptss ssupdate"); console.log(
const superUserCmd = await findExecutable(SUPER_USER_COMMAND_CANDIDATES[0]); "[UpdateCenter] Running: pkexec shell-caller aptss ssupdate",
);
const superUserCmd = await findExecutable(
SUPER_USER_COMMAND_CANDIDATES[0],
);
if (superUserCmd) { if (superUserCmd) {
const result = await runCommand(superUserCmd, [SHELL_CALLER_PATH, "aptss", "ssupdate"]); const result = await runCommand(superUserCmd, [
results.aptss = result.code === 0 ? "ok" : `failed: ${result.stderr.substring(0, 200)}`; SHELL_CALLER_PATH,
"aptss",
"ssupdate",
]);
results.aptss =
result.code === 0
? "ok"
: `failed: ${result.stderr.substring(0, 200)}`;
console.log("[UpdateCenter] aptss ssupdate result:", results.aptss); console.log("[UpdateCenter] aptss ssupdate result:", results.aptss);
} else { } else {
results.aptss = "failed: pkexec not found"; results.aptss = "failed: pkexec not found";
console.warn("[UpdateCenter] pkexec not found, skipping aptss update"); console.warn(
"[UpdateCenter] pkexec not found, skipping aptss update",
);
} }
} else { } else {
results.aptss = "skipped: aptss not installed"; results.aptss = "skipped: aptss not installed";
@@ -574,17 +602,29 @@ export const registerUpdateCenterIpc = (
// apm update — 也需要提权 // apm update — 也需要提权
if (isSourceEnabled(storeFilter, "apm")) { if (isSourceEnabled(storeFilter, "apm")) {
const whichResult = await runCommand("which", ["apm"]); const whichResult = await runCommand("which", ["apm"]);
const apmAvailable = whichResult.code === 0 && whichResult.stdout.trim().length > 0; const apmAvailable =
whichResult.code === 0 && whichResult.stdout.trim().length > 0;
if (apmAvailable) { if (apmAvailable) {
console.log("[UpdateCenter] Running: pkexec shell-caller apm update"); console.log("[UpdateCenter] Running: pkexec shell-caller apm update");
const superUserCmd = await findExecutable(SUPER_USER_COMMAND_CANDIDATES[0]); const superUserCmd = await findExecutable(
SUPER_USER_COMMAND_CANDIDATES[0],
);
if (superUserCmd) { if (superUserCmd) {
const result = await runCommand(superUserCmd, [SHELL_CALLER_PATH, "apm", "update"]); const result = await runCommand(superUserCmd, [
results.apm = result.code === 0 ? "ok" : `failed: ${result.stderr.substring(0, 200)}`; SHELL_CALLER_PATH,
"apm",
"update",
]);
results.apm =
result.code === 0
? "ok"
: `failed: ${result.stderr.substring(0, 200)}`;
console.log("[UpdateCenter] apm update result:", results.apm); console.log("[UpdateCenter] apm update result:", results.apm);
} else { } else {
results.apm = "failed: pkexec not found"; results.apm = "failed: pkexec not found";
console.warn("[UpdateCenter] pkexec not found, skipping apm update"); console.warn(
"[UpdateCenter] pkexec not found, skipping apm update",
);
} }
} else { } else {
results.apm = "skipped: apm not installed"; results.apm = "skipped: apm not installed";
+1 -1
View File
@@ -197,7 +197,7 @@
class="fas text-xs" class="fas text-xs"
:class="spkCopied ? 'fa-check' : 'fa-share-alt'" :class="spkCopied ? 'fa-check' : 'fa-share-alt'"
></i> ></i>
<span>{{ spkCopied ? '已复制链接' : 'SPK 分享' }}</span> <span>{{ spkCopied ? "已复制链接" : "SPK 分享" }}</span>
</button> </button>
</div> </div>
+1 -1
View File
@@ -134,7 +134,7 @@
class="fas text-xs" class="fas text-xs"
:class="spkCopied ? 'fa-check' : 'fa-share-alt'" :class="spkCopied ? 'fa-check' : 'fa-share-alt'"
></i> ></i>
<span>{{ spkCopied ? '已复制链接' : 'SPK 分享' }}</span> <span>{{ spkCopied ? "已复制链接" : "SPK 分享" }}</span>
</button> </button>
</div> </div>
+2 -1
View File
@@ -80,7 +80,8 @@ const handleSearchFocus = () => {
const handleInput = () => { const handleInput = () => {
const value = localSearchQuery.value.trim(); const value = localSearchQuery.value.trim();
// 检测 SPK 分享链接: spk://store/{category}/{pkgname} // 检测 SPK 分享链接: spk://store/{category}/{pkgname}
const spkMatch = value.match(/^spk:\/\/search\/(.+)$/i) || const spkMatch =
value.match(/^spk:\/\/search\/(.+)$/i) ||
value.match(/^spk:\/\/store\/[^/]+\/(.+)$/i); value.match(/^spk:\/\/store\/[^/]+\/(.+)$/i);
if (spkMatch) { if (spkMatch) {
const pkgname = spkMatch[1].trim(); const pkgname = spkMatch[1].trim();
+5
View File
@@ -96,6 +96,11 @@
<i v-else class="fas fa-folder"></i> <i v-else class="fas fa-folder"></i>
</span> </span>
<span class="sidebar-tab-label">{{ entry.name }}</span> <span class="sidebar-tab-label">{{ entry.name }}</span>
<span
v-if="entryCounts[entry.id]"
class="ml-auto rounded-full bg-slate-100 px-2 py-0.5 text-xs font-semibold text-slate-500 dark:bg-slate-800/70 dark:text-slate-300"
>{{ entryCounts[entry.id] }}</span
>
</button> </button>
</div> </div>
+30 -35
View File
@@ -46,12 +46,19 @@
class="hidden" class="hidden"
@change="handleDebFileSelect" @change="handleDebFileSelect"
/> />
<div v-if="isParsingDeb || isSearchingHistory" class="flex flex-col items-center"> <div
v-if="isParsingDeb || isSearchingHistory"
class="flex flex-col items-center"
>
<div <div
class="animate-spin rounded-full h-12 w-12 border-b-2 border-blue-500 mb-4" class="animate-spin rounded-full h-12 w-12 border-b-2 border-blue-500 mb-4"
></div> ></div>
<p class="text-slate-600 dark:text-slate-400"> <p class="text-slate-600 dark:text-slate-400">
{{ isParsingDeb ? '正在解析 deb 文件...' : '正在从服务器查询已上架信息...' }} {{
isParsingDeb
? "正在解析 deb 文件..."
: "正在从服务器查询已上架信息..."
}}
</p> </p>
</div> </div>
<div v-else> <div v-else>
@@ -698,7 +705,11 @@ const loadCategoriesList = async (): Promise<void> => {
if (result?.success && result.data) { if (result?.success && result.data) {
const data = result.data; const data = result.data;
if (data.code === 0 && Array.isArray(data.data) && data.data.length > 0) { if (
data.code === 0 &&
Array.isArray(data.data) &&
data.data.length > 0
) {
categoriesList.value = data.data.map( categoriesList.value = data.data.map(
(item: { id: number; name: string }, index: number) => ({ (item: { id: number; name: string }, index: number) => ({
id: typeof item.id === "number" ? item.id : index + 1, id: typeof item.id === "number" ? item.id : index + 1,
@@ -709,7 +720,10 @@ const loadCategoriesList = async (): Promise<void> => {
}), }),
); );
categoriesLoadError.value = ""; categoriesLoadError.value = "";
console.log("[Submitter] Categories loaded from API:", categoriesList.value); console.log(
"[Submitter] Categories loaded from API:",
categoriesList.value,
);
} else if (data.code === 0 && Array.isArray(data)) { } else if (data.code === 0 && Array.isArray(data)) {
categoriesList.value = data.map( categoriesList.value = data.map(
(item: { id: number; name: string }, index: number) => ({ (item: { id: number; name: string }, index: number) => ({
@@ -719,7 +733,10 @@ const loadCategoriesList = async (): Promise<void> => {
}), }),
); );
categoriesLoadError.value = ""; categoriesLoadError.value = "";
console.log("[Submitter] Categories loaded from API (direct array):", categoriesList.value); console.log(
"[Submitter] Categories loaded from API (direct array):",
categoriesList.value,
);
} else { } else {
const errMsg = `服务器返回异常: code=${data.code}, msg=${data.msg || "未知"}`; const errMsg = `服务器返回异常: code=${data.code}, msg=${data.msg || "未知"}`;
categoriesLoadError.value = errMsg; categoriesLoadError.value = errMsg;
@@ -867,13 +884,8 @@ const searchHistoryApp = async () => {
historyResult.data && historyResult.data &&
historyResult.data.length > 0 historyResult.data.length > 0
) { ) {
console.log( console.log("[Submitter] ============== HISTORY INFO FOUND ==============");
"[Submitter] ============== HISTORY INFO FOUND ==============", console.log("[Submitter] History info count:", historyResult.data.length);
);
console.log(
"[Submitter] History info count:",
historyResult.data.length,
);
console.log( console.log(
"[Submitter] Available archs data:", "[Submitter] Available archs data:",
JSON.stringify(historyResult.data, null, 2), JSON.stringify(historyResult.data, null, 2),
@@ -882,14 +894,8 @@ const searchHistoryApp = async () => {
console.log( console.log(
"[Submitter] ============== BEFORE SETTING STATE ==============", "[Submitter] ============== BEFORE SETTING STATE ==============",
); );
console.log( console.log("[Submitter] availableArchs before:", availableArchs.value);
"[Submitter] availableArchs before:", console.log("[Submitter] showArchDialog before:", showArchDialog.value);
availableArchs.value,
);
console.log(
"[Submitter] showArchDialog before:",
showArchDialog.value,
);
// 按 amd64 → arm64 → loong64 顺序排序 // 按 amd64 → arm64 → loong64 顺序排序
const archOrder: Record<string, number> = { const archOrder: Record<string, number> = {
@@ -900,10 +906,7 @@ const searchHistoryApp = async () => {
availableArchs.value = [...historyResult.data].sort( availableArchs.value = [...historyResult.data].sort(
(a, b) => (archOrder[a.store] ?? 99) - (archOrder[b.store] ?? 99), (a, b) => (archOrder[a.store] ?? 99) - (archOrder[b.store] ?? 99),
); );
console.log( console.log("[Submitter] availableArchs after:", availableArchs.value);
"[Submitter] availableArchs after:",
availableArchs.value,
);
console.log( console.log(
"[Submitter] availableArchs length:", "[Submitter] availableArchs length:",
availableArchs.value.length, availableArchs.value.length,
@@ -922,10 +925,7 @@ const searchHistoryApp = async () => {
} }
showArchDialog.value = true; showArchDialog.value = true;
console.log( console.log("[Submitter] showArchDialog after:", showArchDialog.value);
"[Submitter] showArchDialog after:",
showArchDialog.value,
);
console.log( console.log(
"[Submitter] ============== DIALOG SHOULD BE SHOWING ==============", "[Submitter] ============== DIALOG SHOULD BE SHOWING ==============",
@@ -937,9 +937,7 @@ const searchHistoryApp = async () => {
); );
nextTick(() => { nextTick(() => {
console.log( console.log("[Submitter] ============== AFTER NEXT TICK ==============");
"[Submitter] ============== AFTER NEXT TICK ==============",
);
console.log( console.log(
"[Submitter] showArchDialog in nextTick:", "[Submitter] showArchDialog in nextTick:",
showArchDialog.value, showArchDialog.value,
@@ -965,10 +963,7 @@ const searchHistoryApp = async () => {
console.log( console.log(
"[Submitter] ============== NO HISTORY INFO FOUND ==============", "[Submitter] ============== NO HISTORY INFO FOUND ==============",
); );
console.log( console.log("[Submitter] historyResult.success:", historyResult?.success);
"[Submitter] historyResult.success:",
historyResult?.success,
);
console.log("[Submitter] historyResult.data:", historyResult?.data); console.log("[Submitter] historyResult.data:", historyResult?.data);
console.log( console.log(
"[Submitter] historyResult.data.length:", "[Submitter] historyResult.data.length:",
+4 -1
View File
@@ -153,7 +153,10 @@ export const createUpdateCenterStore = (): UpdateCenterStore => {
loading.value = true; loading.value = true;
try { try {
// 先运行系统更新(aptss update / apm update),确保本地包信息最新 // 先运行系统更新(aptss update / apm update),确保本地包信息最新
await window.ipcRenderer.invoke("update-center-run-system-update", storeFilter); await window.ipcRenderer.invoke(
"update-center-run-system-update",
storeFilter,
);
const nextSnapshot = await window.updateCenter.refresh(storeFilter); const nextSnapshot = await window.updateCenter.refresh(storeFilter);
applySnapshot(nextSnapshot); applySnapshot(nextSnapshot);
} finally { } finally {