mirror of
https://gitee.com/spark-store-project/spark-store
synced 2026-04-26 01:10:16 +08:00
完成 -apm 的全部更改,实现 spk://search,移除 spk://store
This commit is contained in:
@@ -45,7 +45,7 @@ class ListenersMap {
|
||||
}
|
||||
}
|
||||
|
||||
const protocols = ["apmstore"];
|
||||
const protocols = ["spk"];
|
||||
const listeners = new ListenersMap();
|
||||
|
||||
export const deepLink = {
|
||||
@@ -81,17 +81,27 @@ export function handleCommandLine(commandLine: string[]) {
|
||||
try {
|
||||
const url = new URL(target);
|
||||
|
||||
const action = url.hostname;
|
||||
const action = url.hostname; // 'search'
|
||||
logger.info(`Deep link: action found: ${action}`);
|
||||
|
||||
const query: Query = {};
|
||||
url.searchParams.forEach((value, key) => {
|
||||
query[key] = value;
|
||||
});
|
||||
logger.info(`Deep link: query found: ${JSON.stringify(query)}`);
|
||||
|
||||
const emitCount = listeners.emit(action, query);
|
||||
logger.info(`Deep link: emitted for ${emitCount} listeners`);
|
||||
if (action === "search") {
|
||||
// Format: spk://search/pkgname
|
||||
// url.pathname will be '/pkgname'
|
||||
const pkgname = url.pathname.split("/").filter(Boolean)[0];
|
||||
if (pkgname) {
|
||||
query.pkgname = pkgname;
|
||||
logger.info(`Deep link: search query found: ${JSON.stringify(query)}`);
|
||||
listeners.emit(action, query);
|
||||
} else {
|
||||
logger.warn(
|
||||
`Deep link: invalid search format, expected /pkgname, got ${url.pathname}`,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
logger.warn(`Deep link: unknown action ${action}`);
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error(`Deep link: error parsing URL: ${error}`);
|
||||
}
|
||||
|
||||
@@ -80,3 +80,28 @@ deepLink.on("install", (query) => {
|
||||
pendingActions.push(action);
|
||||
}
|
||||
});
|
||||
|
||||
deepLink.on("search", (query) => {
|
||||
logger.info(
|
||||
`Deep link: event "search" fired with query: ${JSON.stringify(query)}`,
|
||||
);
|
||||
|
||||
const action = () => {
|
||||
const win = BrowserWindow.getAllWindows()[0];
|
||||
if (!win) return;
|
||||
|
||||
if (query.pkgname) {
|
||||
win.webContents.send("deep-link-search", { pkgname: query.pkgname });
|
||||
if (win.isMinimized()) win.restore();
|
||||
win.focus();
|
||||
}
|
||||
};
|
||||
|
||||
logger.info(`isLoaded: ${isLoaded.value}`);
|
||||
|
||||
if (isLoaded.value) {
|
||||
action();
|
||||
} else {
|
||||
pendingActions.push(action);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user