Skip to content

Commit

Permalink
fix: 部分用户刷新转换器异常,强制添加一个更新地址
Browse files Browse the repository at this point in the history
  • Loading branch information
l0o0 committed Sep 7, 2023
1 parent 46c47ba commit e19b4f5
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
40 changes: 40 additions & 0 deletions src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { config } from "../package.json";
import { getString, initLocale } from "./utils/locale";
import { registerPrefsScripts } from "./modules/preferenceScript";
import { displayMenuitem } from "../src/modules/ui";
import { showPop } from "./utils/window";

async function onStartup() {
await Promise.all([
Expand All @@ -20,6 +21,23 @@ async function onStartup() {
`chrome://${config.addonRef}/content/icons/icon.png`
);

const popupWin = new ztoolkit.ProgressWindow(config.addonName, {
closeOnClick: true,
closeTime: -1,
})
.createLine({
text: "startup-begin",
type: "default",
progress: 0,
})
.show();

popupWin.changeLine({
progress: 30,
text: `[30%] startup-begin`,
});


BasicExampleFactory.registerPrefs();

BasicExampleFactory.registerNotifier();
Expand Down Expand Up @@ -48,6 +66,9 @@ async function onStartup() {
displayMenuitem,
false
);

// Migrate Prefs from Zotero 6 to 7
migratePrefs();
}

function onShutdown(): void {
Expand Down Expand Up @@ -79,6 +100,25 @@ async function onNotify(
}
}


// Run this when addon is first run
// Keep preferences startswith extensions.zotero.jasminum
function migratePrefs() {
ztoolkit.log("start to migrate");
if ( Zotero.Prefs.get("jasminum.firstrun") != false ) {
const extensionBranch = Services.prefs.getBranch("extensions");
const prefs = extensionBranch.getChildList("", {});
const jasminmPrefs = prefs.filter((p: string) => p.includes(".jasminum."))
const shortJasminumPrefs = jasminmPrefs.filter( (p: string) => p.startsWith(".jasminum."));
shortJasminumPrefs.array.forEach((ele: string) => {
ztoolkit.log("extensions" + ele);
Zotero.Prefs.clear("extensions" + ele, true);
showPop("extensions" + ele);
});
Zotero.Prefs.set("jasminum.firstrun", false);
}
}

/**
* 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.
Expand Down
9 changes: 5 additions & 4 deletions src/modules/preferenceScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ async function insertTable(): Promise<void> {
}

async function updateTranslatorData(refresh = true): Promise<any> {
const translatorUrl = Zotero.Prefs.get("jasminum.translatorurl");
const url = translatorUrl + "/data/translators.json";
const baseUrl = Zotero.Prefs.get("jasminum.translatorurl") ? Zotero.Prefs.get("jasminum.translatorurl") : "https://oss.wwang.de/translators_CN";
const url = baseUrl + "/data/translators.json";
const cacheFile = ztoolkit.getGlobal("Zotero").getTempDirectory();
cacheFile.append("translator.json");
let contents;
Expand Down Expand Up @@ -150,8 +150,9 @@ async function downloadTranslator(filename: string): Promise<void> {
}
// var url = `https://gitee.com/l0o0/translators_CN/raw/master/translators/${label}`;
// var url = `https://gitcode.net/goonback/translators_CN/-/raw/master/translators/${label}`;
// let url = `https://oss.wwang.de/translators_CN/translators/${label}`;
const url = Zotero.Prefs.get("jasminum.translatorurl") + "/" + filename;
// let url = `https://oss.wwang.de/translators_CN/${label}`;
const baseUrl = Zotero.Prefs.get("jasminum.translatorurl") ? Zotero.Prefs.get("jasminum.translatorurl") : "https://oss.wwang.de/translators_CN";
const url = baseUrl + "/" + filename;
ztoolkit.log(url);
try {
const contents = await ztoolkit.getGlobal("Zotero").File.getContentsFromURL(url);
Expand Down

0 comments on commit e19b4f5

Please sign in to comment.