Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scriptcat",
"version": "1.3.0-beta.3",
"version": "1.3.0-beta.4",
"description": "脚本猫,一个可以执行用户脚本的浏览器扩展,万物皆可脚本化,让你的浏览器可以做更多的事情!",
"author": "CodFrm",
"license": "GPLv3",
Expand Down
20 changes: 20 additions & 0 deletions src/app/service/service_worker/gm_api/gm_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import type {
GMApiRequest,
} from "../types";
import type { TScriptMenuRegister, TScriptMenuUnregister } from "../../queue";
import type { NotificationOptionCache } from "../utils";
import { BrowserNoSupport, notificationsUpdate } from "../utils";
import i18n from "@App/locales/locales";
import { encodeRValue, type TKeyValuePair } from "@App/pkg/utils/message_value";
Expand Down Expand Up @@ -1320,6 +1321,25 @@ export default class GMApi {
params,
} as NotificationMessageOption,
});
} else {
// 从缓存中检查是不是有选项
const options = await cacheInstance.get<NotificationOptionCache>(`notification:${notificationId}:options`);
if (options) {
if (event === "click") {
if (options.url) {
// 打开链接
chrome.tabs.create({
url: options.url,
});
// 关闭通知
chrome.notifications.clear(notificationId);
cacheInstance.del(`notification:${notificationId}:options`);
}
} else if (event === "close") {
// 删除缓存
cacheInstance.del(`notification:${notificationId}:options`);
}
Comment on lines +1338 to +1341
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

当通知被清除时,缓存也应该被删除。建议在第1336行 chrome.notifications.clear(notificationId) 之前也调用 cacheInstance.del(),以确保在所有情况下都能正确清理缓存。或者,可以将缓存删除逻辑提取为一个独立的函数来避免重复。

Copilot uses AI. Check for mistakes.
}
}
};
chrome.notifications.onClosed.addListener((notificationId, byUser) => {
Expand Down
7 changes: 5 additions & 2 deletions src/app/service/service_worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ import { ScriptDAO } from "@App/app/repo/scripts";
import { SystemService } from "./system";
import { type Logger, LoggerDAO } from "@App/app/repo/logger";
import { initLocales, initLocalesPromise, localePath, t, watchLanguageChange } from "@App/locales/locales";
import { getCurrentTab, InfoNotification } from "@App/pkg/utils/utils";
import { getCurrentTab } from "@App/pkg/utils/utils";
import { onTabRemoved, onUrlNavigated, setOnUserActionDomainChanged } from "./url_monitor";
import { LocalStorageDAO } from "@App/app/repo/localStorage";
import { FaviconDAO } from "@App/app/repo/favicon";
import { onRegularUpdateCheckAlarm } from "./regular_updatecheck";
import { cacheInstance } from "@App/app/cache";
import { InfoNotification } from "./utils";

// service worker的管理器
export default class ServiceWorkerManager {
Expand Down Expand Up @@ -207,7 +208,9 @@ export default class ServiceWorkerManager {
const url = `${DocumentationSite}${localePath}/docs/change/${ExtVersion.includes("-") ? "beta-changelog/" : ""}#${ExtVersion}`;
// 如果只是修复版本,只弹出通知不打开页面
// beta版本还是每次都打开更新页面
InfoNotification(t("ext_update_notification"), t("ext_update_notification_desc", { version: ExtVersion }));
InfoNotification(t("ext_update_notification"), t("ext_update_notification_desc", { version: ExtVersion }), {
url,
});
if (ExtVersion.endsWith(".0")) {
getCurrentTab()
.then((tab) => {
Expand Down
3 changes: 2 additions & 1 deletion src/app/service/service_worker/subscribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import { type Group } from "@Packages/message/server";
import { type ScriptService } from "./script";
import { createScriptInfo, type InstallSource } from "@App/pkg/utils/scriptInstall";
import { type TInstallSubscribe } from "../queue";
import { checkSilenceUpdate, InfoNotification } from "@App/pkg/utils/utils";
import { checkSilenceUpdate } from "@App/pkg/utils/utils";
import { ltever } from "@App/pkg/utils/semver";
import { fetchScriptBody, parseMetadata, prepareSubscribeByCode } from "@App/pkg/utils/script";
import { cacheInstance } from "@App/app/cache";
import { uuidv4 } from "@App/pkg/utils/uuid";
import { CACHE_KEY_SCRIPT_INFO } from "@App/app/cache_key";
import i18n, { i18nName } from "@App/locales/locales";
import { InfoNotification } from "./utils";

export class SubscribeService {
logger: Logger;
Expand Down
3 changes: 2 additions & 1 deletion src/app/service/service_worker/synchronize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ import { type ResourceService } from "./resource";
import { createObjectURL } from "../offscreen/client";
import { type CloudSyncConfig, type SystemConfig } from "@App/pkg/config/config";
import type { TDeleteScript, TInstallScript, TInstallScriptParams } from "../queue";
import { errorMsg, InfoNotification, makeBlobURL } from "@App/pkg/utils/utils";
import { errorMsg, makeBlobURL } from "@App/pkg/utils/utils";
import { t } from "i18next";
import ChromeStorage from "@App/pkg/config/chrome_storage";
import { type ScriptService } from "./script";
import { prepareScriptByCode } from "@App/pkg/utils/script";
import { ExtVersion } from "@App/app/const";
import { dayFormat } from "@App/pkg/utils/day_format";
import i18n, { i18nName } from "@App/locales/locales";
import { InfoNotification } from "./utils";

// type SynchronizeTarget = "local";

Expand Down
18 changes: 18 additions & 0 deletions src/app/service/service_worker/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
toUniquePatternStrings,
type URLRuleEntry,
} from "@App/pkg/utils/url_matcher";
import { cacheInstance } from "@App/app/cache";

export function getRunAt(runAts: string[]): chrome.extensionTypes.RunAt {
// 没有 run-at 时为 undefined. Fallback 至 document_idle
Expand Down Expand Up @@ -287,3 +288,20 @@ export const removeFavicon = (filename: string): Promise<void> => {
.then((opfsRoot) => opfsRoot.getDirectoryHandle(`cached_favicons`))
.then((faviconsFolder) => faviconsFolder.removeEntry(`${filename}`, { recursive: true }));
};

export type NotificationOptionCache = {
url?: string;
};

Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

函数缺少文档注释。建议添加 JSDoc 注释说明该函数的用途、参数含义以及 options 参数的作用,特别是 URL 选项会如何影响通知的行为。

Suggested change
/**
* 显示基础通知,并可选地为通知绑定额外参数(如跳转 URL)。
*
* 当提供 {@link NotificationOptionCache.url} 时,会将该选项与通知 ID 关联后
* 缓存到 {@link cacheInstance} 中,键名格式为 `notification:{notificationId}:options`
* 以便在 gm_api 中统一根据通知 ID 读取并处理(例如在点击通知时打开对应的 URL)。
*
* @param title 通知标题。
* @param msg 通知内容文本。
* @param options 额外的通知选项,例如 `url` 字段用于指定后续处理时需要打开的页面地址。
*/

Copilot uses AI. Check for mistakes.
export async function InfoNotification(title: string, msg: string, options?: NotificationOptionCache) {
const notificationId = await chrome.notifications.create({
type: "basic",
title,
message: msg,
iconUrl: chrome.runtime.getURL("assets/logo.png"),
});
// 如果设定了url,则保存到cache里,在gm_api中集中处理
if (options) {
cacheInstance.set(`notification:${notificationId}:options`, options);
}
}
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "__MSG_scriptcat__",
"version": "1.3.0.1400",
"version": "1.3.0.1500",
"author": "CodFrm",
"description": "__MSG_scriptcat_description__",
"options_ui": {
Expand Down
9 changes: 0 additions & 9 deletions src/pkg/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,6 @@ export function isFirefox() {
return typeof mozInnerScreenX !== "undefined";
}

export function InfoNotification(title: string, msg: string) {
chrome.notifications.create({
type: "basic",
title,
message: msg,
iconUrl: chrome.runtime.getURL("assets/logo.png"),
});
}

export function valueType(val: unknown) {
switch (typeof val) {
case "string":
Expand Down
Loading