Skip to content

Commit

Permalink
🏷️ update types
Browse files Browse the repository at this point in the history
  • Loading branch information
volatile-static committed Sep 26, 2024
1 parent 5702b59 commit 8241d9b
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 18 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"unplugin-vue-components": "^0.27.4",
"vite": "^5.4.6",
"vue-tsc": "^2.0.29",
"zotero-types": "^2.1.1"
"zotero-types": "^2.2.0"
},
"eslintConfig": {
"extends": [
Expand Down
5 changes: 3 additions & 2 deletions src/bootstrap/addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { config, name as packageName } from '../../package.json';
import ReadingHistory from './modules/history/history';
import { onAddonLoad, onHistoryRecord, onItemSelect, onMainWindowLoad } from './events';
import { showMessage, WorkerManager } from './modules/utils';
import { G } from './modules/global';

type DefaultPrefs = Omit<
typeof config.defaultSettings,
Expand Down Expand Up @@ -148,7 +149,7 @@ export default class Addon extends BasicTool {
/**
* 初始化插件时调用
*/
init(win?: MainWindow) {
init(win?: _ZoteroTypes.MainWindow) {
try {
if (win) {
onMainWindowLoad(win);
Expand All @@ -163,7 +164,7 @@ export default class Addon extends BasicTool {

async unload() {
this.patchSearch.disable();
this.overviewTabID && (window as unknown as MainWindow).Zotero_Tabs.close(this.overviewTabID);
this.overviewTabID && G('Zotero_Tabs').close(this.overviewTabID);
this.notifierID && Zotero.Notifier.unregisterObserver(this.notifierID);
this.prefsObserverIDs.forEach(id => Zotero.Prefs.unregisterObserver(id));
this.listeners.forEach(({ target, type, listener }) =>
Expand Down
6 changes: 3 additions & 3 deletions src/bootstrap/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function onAddonLoad() {
Zotero.Server.Endpoints['/test/chartero'] = DebuggerBackend;
}

export function onMainWindowLoad(win: MainWindow) {
export function onMainWindowLoad(win: _ZoteroTypes.MainWindow) {
addon.registerListener(
win.document.getElementById('zotero-itemmenu')!,
'popupshowing',
Expand Down Expand Up @@ -106,7 +106,7 @@ export function openReport() {
}

export function openOverview() {
const Zotero_Tabs = (Zotero.getMainWindow() as unknown as MainWindow).Zotero_Tabs;
const Zotero_Tabs = Zotero.getMainWindow().Zotero_Tabs;
if (addon.overviewTabID) {
Zotero_Tabs.select(addon.overviewTabID);
return;
Expand Down Expand Up @@ -144,7 +144,7 @@ export function onHistoryRecord(reader: _ZoteroTypes.ReaderInstance) {

export async function onItemSelect() {
// 仅用户操作GUI时响应
if ((Zotero.getMainWindow() as unknown as MainWindow).Zotero_Tabs.selectedType != 'library') return;
if (Zotero.getMainWindow().Zotero_Tabs.selectedType != 'library') return;
const ZoteroPane = Zotero.getActiveZoteroPane(),
items = ZoteroPane.getSelectedItems(true),
dashboard = Zotero.getMainWindow().document.querySelector(
Expand Down
6 changes: 0 additions & 6 deletions src/bootstrap/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@ declare const rootURI: string;
declare const __dev__: boolean;

declare type ReactDOM = typeof import('react-dom');
declare class ChromeWorker extends Worker { }
declare module '*.sass';
declare module '*.svg';

declare type MaybeArray<T> = T | T[];

declare interface MainWindow extends Window {
Zotero_Tabs: typeof Zotero_Tabs;
ZoteroPane_Local: typeof ZoteroPane;
}
4 changes: 2 additions & 2 deletions src/bootstrap/modules/recent.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ICON_URL } from './utils';

export default function (win: MainWindow) {
export default function (win: _ZoteroTypes.MainWindow) {
// 注册“最近在读”菜单
addon.menu.register(
'menuFile',
Expand Down Expand Up @@ -40,7 +40,7 @@ export default function (win: MainWindow) {
}

async function addRecentTabsMenu({ target }: Event) {
const win = (target as any).ownerGlobal as MainWindow,
const win = (target as any).ownerGlobal as _ZoteroTypes.MainWindow,
openedItems = win.Zotero_Tabs.getState().map(tab => tab.data?.itemID).filter(i => !!i),
regex = new RegExp(`(${Zotero.Utilities.quotemeta(win.Zotero_Tabs._tabsMenuFilter)})`, 'gi');
let tabIndex = win.Zotero_Tabs.tabsMenuList.querySelectorAll('*[tabindex]').length;
Expand Down

0 comments on commit 8241d9b

Please sign in to comment.