Skip to content

Commit

Permalink
修复插件间冲突
Browse files Browse the repository at this point in the history
  • Loading branch information
MuiseDestiny committed Jan 31, 2023
1 parent 3c88c3b commit 3cf3d21
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 74 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zotero-style",
"version": "2.0.6",
"version": "2.0.7",
"description": "让你的Zotero看起来更有趣",
"config": {
"addonName": "Zotero Style",
Expand Down
4 changes: 2 additions & 2 deletions src/addon.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ZoteroToolkit from "zotero-plugin-toolkit/dist"
import ZoteroToolkit from "E:/Github/zotero-plugin-toolkit/dist"
import hooks from "./hooks";

class Addon {
Expand All @@ -16,7 +16,7 @@ class Addon {
};
// Lifecycle hooks
public hooks: typeof hooks;

constructor() {
this.data = {
alive: true,
Expand Down
23 changes: 3 additions & 20 deletions src/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { BasicExampleFactory, UIExampleFactory } from "./modules/examples";
import { config } from "../package.json";
import { getString, initLocale } from "./modules/locale";
import { registerPrefsScripts } from "./modules/preferenceScript";
import Views from "./modules/views";
import Events from "./modules/events";
import AddonItem from "./modules/item";
Expand Down Expand Up @@ -64,8 +63,8 @@ async function onStartup() {
function onShutdown(): void {
ztoolkit.log("zotero style onShutdown")
ztoolkit.unregisterAll()
// ztoolkit.UI.unregisterAll()
// ztoolkit.ItemTree.unregisterAll()
ztoolkit.UI.unregisterAll()
ztoolkit.ItemTree.unregisterAll()

// Remove addon object
addon.data.alive = false;
Expand Down Expand Up @@ -103,21 +102,6 @@ async function onNotify(
}
}

/**
* 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;
}
}

// 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.
Expand All @@ -126,6 +110,5 @@ async function onPrefsEvent(type: string, data: { [key: string]: any }) {
export default {
onStartup,
onShutdown,
onNotify,
onPrefsEvent,
onNotify
};
41 changes: 0 additions & 41 deletions src/modules/preferenceScript.ts

This file was deleted.

22 changes: 15 additions & 7 deletions src/modules/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ export default class Views {
},
}
);

this.patchSetting(
key,
[
Expand Down Expand Up @@ -699,12 +700,16 @@ export default class Views {
)

// menu UI
const sign = "zoterostyle-registerSwitchColumnsViewUI"
if (ZoteroPane.itemsView[sign]) { return }
ztoolkit.patch(
ZoteroPane.itemsView,
"_displayColumnPickerMenu",
"zoterostyle-registerSwitchColumnsViewUI",
sign,
(original) =>
function() {
function () {
original.apply(ZoteroPane.itemsView, arguments);
if (!Zotero.ZoteroStyle) { return }
let sort = (columnsViews: ColumnsView[]) => {
return columnsViews.sort((a: ColumnsView, b: ColumnsView) => Number(a.position) - Number(b.position))
}
Expand Down Expand Up @@ -828,9 +833,7 @@ export default class Views {
colViewPopup.appendChild(saveMenuItem)
}
const ns = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
// @ts-ignore
original.apply(ZoteroPane.itemsView, arguments);
const menupopup = document.querySelector("#zotero-column-picker")!
const menupopup = [...document.querySelectorAll("#zotero-column-picker")].slice(-1)[0]
// 分割线
let sep = document.createElementNS(ns, "menuseparator");
menupopup.appendChild(sep);
Expand Down Expand Up @@ -895,6 +898,7 @@ export default class Views {
menupopup.appendChild(colViewPrimaryMenu)
}
)
ZoteroPane.itemsView[sign] = true
}

/**
Expand All @@ -906,15 +910,18 @@ export default class Views {
colKey: string,
args: { prefKey: string, name: string, type: string, range?: number[], values?: string[] }[]
) {
const sign = `zoterostyle-setting-${colKey}`
if (ZoteroPane.itemsView[sign]) { return }
ztoolkit.patch(
ZoteroPane.itemsView,
"_displayColumnPickerMenu",
`zoterostyle-setting-${colKey}`,
sign,
(original) =>
function () {
// @ts-ignore
original.apply(ZoteroPane.itemsView, arguments);
const menupopup = document.querySelector("#zotero-column-picker")!
if (!Zotero.ZoteroStyle) { return }
const menupopup = [...document.querySelectorAll("#zotero-column-picker")].slice(-1)[0]
let left = menupopup.getBoundingClientRect().left
let rect
try {
Expand Down Expand Up @@ -1157,6 +1164,7 @@ export default class Views {
}
}
)
ZoteroPane.itemsView[sign] = true
}

/**
Expand Down
4 changes: 2 additions & 2 deletions update.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"[email protected]": {
"updates": [
{
"version": "2.0.6",
"version": "2.0.7",
"update_link": "https://github.com/muisedestiny/zotero-style/releases/latest/download/zotero-style.xpi",
"applications": {
"gecko": {
Expand All @@ -12,7 +12,7 @@
}
},
{
"version": "2.0.6",
"version": "2.0.7",
"update_link": "https://github.com/muisedestiny/zotero-style/releases/latest/download/zotero-style.xpi",
"applications": {
"zotero": {
Expand Down
2 changes: 1 addition & 1 deletion update.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<rdf:Seq>
<rdf:li>
<rdf:Description>
<em:version>2.0.6</em:version>
<em:version>2.0.7</em:version>
<em:targetApplication>
<rdf:Description>
<em:id>[email protected]</em:id>
Expand Down

0 comments on commit 3cf3d21

Please sign in to comment.