Skip to content

Commit 75180b7

Browse files
authored
🐛 修复点击更新日志通知打开页面问题 (#1266)
* 🐛 修复点击更新日志通知打开页面问题 * 删除缓存 * 1.3.0-beta.4
1 parent b27971f commit 75180b7

File tree

8 files changed

+49
-15
lines changed

8 files changed

+49
-15
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "scriptcat",
3-
"version": "1.3.0-beta.3",
3+
"version": "1.3.0-beta.4",
44
"description": "脚本猫,一个可以执行用户脚本的浏览器扩展,万物皆可脚本化,让你的浏览器可以做更多的事情!",
55
"author": "CodFrm",
66
"license": "GPLv3",

src/app/service/service_worker/gm_api/gm_api.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import type {
2626
GMApiRequest,
2727
} from "../types";
2828
import type { TScriptMenuRegister, TScriptMenuUnregister } from "../../queue";
29+
import type { NotificationOptionCache } from "../utils";
2930
import { BrowserNoSupport, notificationsUpdate } from "../utils";
3031
import i18n from "@App/locales/locales";
3132
import { encodeRValue, type TKeyValuePair } from "@App/pkg/utils/message_value";
@@ -1320,6 +1321,25 @@ export default class GMApi {
13201321
params,
13211322
} as NotificationMessageOption,
13221323
});
1324+
} else {
1325+
// 从缓存中检查是不是有选项
1326+
const options = await cacheInstance.get<NotificationOptionCache>(`notification:${notificationId}:options`);
1327+
if (options) {
1328+
if (event === "click") {
1329+
if (options.url) {
1330+
// 打开链接
1331+
chrome.tabs.create({
1332+
url: options.url,
1333+
});
1334+
// 关闭通知
1335+
chrome.notifications.clear(notificationId);
1336+
cacheInstance.del(`notification:${notificationId}:options`);
1337+
}
1338+
} else if (event === "close") {
1339+
// 删除缓存
1340+
cacheInstance.del(`notification:${notificationId}:options`);
1341+
}
1342+
}
13231343
}
13241344
};
13251345
chrome.notifications.onClosed.addListener((notificationId, byUser) => {

src/app/service/service_worker/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ import { ScriptDAO } from "@App/app/repo/scripts";
1414
import { SystemService } from "./system";
1515
import { type Logger, LoggerDAO } from "@App/app/repo/logger";
1616
import { initLocales, initLocalesPromise, localePath, t, watchLanguageChange } from "@App/locales/locales";
17-
import { getCurrentTab, InfoNotification } from "@App/pkg/utils/utils";
17+
import { getCurrentTab } from "@App/pkg/utils/utils";
1818
import { onTabRemoved, onUrlNavigated, setOnUserActionDomainChanged } from "./url_monitor";
1919
import { LocalStorageDAO } from "@App/app/repo/localStorage";
2020
import { FaviconDAO } from "@App/app/repo/favicon";
2121
import { onRegularUpdateCheckAlarm } from "./regular_updatecheck";
2222
import { cacheInstance } from "@App/app/cache";
23+
import { InfoNotification } from "./utils";
2324

2425
// service worker的管理器
2526
export default class ServiceWorkerManager {
@@ -207,7 +208,9 @@ export default class ServiceWorkerManager {
207208
const url = `${DocumentationSite}${localePath}/docs/change/${ExtVersion.includes("-") ? "beta-changelog/" : ""}#${ExtVersion}`;
208209
// 如果只是修复版本,只弹出通知不打开页面
209210
// beta版本还是每次都打开更新页面
210-
InfoNotification(t("ext_update_notification"), t("ext_update_notification_desc", { version: ExtVersion }));
211+
InfoNotification(t("ext_update_notification"), t("ext_update_notification_desc", { version: ExtVersion }), {
212+
url,
213+
});
211214
if (ExtVersion.endsWith(".0")) {
212215
getCurrentTab()
213216
.then((tab) => {

src/app/service/service_worker/subscribe.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ import { type Group } from "@Packages/message/server";
99
import { type ScriptService } from "./script";
1010
import { createScriptInfo, type InstallSource } from "@App/pkg/utils/scriptInstall";
1111
import { type TInstallSubscribe } from "../queue";
12-
import { checkSilenceUpdate, InfoNotification } from "@App/pkg/utils/utils";
12+
import { checkSilenceUpdate } from "@App/pkg/utils/utils";
1313
import { ltever } from "@App/pkg/utils/semver";
1414
import { fetchScriptBody, parseMetadata, prepareSubscribeByCode } from "@App/pkg/utils/script";
1515
import { cacheInstance } from "@App/app/cache";
1616
import { uuidv4 } from "@App/pkg/utils/uuid";
1717
import { CACHE_KEY_SCRIPT_INFO } from "@App/app/cache_key";
1818
import i18n, { i18nName } from "@App/locales/locales";
19+
import { InfoNotification } from "./utils";
1920

2021
export class SubscribeService {
2122
logger: Logger;

src/app/service/service_worker/synchronize.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,15 @@ import { type ResourceService } from "./resource";
2424
import { createObjectURL } from "../offscreen/client";
2525
import { type CloudSyncConfig, type SystemConfig } from "@App/pkg/config/config";
2626
import type { TDeleteScript, TInstallScript, TInstallScriptParams } from "../queue";
27-
import { errorMsg, InfoNotification, makeBlobURL } from "@App/pkg/utils/utils";
27+
import { errorMsg, makeBlobURL } from "@App/pkg/utils/utils";
2828
import { t } from "i18next";
2929
import ChromeStorage from "@App/pkg/config/chrome_storage";
3030
import { type ScriptService } from "./script";
3131
import { prepareScriptByCode } from "@App/pkg/utils/script";
3232
import { ExtVersion } from "@App/app/const";
3333
import { dayFormat } from "@App/pkg/utils/day_format";
3434
import i18n, { i18nName } from "@App/locales/locales";
35+
import { InfoNotification } from "./utils";
3536

3637
// type SynchronizeTarget = "local";
3738

src/app/service/service_worker/utils.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
toUniquePatternStrings,
1818
type URLRuleEntry,
1919
} from "@App/pkg/utils/url_matcher";
20+
import { cacheInstance } from "@App/app/cache";
2021

2122
export function getRunAt(runAts: string[]): chrome.extensionTypes.RunAt {
2223
// 没有 run-at 时为 undefined. Fallback 至 document_idle
@@ -287,3 +288,20 @@ export const removeFavicon = (filename: string): Promise<void> => {
287288
.then((opfsRoot) => opfsRoot.getDirectoryHandle(`cached_favicons`))
288289
.then((faviconsFolder) => faviconsFolder.removeEntry(`${filename}`, { recursive: true }));
289290
};
291+
292+
export type NotificationOptionCache = {
293+
url?: string;
294+
};
295+
296+
export async function InfoNotification(title: string, msg: string, options?: NotificationOptionCache) {
297+
const notificationId = await chrome.notifications.create({
298+
type: "basic",
299+
title,
300+
message: msg,
301+
iconUrl: chrome.runtime.getURL("assets/logo.png"),
302+
});
303+
// 如果设定了url,则保存到cache里,在gm_api中集中处理
304+
if (options) {
305+
cacheInstance.set(`notification:${notificationId}:options`, options);
306+
}
307+
}

src/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": 3,
33
"name": "__MSG_scriptcat__",
4-
"version": "1.3.0.1400",
4+
"version": "1.3.0.1500",
55
"author": "CodFrm",
66
"description": "__MSG_scriptcat_description__",
77
"options_ui": {

src/pkg/utils/utils.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,6 @@ export function isFirefox() {
4444
return typeof mozInnerScreenX !== "undefined";
4545
}
4646

47-
export function InfoNotification(title: string, msg: string) {
48-
chrome.notifications.create({
49-
type: "basic",
50-
title,
51-
message: msg,
52-
iconUrl: chrome.runtime.getURL("assets/logo.png"),
53-
});
54-
}
55-
5647
export function valueType(val: unknown) {
5748
switch (typeof val) {
5849
case "string":

0 commit comments

Comments
 (0)