-
Notifications
You must be signed in to change notification settings - Fork 119
/
Copy pathhooks.ts
180 lines (151 loc) · 4.29 KB
/
hooks.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import {
BasicExampleFactory,
HelperExampleFactory,
KeyExampleFactory,
PromptExampleFactory,
UIExampleFactory,
} from "./modules/examples";
import { config } from "../package.json";
import { getString, initLocale } from "./utils/locale";
import { registerPrefsScripts } from "./modules/preferenceScript";
async function onStartup() {
await Promise.all([
Zotero.initializationPromise,
Zotero.unlockPromise,
Zotero.uiReadyPromise,
]);
initLocale();
ztoolkit.ProgressWindow.setIconURI(
"default",
`chrome://${config.addonRef}/content/icons/favicon.png`
);
const popupWin = new ztoolkit.ProgressWindow(config.addonName, {
closeOnClick: true,
closeTime: -1,
})
.createLine({
text: getString("startup.begin"),
type: "default",
progress: 0,
})
.show();
BasicExampleFactory.registerPrefs();
BasicExampleFactory.registerNotifier();
KeyExampleFactory.registerShortcuts();
await Zotero.Promise.delay(1000);
popupWin.changeLine({
progress: 30,
text: `[30%] ${getString("startup.begin")}`,
});
UIExampleFactory.registerStyleSheet();
UIExampleFactory.registerRightClickMenuItem();
UIExampleFactory.registerRightClickMenuPopup();
UIExampleFactory.registerWindowMenuWithSeparator();
await UIExampleFactory.registerExtraColumn();
await UIExampleFactory.registerExtraColumnWithCustomCell();
await UIExampleFactory.registerCustomCellRenderer();
await UIExampleFactory.registerCustomItemBoxRow();
UIExampleFactory.registerLibraryTabPanel();
await UIExampleFactory.registerReaderTabPanel();
PromptExampleFactory.registerNormalCommandExample();
PromptExampleFactory.registerAnonymousCommandExample();
PromptExampleFactory.registerConditionalCommandExample();
await Zotero.Promise.delay(1000);
popupWin.changeLine({
progress: 100,
text: `[100%] ${getString("startup.finish")}`,
});
popupWin.startCloseTimer(5000);
addon.hooks.onDialogEvents("dialogExample");
}
function onShutdown(): void {
ztoolkit.unregisterAll();
addon.data.dialog?.window?.close();
// Remove addon object
addon.data.alive = false;
delete Zotero[config.addonInstance];
}
/**
* This function is just an example of dispatcher for Notify events.
* Any operations should be placed in a function to keep this funcion clear.
*/
async function onNotify(
event: string,
type: string,
ids: Array<string | number>,
extraData: { [key: string]: any }
) {
// You can add your code to the corresponding notify type
ztoolkit.log("notify", event, type, ids, extraData);
if (
event == "select" &&
type == "tab" &&
extraData[ids[0]].type == "reader"
) {
BasicExampleFactory.exampleNotifierCallback();
} else {
return;
}
}
/**
* This function is just an example of dispatcher for Preference UI events.
* Any operations should be placed in a function to keep this funcion clear.
* @param type event type
* @param data event data
*/
async function onPrefsEvent(type: string, data: { [key: string]: any }) {
switch (type) {
case "load":
registerPrefsScripts(data.window);
break;
default:
return;
}
}
function onShortcuts(type: string) {
switch (type) {
case "larger":
KeyExampleFactory.exampleShortcutLargerCallback();
break;
case "smaller":
KeyExampleFactory.exampleShortcutSmallerCallback();
break;
case "confliction":
KeyExampleFactory.exampleShortcutConflictingCallback();
break;
default:
break;
}
}
function onDialogEvents(type: string) {
switch (type) {
case "dialogExample":
HelperExampleFactory.dialogExample();
break;
case "clipboardExample":
HelperExampleFactory.clipboardExample();
break;
case "filePickerExample":
HelperExampleFactory.filePickerExample();
break;
case "progressWindowExample":
HelperExampleFactory.progressWindowExample();
break;
case "vtableExample":
HelperExampleFactory.vtableExample();
break;
default:
break;
}
}
// Add your hooks here. For element click, etc.
// Keep in mind hooks only do dispatch. Don't add code that does real jobs in hooks.
// Otherwise the code would be hard to read and maintian.
export default {
onStartup,
onShutdown,
onNotify,
onPrefsEvent,
onShortcuts,
onDialogEvents,
};