Skip to content

Commit

Permalink
fix: alert blocking thread
Browse files Browse the repository at this point in the history
  • Loading branch information
northword committed Jan 29, 2024
1 parent cdc14a6 commit b4ab17d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- 修复网页条目导入时警告窗阻塞线程导致附件存储失败的问题。[#102](https://github.com/northword/zotero-format-metadata/issues/102#issuecomment-1914045722)

## [1.11.0] - 2024-01-27

### Added
Expand Down
19 changes: 9 additions & 10 deletions src/modules/rules/no-webpage-item.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { progressWindow } from "../../utils/logger";
import { RuleBase, RuleBaseOptions } from "../../utils/rule-base";
import { isStringMatchStringInArray } from "../../utils/str";

Expand Down Expand Up @@ -98,17 +99,15 @@ export default class NoWebPageItem extends RuleBase<NoWebPageItemOptions> {
apply(item: Zotero.Item): Zotero.Item | Promise<Zotero.Item> {
if (item.itemType !== "webpage") return item;
const url = item.getField("url");
if (typeof url == "string" && url !== "") {
if (isStringMatchStringInArray(url, publisherUrlKeyWords)) {
ztoolkit.log("The url of this webpage item is match with domin of publisher.");
// show alart todo: 对话框完善,通过 URL 获取 DOI 并通过 DOI 强制更新条目类别
window.alert(
"Linter for Zotero \n监测到您导入了一个 WebPage 条目,其 URL 中包含了主要学术出版商的域名,\n导入可能存在异常,请确认!",
);
} else {
ztoolkit.log(`The url of this webpage item is not belong to publisher, maybe a normal webpage.`);
}
if (typeof url == "string" && url !== "" && isStringMatchStringInArray(url, publisherUrlKeyWords)) {
ztoolkit.log("The url of this webpage item is match with domin of publisher.");
// show alart todo: 对话框完善,通过 URL 获取 DOI 并通过 DOI 强制更新条目类别
progressWindow(
"监测到您导入了一个 WebPage 条目,其 URL 中包含了主要学术出版商的域名,\n导入可能存在异常,请确认!",
"fail",
).startCloseTimer(10000);
}
ztoolkit.log(`The url of this webpage item is not belong to publisher, maybe a normal webpage.`);
return item;
}
}
2 changes: 1 addition & 1 deletion src/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function callingLoggerForMethod(target: any, propertyKey: string | symbol
// }

export function progressWindow(text: string, type = "default", progress = 100) {
new ztoolkit.ProgressWindow(config.addonName, {
return new ztoolkit.ProgressWindow(config.addonName, {
closeOnClick: true,
})
.createLine({
Expand Down

0 comments on commit b4ab17d

Please sign in to comment.