update: toolkit 0.1.3
This commit is contained in:
parent
5d3cde376d
commit
6a986305a4
@ -31,7 +31,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/windingwind/zotero-addon-template#readme",
|
||||
"dependencies": {
|
||||
"zotero-plugin-toolkit": "^0.1.1"
|
||||
"zotero-plugin-toolkit": "^0.1.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^18.11.17",
|
||||
|
@ -1,5 +1,4 @@
|
||||
import { BasicExampleFactory, UIExampleFactory } from "./modules/examples";
|
||||
import { PopupWindow } from "./modules/popup";
|
||||
import { config } from "../package.json";
|
||||
import { getString, initLocale } from "./modules/locale";
|
||||
import { registerPrefsScripts } from "./modules/preferenceScript";
|
||||
@ -11,8 +10,12 @@ async function onStartup() {
|
||||
Zotero.uiReadyPromise,
|
||||
]);
|
||||
initLocale();
|
||||
ztoolkit.Tool.setIconURI(
|
||||
"default",
|
||||
`chrome://${config.addonRef}/content/icons/favicon.png`
|
||||
);
|
||||
|
||||
const popupWin = new PopupWindow(config.addonName, {
|
||||
const popupWin = ztoolkit.Tool.createProgressWindow(config.addonName, {
|
||||
closeOnClick: true,
|
||||
closeTime: -1,
|
||||
})
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { config } from "../../package.json";
|
||||
import { getString } from "./locale";
|
||||
import { PopupWindow } from "./popup";
|
||||
|
||||
function example(
|
||||
target: any,
|
||||
@ -62,7 +61,7 @@ export class BasicExampleFactory {
|
||||
|
||||
@example
|
||||
static exampleNotifierCallback() {
|
||||
new PopupWindow(config.addonName)
|
||||
ztoolkit.Tool.createProgressWindow(config.addonName)
|
||||
.createLine({
|
||||
text: "Open Tab Detected!",
|
||||
type: "success",
|
||||
|
@ -1,87 +0,0 @@
|
||||
import { config } from "../../package.json";
|
||||
|
||||
const progressWindowIcon = {
|
||||
success: "chrome://zotero/skin/tick.png",
|
||||
fail: "chrome://zotero/skin/cross.png",
|
||||
default: `chrome://${config.addonRef}/content/icons/favicon.png`,
|
||||
};
|
||||
|
||||
interface LineOptions {
|
||||
type?: keyof typeof progressWindowIcon;
|
||||
icon?: string;
|
||||
text?: string;
|
||||
progress?: number;
|
||||
idx?: number;
|
||||
}
|
||||
|
||||
export class PopupWindow extends Zotero.ProgressWindow {
|
||||
private lines: _ZoteroItemProgress[];
|
||||
private closeTime: number | undefined;
|
||||
private originalShow: typeof Zotero.ProgressWindow.prototype.show;
|
||||
// @ts-ignore
|
||||
public show!: typeof this.showWithTimer;
|
||||
|
||||
constructor(
|
||||
header: string,
|
||||
options: {
|
||||
window?: Window;
|
||||
closeOnClick?: boolean;
|
||||
closeTime?: number;
|
||||
} = {
|
||||
closeOnClick: true,
|
||||
closeTime: 5000,
|
||||
}
|
||||
) {
|
||||
super(options);
|
||||
this.lines = [];
|
||||
this.closeTime = options.closeTime || 5000;
|
||||
this.changeHeadline(header);
|
||||
this.originalShow = this
|
||||
.show as unknown as typeof Zotero.ProgressWindow.prototype.show;
|
||||
this.show = this.showWithTimer;
|
||||
}
|
||||
|
||||
createLine(options: LineOptions) {
|
||||
const icon = this.getIcon(options.type, options.icon);
|
||||
const line = new this.ItemProgress(icon || "", options.text || "");
|
||||
if (typeof options.progress === "number") {
|
||||
line.setProgress(options.progress);
|
||||
}
|
||||
this.lines.push(line);
|
||||
return this;
|
||||
}
|
||||
|
||||
changeLine(options: LineOptions) {
|
||||
if (this.lines?.length === 0) {
|
||||
return this;
|
||||
}
|
||||
const idx =
|
||||
typeof options.idx !== "undefined" &&
|
||||
options.idx >= 0 &&
|
||||
options.idx < this.lines.length
|
||||
? options.idx
|
||||
: 0;
|
||||
const icon = this.getIcon(options.type, options.icon);
|
||||
options.text && this.lines[idx].setText(options.text);
|
||||
icon && this.lines[idx].setIcon(icon);
|
||||
typeof options.progress === "number" &&
|
||||
this.lines[idx].setProgress(options.progress);
|
||||
return this;
|
||||
}
|
||||
|
||||
protected showWithTimer(closeTime: number | undefined = undefined) {
|
||||
this.originalShow();
|
||||
typeof closeTime !== "undefined" && (this.closeTime = closeTime);
|
||||
if (this.closeTime && this.closeTime > 0) {
|
||||
this.startCloseTimer(this.closeTime);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
protected getIcon(
|
||||
type: keyof typeof progressWindowIcon | undefined,
|
||||
defaulIcon?: string | undefined
|
||||
) {
|
||||
return type ? progressWindowIcon[type] : defaulIcon;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user