Skip to content

Commit 40f13b9

Browse files
committed
fix: chrome notifications not working
- when using fixed notificationId - it works on firefox
1 parent eda0d48 commit 40f13b9

File tree

10 files changed

+16
-31
lines changed

10 files changed

+16
-31
lines changed

src/scripts/background.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import "./background/weibo-referer.js";
1717
import { Log } from "./background/log.js";
1818
import { Utils } from "./sharre/utils.js";
1919
import { GUID } from "./background/guid.js";
20-
import { NID_MISMATCH_CORS } from "./sharre/constant.js";
2120

2221
chrome.runtime.onMessage.addListener((message: ServiceWorkerMessage, sender, sendResponse) => {
2322
if (!message) return;
@@ -32,7 +31,7 @@ chrome.runtime.onMessage.addListener((message: ServiceWorkerMessage, sender, sen
3231
break;
3332
}
3433
case "WithoutCorsMode": {
35-
Utils.notify(NID_MISMATCH_CORS, {
34+
Utils.notify({
3635
title: chrome.i18n.getMessage("warn_title"),
3736
message: "当前资源的网络请求不符合 CORS 规范,无法读取资源的数据",
3837
});

src/scripts/background/context-menu.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,7 @@
44
* found in the LICENSE file.
55
*/
66

7-
import {
8-
M_UPLOAD_FRAME,
9-
M_BATCH_DELETE,
10-
M_UPLOAD_IMAGE,
11-
M_OPEN_HISTORY,
12-
M_DOWNLOAD_LOG,
13-
NID_COPY_URL_FAIL,
14-
} from "../sharre/constant.js";
7+
import { M_UPLOAD_FRAME, M_BATCH_DELETE, M_UPLOAD_IMAGE, M_OPEN_HISTORY, M_DOWNLOAD_LOG } from "../sharre/constant.js";
158
import { Utils } from "../sharre/utils.js";
169
import { Base64 } from "../sharre/base64.js";
1710
import { PConfig } from "../sharre/constant.js";
@@ -102,7 +95,7 @@ chrome.contextMenus.onClicked.addListener((info, tab) => {
10295
},
10396
(response) => {
10497
if (response && response.valid && !response.done) {
105-
Utils.notify(NID_COPY_URL_FAIL, { message: "操作失败:链接没有复制到剪切板中(lll¬ω¬)" });
98+
Utils.notify({ message: "操作失败:链接没有复制到剪切板中(lll¬ω¬)" });
10699
}
107100
},
108101
);

src/scripts/background/events-handler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import { NID_REMAIN_LOGOUT } from "../sharre/constant.js";
88

99
chrome.notifications.onClicked.addListener((notificationId) => {
10-
if (notificationId === NID_REMAIN_LOGOUT) {
10+
if (notificationId.startsWith(NID_REMAIN_LOGOUT)) {
1111
const url = `https://weibo.com/login.php?url=${encodeURIComponent("https://weibo.com")}`;
12-
chrome.tabs.create({ url }, (tab) => chrome.notifications.clear(NID_REMAIN_LOGOUT));
12+
chrome.tabs.create({ url }, (tab) => chrome.notifications.clear(notificationId));
1313
}
1414
});
1515

src/scripts/history/dispatcher.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export class Dispatcher {
2424
locked: boolean;
2525
platformOs: chrome.runtime.PlatformOs;
2626
maxSelected: number;
27-
nid: string;
2827
head: HTMLElement;
2928
main: HTMLElement;
3029
foot: HTMLElement;
@@ -54,7 +53,6 @@ export class Dispatcher {
5453
this.locked = false;
5554
this.platformOs = null;
5655
this.maxSelected = 50;
57-
this.nid = Utils.randomString(16);
5856
this.head = document.querySelector("#head");
5957
this.main = document.querySelector("#main");
6058
this.foot = document.querySelector("#foot");
@@ -300,7 +298,7 @@ export class Dispatcher {
300298
this.selected.add(section);
301299
section.dataset.selected = "true";
302300
} else {
303-
Utils.notify(this.nid, { message: `选择失败:最多同时选中${this.maxSelected}个元素` });
301+
Utils.notify({ message: `选择失败:最多同时选中${this.maxSelected}个元素` });
304302
}
305303
}
306304
} else {
@@ -358,7 +356,7 @@ export class Dispatcher {
358356
this.availableChecker();
359357
})
360358
.catch((reason) => {
361-
Utils.notify(this.nid, { message: "操作失败:移除文件没有成功哈~" });
359+
Utils.notify({ message: "操作失败:移除文件没有成功哈~" });
362360
});
363361
}
364362

src/scripts/popup/dispatcher.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export class Dispatcher {
2929
copier: HTMLTextAreaElement;
3030
linker: HTMLInputElement;
3131
checkout: { clear: boolean };
32-
nid: string;
3332
directorySymbol: string;
3433
classifyMap: Map<Blob, string>;
3534
preStoreMap: Map<string, IPreStore[]>;
@@ -43,7 +42,6 @@ export class Dispatcher {
4342
this.copier = document.querySelector("#transfer-to-clipboard");
4443
this.linker = document.querySelector("input.custom-clip");
4544
this.checkout = { clear: true };
46-
this.nid = Utils.randomString(16);
4745
this.directorySymbol = "\ud83d\udcc1";
4846
this.classifyMap = new Map();
4947
this.preStoreMap = new Map();
@@ -186,7 +184,7 @@ export class Dispatcher {
186184
{ duration: 500, easing: "ease", fill: "backwards" },
187185
);
188186
} else {
189-
chrome.notifications.create(this.nid, {
187+
chrome.notifications.create({
190188
type: "basic",
191189
iconUrl: chrome.i18n.getMessage("notify_icon"),
192190
title: chrome.i18n.getMessage("warn_title"),

src/scripts/sharre/fetch-blob.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
import { Utils } from "./utils.js";
8-
import { FP_TYPE_DOWNLOAD, NID_GRAB_RESOURCE } from "./constant.js";
8+
import { FP_TYPE_DOWNLOAD } from "./constant.js";
99
import { Isomorphic } from "./isomorphic.js";
1010
import { FileProgress } from "./file-progress.js";
1111

@@ -31,8 +31,8 @@ export async function fetchBlob(srcUrl: string, pageUrl?: string, _replay = fals
3131
progress.padding(1);
3232

3333
if (granted && !_replay && Utils.isValidURL(srcUrl) && Utils.isValidURL(pageUrl)) {
34-
const DNR_MODIFY_HEADERS = 'modifyHeaders' as chrome.declarativeNetRequest.RuleActionType.MODIFY_HEADERS;
35-
const DNR_SET = 'set' as chrome.declarativeNetRequest.HeaderOperation.SET;
34+
const DNR_MODIFY_HEADERS = "modifyHeaders" as chrome.declarativeNetRequest.RuleActionType.MODIFY_HEADERS;
35+
const DNR_SET = "set" as chrome.declarativeNetRequest.HeaderOperation.SET;
3636
const hostname = new URL(location.href).hostname;
3737
await chrome.declarativeNetRequest.updateSessionRules({
3838
addRules: [
@@ -77,7 +77,7 @@ export async function fetchBlob(srcUrl: string, pageUrl?: string, _replay = fals
7777

7878
if (notGranted || grantedAndReplayError) {
7979
progress.failure();
80-
Utils.notify(NID_GRAB_RESOURCE, {
80+
Utils.notify({
8181
title: chrome.i18n.getMessage("warn_title"),
8282
message: "无法读取远程文件,请开启选项中的伪造 HTTP Referer 功能",
8383
});

src/scripts/sharre/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ export class Utils {
481481
static notify(arg1: any, arg2?: any, arg3?: any): void {
482482
if (typeof arg1 === "string") {
483483
return chrome.notifications.create(
484-
arg1,
484+
arg1 + "@" + crypto.randomUUID(),
485485
Object.assign(
486486
{
487487
type: "basic",

src/scripts/sharre/weibo-action.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
E_FILE_TYPE_RESTRICT,
1212
FP_TYPE_UPLOAD,
1313
K_WEIBO_INHERITED_WATERMARK,
14-
NID_UPLOAD_RESULT,
1514
} from "./constant.js";
1615

1716
import { requestUpload } from "../weibo/upload.js";
@@ -147,7 +146,7 @@ export class WeiboUpload {
147146
if (this.isNotify) {
148147
const { succeed, failure, discard } = await this.progress.getPrevInfo();
149148
if (failure || discard) {
150-
chrome.notifications.create(NID_UPLOAD_RESULT, {
149+
chrome.notifications.create({
151150
type: "basic",
152151
iconUrl: chrome.i18n.getMessage("notify_icon"),
153152
title: chrome.i18n.getMessage("warn_title"),

src/scripts/weibo/author.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
E_MISS_WEIBO_ACCOUNT,
1313
E_WEIBO_USER_ID_SLIP,
1414
K_WEIBO_ACCOUNT_DETAILS,
15-
NID_LOGIN_RESULT,
1615
NID_REMAIN_LOGOUT,
1716
} from "../sharre/constant.js";
1817
import { tryActivateUserStatus } from "./activator.js";
@@ -81,7 +80,7 @@ async function setUserStatus(notify: boolean): Promise<WB.LoginInfo> {
8180
return signInByUserAccount(accountInfo.username, accountInfo.password)
8281
.catch((reason) => {
8382
notify &&
84-
Utils.notify(NID_LOGIN_RESULT, {
83+
Utils.notify({
8584
title: chrome.i18n.getMessage("fail_title"),
8685
message: "登录失败,请检查微博账户信息及网络情况",
8786
});

src/scripts/weibo/upload.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
E_FILE_SIZE_RESTRICT,
1515
E_FILE_SIZE_OVERFLOW,
1616
UNKNOWN_FILE_SIZE_RESTRICT,
17-
NID_LOGIN_RESULT,
1817
} from "../sharre/constant.js";
1918
import { attachPhotoToSpecialAlbum } from "./photo.js";
2019
import { requestSignIn } from "./author.js";
@@ -135,7 +134,7 @@ async function uploader(item: WB.PackedItem, watermark?: WB.Watermark, _replay =
135134
return requestSignIn(true)
136135
.catch((reason) => {
137136
reason.login &&
138-
Utils.notify(NID_LOGIN_RESULT, {
137+
Utils.notify({
139138
title: chrome.i18n.getMessage("fail_title"),
140139
message: "微博登录信息校验成功,可是。。。图片上传失败了呢",
141140
});

0 commit comments

Comments
 (0)