add: system Notification
This commit is contained in:
parent
329e6dab88
commit
25befec9c6
@ -1,6 +1,7 @@
|
|||||||
import { BasicExampleFactory, UIExampleFactory } from "./modules/examples";
|
import { BasicExampleFactory, UIExampleFactory } from "./modules/examples";
|
||||||
import {
|
import {
|
||||||
changeProgressWindowLine,
|
changeProgressWindowLine,
|
||||||
|
isProgressWindow,
|
||||||
showProgressWindow,
|
showProgressWindow,
|
||||||
} from "./modules/progressWindow";
|
} from "./modules/progressWindow";
|
||||||
import { config } from "../package.json";
|
import { config } from "../package.json";
|
||||||
@ -14,7 +15,9 @@ async function onStartup() {
|
|||||||
config.addonName,
|
config.addonName,
|
||||||
getString("startup.begin"),
|
getString("startup.begin"),
|
||||||
"default",
|
"default",
|
||||||
-1
|
{
|
||||||
|
closeTime: -1,
|
||||||
|
}
|
||||||
);
|
);
|
||||||
changeProgressWindowLine(progWin, { newProgress: 0 });
|
changeProgressWindowLine(progWin, { newProgress: 0 });
|
||||||
|
|
||||||
@ -51,7 +54,9 @@ async function onStartup() {
|
|||||||
newProgress: 100,
|
newProgress: 100,
|
||||||
newText: `[100%] ${getString("startup.finish")}`,
|
newText: `[100%] ${getString("startup.finish")}`,
|
||||||
});
|
});
|
||||||
progWin.startCloseTimer(5000);
|
if (isProgressWindow(progWin)) {
|
||||||
|
(progWin as _ZoteroProgressWindow).startCloseTimer(5000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onShutdown(): void {
|
function onShutdown(): void {
|
||||||
|
@ -10,33 +10,61 @@ export function showProgressWindow(
|
|||||||
header: string,
|
header: string,
|
||||||
context: string,
|
context: string,
|
||||||
type: "success" | "fail" | "default" = "default",
|
type: "success" | "fail" | "default" = "default",
|
||||||
t: number = 5000
|
options: {
|
||||||
): _ZoteroProgressWindow {
|
closeTime?: number;
|
||||||
// A simple wrapper of the Zotero ProgressWindow
|
backend?: "Zotero" | "system";
|
||||||
let progressWindow = new Zotero.ProgressWindow({
|
} = {
|
||||||
closeOnClick: true,
|
closeTime: 5000,
|
||||||
}) as _ZoteroProgressWindow;
|
backend: "Zotero",
|
||||||
progressWindow.changeHeadline(header);
|
}
|
||||||
// @ts-ignore
|
): _ZoteroProgressWindow | Notification {
|
||||||
progressWindow.progress = new progressWindow.ItemProgress(
|
// Currently Zotero 7 doesn't support progress window.
|
||||||
progressWindowIcon[type],
|
// Use system backend on Zotero 7.
|
||||||
context
|
if (options.backend === "system" || ztoolkit.Compat.isZotero7()) {
|
||||||
);
|
Zotero.Prefs.set("alerts.useSystemBackend", true, true);
|
||||||
progressWindow.show();
|
const notification = new (ztoolkit.Compat.getGlobal(
|
||||||
if (t > 0) {
|
"Notification"
|
||||||
progressWindow.startCloseTimer(t);
|
) as typeof Notification)(header, {
|
||||||
|
body: context,
|
||||||
|
icon: progressWindowIcon[type],
|
||||||
|
tag: config.addonName,
|
||||||
|
});
|
||||||
|
if (options.closeTime) {
|
||||||
|
(ztoolkit.Compat.getGlobal("setTimeout") as typeof setTimeout)(() => {
|
||||||
|
notification.close();
|
||||||
|
}, options.closeTime);
|
||||||
|
}
|
||||||
|
return notification;
|
||||||
|
} else {
|
||||||
|
// A simple wrapper of the Zotero ProgressWindow
|
||||||
|
const progressWindow = new Zotero.ProgressWindow({
|
||||||
|
closeOnClick: true,
|
||||||
|
}) as _ZoteroProgressWindow;
|
||||||
|
progressWindow.changeHeadline(header);
|
||||||
|
// @ts-ignore
|
||||||
|
progressWindow.progress = new progressWindow.ItemProgress(
|
||||||
|
progressWindowIcon[type],
|
||||||
|
context
|
||||||
|
);
|
||||||
|
progressWindow.show();
|
||||||
|
if (options.closeTime) {
|
||||||
|
progressWindow.startCloseTimer(options.closeTime);
|
||||||
|
}
|
||||||
|
return progressWindow;
|
||||||
}
|
}
|
||||||
return progressWindow;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function changeProgressWindowLine(
|
export function changeProgressWindowLine(
|
||||||
progressWindow: _ZoteroProgressWindow,
|
progressWindow: _ZoteroProgressWindow | Notification,
|
||||||
options: {
|
options: {
|
||||||
newText?: string;
|
newText?: string;
|
||||||
newIcon?: string;
|
newIcon?: string;
|
||||||
newProgress?: number;
|
newProgress?: number;
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
|
if (!isProgressWindow(progressWindow)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const progress = progressWindow.progress as _ZoteroItemProgress;
|
const progress = progressWindow.progress as _ZoteroItemProgress;
|
||||||
if (!progress) {
|
if (!progress) {
|
||||||
@ -46,3 +74,9 @@ export function changeProgressWindowLine(
|
|||||||
options.newIcon && progress.setIcon(options.newIcon);
|
options.newIcon && progress.setIcon(options.newIcon);
|
||||||
options.newProgress && progress.setProgress(options.newProgress);
|
options.newProgress && progress.setProgress(options.newProgress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isProgressWindow(
|
||||||
|
progressWindow: _ZoteroProgressWindow | Notification
|
||||||
|
) {
|
||||||
|
return !(progressWindow as Notification).title;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user