Skip to content

Commit 5de0970

Browse files
启动时自动检查扩展更新;更新翻译
1 parent 9d8d1ac commit 5de0970

File tree

8 files changed

+242
-117
lines changed

8 files changed

+242
-117
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# 更新日志
22

3+
## 1.3.0
4+
5+
- 启动时自动检查扩展更新
6+
- 更新翻译 (#184#185#186)
7+
38
## 1.2.13
49

510
- 更新翻译 (#180)

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ehsyringe",
33
"displayName": "EhSyringe",
4-
"version": "1.2.13",
4+
"version": "1.3.0",
55
"description": "E 站注射器,将中文翻译注入到 E 站体内。",
66
"author": "EhTagTranslation",
77
"main": "syringe.js",

src/assets/logo-padding.svg

+22
Loading

src/assets/tag.db

22.2 KB
Binary file not shown.

src/background/extension-updater.ts

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { browser } from 'webextension-polyfill-ts';
2+
import { logger } from '../tool/log';
3+
4+
async function main(): Promise<void> {
5+
const info = await browser.management.getSelf();
6+
const response = await fetch('https://api.github.com/repos/EhTagTranslation/EhSyringe/releases/latest', {
7+
headers: {
8+
accept: 'application/json',
9+
},
10+
});
11+
const payload = (await response.json()) as { tag_name: string; html_url: string };
12+
const current = `v${info.version}`;
13+
const latest = payload.tag_name;
14+
logger.log('检查插件更新', { current, latest });
15+
if (latest !== current) {
16+
const id = await browser.notifications.create({
17+
type: 'basic',
18+
title: info.name,
19+
message: `发现新的版本 ${latest},点击跳转到下载页面。`,
20+
iconUrl: '../assets/logo-padding.svg',
21+
});
22+
browser.notifications.onClicked.addListener((cid) => {
23+
if (cid === id) {
24+
chrome.tabs.create({
25+
url: payload.html_url,
26+
});
27+
}
28+
});
29+
}
30+
}
31+
32+
export const result = main();

src/background/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class Background {
1212
readonly contextMenu: typeof contextMenu = require('./context-menu').contextMenu;
1313
readonly omnibox: typeof omnibox = require('./omnibox').omnibox;
1414
readonly tagDatabase: typeof tagDatabase = require('./tag-database').tagDatabase;
15+
readonly extensionUpdate = require('./extension-updater');
1516
}
1617

1718
function getBackground(): Background {

src/background/tag-database.ts

+2-9
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,7 @@ class TagDatabase {
5353
'sha',
5454
'dataStructureVersion',
5555
]);
56-
if (
57-
dataStructureVersion !== DATA_STRUCTURE_VERSION ||
58-
!tagList ||
59-
!tagReplace ||
60-
!releaseLink ||
61-
!sha ||
62-
!updateTime
63-
) {
56+
if (dataStructureVersion !== DATA_STRUCTURE_VERSION || !tagList || !tagReplace || !releaseLink || !sha) {
6457
const timer = logger.time('数据结构变化, 重新构建数据');
6558
await this.updateUseLocal();
6659
timer.end();
@@ -130,7 +123,7 @@ class TagDatabase {
130123
tagReplace,
131124
releaseLink,
132125
sha,
133-
updateTime: updateTime.getTime() || undefined,
126+
updateTime: updateTime.getTime() ?? undefined,
134127
dataStructureVersion: DATA_STRUCTURE_VERSION,
135128
})
136129
.catch(logger.error);

0 commit comments

Comments
 (0)