Skip to content

Commit

Permalink
Merge pull request #269 from jiaojiaodubai/laststable
Browse files Browse the repository at this point in the history
fix: 修复转换器下载表格页面异常 fixed #267
  • Loading branch information
l0o0 committed Apr 10, 2024
2 parents 8d00c92 + 471b159 commit e0132ad
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 31 deletions.
3 changes: 0 additions & 3 deletions addon/chrome/content/prefpanel.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
height: 12px;
top: 0;
position: sticky;
background: white;
text-align: left;
z-index: 4;
}
Expand All @@ -44,8 +43,6 @@
.jasminum-tooltip-text {
position: absolute;
z-index: 2;
color: black;
background-color: white;
border: 1px solid;
border-radius: 5px;
margin: 10px 0px 10px 10px;
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ if (!basicTool.getGlobal("Zotero")[config.addonInstance]) {
_globalThis.document = basicTool.getGlobal("document");
_globalThis.addon = new Addon();
_globalThis.ztoolkit = addon.data.ztoolkit;
_globalThis.OS = basicTool.getGlobal("OS") as typeof OS;
ztoolkit.basicOptions.log.prefix = `[${config.addonName}]`;
ztoolkit.basicOptions.log.disableConsole = addon.data.env === "production";
ztoolkit.UI.basicOptions.ui.enableElementJSONLog =
Expand Down
39 changes: 12 additions & 27 deletions src/modules/preferenceScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function checkPath(pathvalue: string): Promise<void> {
let pdftk = "";
let checkResult = false;
try {
if (ztoolkit.getGlobal("Zotero").isWin) {
if (Zotero.isWin) {
pdftk = PathUtils.join(pathvalue, "pdftk.exe");
} else {
pdftk = PathUtils.join(pathvalue, "pdftk");
Expand All @@ -41,20 +41,18 @@ export async function checkPath(pathvalue: string): Promise<void> {
async function getLastUpdateFromFile(filename: string): Promise<string> {
const desPath = PathUtils.join(
PathUtils.join(
ztoolkit.getGlobal("Zotero").Prefs.get("dataDir") as string,
Zotero.Prefs.get("dataDir") as string,
"translators",
filename
)
);
Zotero.debug(desPath);
if (!(await ztoolkit.getGlobal("OS").File.exists(desPath))) {
if (!(IOUtils.exists(desPath))) {
Zotero.debug(filename + " not exists");
return "---";
}
try {
const source = (await ztoolkit
.getGlobal("Zotero")
.File.getContentsAsync(desPath)) as string;
const source = (await Zotero.File.getContentsAsync(desPath)) as string;
const infoRe = /^\s*{[\S\s]*?}\s*?[\r\n]/;
const metaData = JSON.parse(infoRe.exec(source)![0]);
return metaData.lastUpdated;
Expand Down Expand Up @@ -143,29 +141,21 @@ async function getTranslatorData(refresh = true): Promise<any> {
: "https://oss.wwang.de/translators_CN";
const url = baseUrl + "/data/translators.json";

const cacheFile = ztoolkit.getGlobal("Zotero").getTempDirectory();
const cacheFile = Zotero.getTempDirectory();
if (!cacheFile.exists()) {
// Sometimes the temp folder is missing
await ztoolkit
.getGlobal("Zotero")
.File.createDirectoryIfMissingAsync(cacheFile.path);
await Zotero.File.createDirectoryIfMissingAsync(cacheFile.path);
}
cacheFile.append("translator.json");
ztoolkit.log(cacheFile.path);
let contents;
if (refresh == false && cacheFile.exists()) {
contents = await ztoolkit
.getGlobal("Zotero")
.File.getContentsAsync(cacheFile, "utf8");
contents = await Zotero.File.getContentsAsync(cacheFile, "utf8");
return JSON.parse(contents as string);
} else {
try {
contents = await ztoolkit
.getGlobal("Zotero")
.File.getContentsFromURLAsync(url);
await ztoolkit
.getGlobal("Zotero")
.File.putContentsAsync(cacheFile, contents);
contents = await Zotero.File.getContentsFromURLAsync(url);
await Zotero.File.putContentsAsync(cacheFile, contents);
return JSON.parse(contents);
} catch (e) {
ztoolkit.log("更新转换器数据失败");
Expand Down Expand Up @@ -203,22 +193,17 @@ async function downloadTranslator(filename: string): Promise<void> {
const url = baseUrl + "/" + filename;
ztoolkit.log(url);
try {
const contents = await ztoolkit
.getGlobal("Zotero")
.File.getContentsFromURL(url);
const contents = await Zotero.File.getContentsFromURLAsync(url);
const desPath = PathUtils.join(
PathUtils.join(
ztoolkit.getGlobal("Zotero").Prefs.get("dataDir") as string,
Zotero.Prefs.get("dataDir") as string,
"translators"
),
filename
);
await IOUtils.writeUTF8(desPath, contents);
await updateTranslatorImg(filename);
ztoolkit.log(`${filename} 下载成功`);
showPop(
getString("translator-download-success", { args: { filename: filename } })
);
} catch (e) {
ztoolkit.log(`${filename} 下载失败 ${e}`);
showPop(
Expand Down Expand Up @@ -293,7 +278,7 @@ async function updatePrefsUI() {
if (addon.data.prefs?.window == undefined) return;

ztoolkit.log("***** update UI");
const renderLock = ztoolkit.getGlobal("Zotero").Promise.defer();
const renderLock = Zotero.Promise.defer();
checkInputMenu();
// Update pdftk check icon
await checkPath(getPref("pdftkpath") as string);
Expand Down

0 comments on commit e0132ad

Please sign in to comment.