add: sync period setting
This commit is contained in:
parent
0a119860c9
commit
5bf65abd9f
|
|
@ -40,6 +40,7 @@
|
|||
</listbox>
|
||||
<hbox flex="0">
|
||||
<button id="doupdate" label="&zotero.__addonRef__.syncList.doupdate.label;" oncommand="Zotero.Knowledge4Zotero.syncList.doUpdate();"></button>
|
||||
<button id="changesyncperiod" label="&zotero.__addonRef__.syncList.changesyncperiod.label;" oncommand="Zotero.Knowledge4Zotero.syncList.changeSyncPeriod();"></button>
|
||||
<button id="dosync" label="&zotero.__addonRef__.syncList.dosync.label;" oncommand="Zotero.Knowledge4Zotero.syncList.doSync();"></button>
|
||||
<button id="changesync" label="&zotero.__addonRef__.syncList.changesync.label;" oncommand="Zotero.Knowledge4Zotero.syncList.changeSync();"></button>
|
||||
<button id="removesync" label="&zotero.__addonRef__.syncList.removesync.label;" oncommand="Zotero.Knowledge4Zotero.syncList.removeSync();"></button>
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@
|
|||
<!ENTITY zotero.__addonRef__.syncList.syncpath.label "Sync To">
|
||||
<!ENTITY zotero.__addonRef__.syncList.lastsync.label "Last Sync">
|
||||
<!ENTITY zotero.__addonRef__.syncList.doupdate.label "Refresh">
|
||||
<!ENTITY zotero.__addonRef__.syncList.changesyncperiod.label "Sync Period:">
|
||||
<!ENTITY zotero.__addonRef__.syncList.dosync.label "Sync">
|
||||
<!ENTITY zotero.__addonRef__.syncList.changesync.label "Change Folder">
|
||||
<!ENTITY zotero.__addonRef__.syncList.removesync.label "Remove This">
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@
|
|||
<!ENTITY zotero.__addonRef__.syncList.syncpath.label "同步到">
|
||||
<!ENTITY zotero.__addonRef__.syncList.lastsync.label "最近同步">
|
||||
<!ENTITY zotero.__addonRef__.syncList.doupdate.label "刷新">
|
||||
<!ENTITY zotero.__addonRef__.syncList.changesyncperiod.label "同步周期:">
|
||||
<!ENTITY zotero.__addonRef__.syncList.dosync.label "同步">
|
||||
<!ENTITY zotero.__addonRef__.syncList.changesync.label "修改路径">
|
||||
<!ENTITY zotero.__addonRef__.syncList.removesync.label "取消同步">
|
||||
|
|
|
|||
|
|
@ -1586,6 +1586,13 @@ class AddonEvents extends AddonBase {
|
|||
this._Addon.template.getCitationStyle();
|
||||
// Initialize sync notes
|
||||
this._Addon.sync.getSyncNoteIds();
|
||||
// Initialize sync period
|
||||
// Default sync period is 10s
|
||||
if (
|
||||
typeof Zotero.Prefs.get("Knowledge4Zotero.syncPeriod") === "undefined"
|
||||
) {
|
||||
this._Addon.syncList.changeSyncPeriod(10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
17
src/sync.ts
17
src/sync.ts
|
|
@ -193,7 +193,7 @@ class AddonSync extends AddonBase {
|
|||
noteItem.removeTag(sycnTag.tag);
|
||||
}
|
||||
noteItem.addTag(
|
||||
`sync://note/?version=${noteItem._version}&path=${
|
||||
`sync://note/?version=${noteItem._version + 1}&path=${
|
||||
path ? encodeURIComponent(path) : syncInfo["path"]
|
||||
}&filename=${
|
||||
filename ? encodeURIComponent(filename) : syncInfo["filename"]
|
||||
|
|
@ -206,11 +206,14 @@ class AddonSync extends AddonBase {
|
|||
setSync() {
|
||||
const _t = new Date().getTime();
|
||||
this.triggerTime = _t;
|
||||
setTimeout(() => {
|
||||
if (this.triggerTime === _t) {
|
||||
this.doSync();
|
||||
}
|
||||
}, 10000);
|
||||
const syncPeriod = Number(Zotero.Prefs.get("Knowledge4Zotero.syncPeriod"));
|
||||
if (syncPeriod > 0) {
|
||||
setTimeout(() => {
|
||||
if (this.triggerTime === _t) {
|
||||
this.doSync();
|
||||
}
|
||||
}, syncPeriod);
|
||||
}
|
||||
}
|
||||
|
||||
async doSync(
|
||||
|
|
@ -229,7 +232,7 @@ class AddonSync extends AddonBase {
|
|||
const filepath = decodeURIComponent(syncInfo.path);
|
||||
const filename = decodeURIComponent(syncInfo.filename);
|
||||
if (
|
||||
Number(syncInfo.version) < item._version - 1 ||
|
||||
Number(syncInfo.version) < item._version ||
|
||||
!(await OS.File.exists(`${filepath}/${filename}`)) ||
|
||||
forceNoteIds.includes(item.id)
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ class AddonSyncList extends AddonBase {
|
|||
window.open(
|
||||
"chrome://Knowledge4Zotero/content/syncList.xul",
|
||||
"",
|
||||
"chrome,centerscreen,resizable,status,width=500,height=400"
|
||||
"chrome,centerscreen,resizable,status,width=600,height=400"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -25,6 +25,9 @@ class AddonSyncList extends AddonBase {
|
|||
}
|
||||
|
||||
doUpdate() {
|
||||
if (!this._window || this._window.closed) {
|
||||
return;
|
||||
}
|
||||
const notes = Zotero.Items.get(this._Addon.sync.getSyncNoteIds());
|
||||
const listbox = this._window.document.getElementById("sync-list");
|
||||
let e,
|
||||
|
|
@ -77,6 +80,19 @@ class AddonSyncList extends AddonBase {
|
|||
});
|
||||
listbox.append(listitem);
|
||||
}
|
||||
|
||||
const periodButton = this._window.document.getElementById(
|
||||
"changesyncperiod"
|
||||
) as XUL.Button;
|
||||
const period =
|
||||
Number(Zotero.Prefs.get("Knowledge4Zotero.syncPeriod")) / 1000;
|
||||
periodButton.setAttribute(
|
||||
"label",
|
||||
periodButton.getAttribute("label").split(":")[0] +
|
||||
":" +
|
||||
(period > 0 ? period + "s" : "disabled")
|
||||
);
|
||||
this._window.focus();
|
||||
}
|
||||
|
||||
getSelectedItems(): ZoteroItem[] {
|
||||
|
|
@ -112,6 +128,22 @@ class AddonSyncList extends AddonBase {
|
|||
this.doUpdate();
|
||||
}
|
||||
|
||||
changeSyncPeriod(period: number = -1) {
|
||||
if (period < 0) {
|
||||
const inputPeriod = prompt("Enter synchronization period in seconds:");
|
||||
if (inputPeriod) {
|
||||
period = Number(inputPeriod);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (period < 0) {
|
||||
period = 0;
|
||||
}
|
||||
Zotero.Prefs.set("Knowledge4Zotero.syncPeriod", Math.round(period) * 1000);
|
||||
this.doUpdate();
|
||||
}
|
||||
|
||||
async removeSync() {
|
||||
let selectedItems = this.getSelectedItems();
|
||||
if (selectedItems.length === 0) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue