Merge branch 'master' of https://github.com/fyears/remotely-save
This commit is contained in:
commit
635db41d0d
5087
pnpm-lock.yaml
generated
Normal file
5087
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -79,6 +79,7 @@ export interface RemotelySavePluginSettings {
|
|||||||
currLogLevel?: string;
|
currLogLevel?: string;
|
||||||
autoRunEveryMilliseconds?: number;
|
autoRunEveryMilliseconds?: number;
|
||||||
initRunAfterMilliseconds?: number;
|
initRunAfterMilliseconds?: number;
|
||||||
|
syncOnSaveAfterMilliseconds?: number;
|
||||||
agreeToUploadExtraMetadata?: boolean;
|
agreeToUploadExtraMetadata?: boolean;
|
||||||
concurrency?: number;
|
concurrency?: number;
|
||||||
syncConfigDir?: boolean;
|
syncConfigDir?: boolean;
|
||||||
|
|||||||
50
src/main.ts
50
src/main.ts
@ -83,6 +83,7 @@ const DEFAULT_SETTINGS: RemotelySavePluginSettings = {
|
|||||||
// vaultRandomID: "", // deprecated
|
// vaultRandomID: "", // deprecated
|
||||||
autoRunEveryMilliseconds: -1,
|
autoRunEveryMilliseconds: -1,
|
||||||
initRunAfterMilliseconds: -1,
|
initRunAfterMilliseconds: -1,
|
||||||
|
syncOnSaveAfterMilliseconds: -1,
|
||||||
agreeToUploadExtraMetadata: false,
|
agreeToUploadExtraMetadata: false,
|
||||||
concurrency: 5,
|
concurrency: 5,
|
||||||
syncConfigDir: false,
|
syncConfigDir: false,
|
||||||
@ -138,6 +139,7 @@ export default class RemotelySavePlugin extends Plugin {
|
|||||||
currSyncMsg?: string;
|
currSyncMsg?: string;
|
||||||
syncRibbon?: HTMLElement;
|
syncRibbon?: HTMLElement;
|
||||||
autoRunIntervalID?: number;
|
autoRunIntervalID?: number;
|
||||||
|
syncOnSaveIntervalID?: number;
|
||||||
i18n: I18n;
|
i18n: I18n;
|
||||||
vaultRandomID: string;
|
vaultRandomID: string;
|
||||||
|
|
||||||
@ -174,8 +176,7 @@ export default class RemotelySavePlugin extends Plugin {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
log.info(
|
log.info(
|
||||||
`${
|
`${this.manifest.id
|
||||||
this.manifest.id
|
|
||||||
}-${Date.now()}: start sync, triggerSource=${triggerSource}`
|
}-${Date.now()}: start sync, triggerSource=${triggerSource}`
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -381,8 +382,7 @@ export default class RemotelySavePlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.info(
|
log.info(
|
||||||
`${
|
`${this.manifest.id
|
||||||
this.manifest.id
|
|
||||||
}-${Date.now()}: finish sync, triggerSource=${triggerSource}`
|
}-${Date.now()}: finish sync, triggerSource=${triggerSource}`
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -809,6 +809,7 @@ export default class RemotelySavePlugin extends Plugin {
|
|||||||
} else {
|
} else {
|
||||||
this.enableAutoSyncIfSet();
|
this.enableAutoSyncIfSet();
|
||||||
this.enableInitSyncIfSet();
|
this.enableInitSyncIfSet();
|
||||||
|
this.enableSyncOnSaveIfSet();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -990,6 +991,47 @@ export default class RemotelySavePlugin extends Plugin {
|
|||||||
this.vaultRandomID = vaultRandomID;
|
this.vaultRandomID = vaultRandomID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enableSyncOnSaveIfSet() {
|
||||||
|
if (
|
||||||
|
this.settings.syncOnSaveAfterMilliseconds !== undefined &&
|
||||||
|
this.settings.syncOnSaveAfterMilliseconds !== null &&
|
||||||
|
this.settings.syncOnSaveAfterMilliseconds > 0
|
||||||
|
) {
|
||||||
|
let runScheduled = false;
|
||||||
|
this.app.workspace.onLayoutReady(() => {
|
||||||
|
const intervalID = window.setInterval(() => {
|
||||||
|
const currentFile = this.app.workspace.getActiveFile();
|
||||||
|
|
||||||
|
if (currentFile) {
|
||||||
|
// get the last modified time of the current file
|
||||||
|
// if it has been modified within the last syncOnSaveAfterMilliseconds
|
||||||
|
// then schedule a run for syncOnSaveAfterMilliseconds after it was modified
|
||||||
|
const lastModified = currentFile.stat.mtime;
|
||||||
|
const currentTime = Date.now();
|
||||||
|
log.debug(
|
||||||
|
`Checking if file was modified within last ${this.settings.syncOnSaveAfterMilliseconds / 1000} seconds, last modified: ${(currentTime - lastModified) / 1000} seconds ago`
|
||||||
|
);
|
||||||
|
if (currentTime - lastModified < this.settings.syncOnSaveAfterMilliseconds) {
|
||||||
|
if (!runScheduled) {
|
||||||
|
const scheduleTimeFromNow = this.settings.syncOnSaveAfterMilliseconds - (currentTime - lastModified)
|
||||||
|
log.info(`schedule a run for ${scheduleTimeFromNow} milliseconds later`)
|
||||||
|
runScheduled = true
|
||||||
|
setTimeout(() => {
|
||||||
|
this.syncRun("auto")
|
||||||
|
runScheduled = false
|
||||||
|
},
|
||||||
|
scheduleTimeFromNow
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 1_000);
|
||||||
|
this.syncOnSaveIntervalID = intervalID;
|
||||||
|
this.registerInterval(intervalID);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
enableAutoSyncIfSet() {
|
enableAutoSyncIfSet() {
|
||||||
if (
|
if (
|
||||||
this.settings.autoRunEveryMilliseconds !== undefined &&
|
this.settings.autoRunEveryMilliseconds !== undefined &&
|
||||||
|
|||||||
@ -21,6 +21,7 @@ export const applyLogWriterInplace = function (writer: (...msg: any[]) => any) {
|
|||||||
logLevel: LogLevelNumbers,
|
logLevel: LogLevelNumbers,
|
||||||
loggerName: string | symbol
|
loggerName: string | symbol
|
||||||
) {
|
) {
|
||||||
|
// @ts-ignore
|
||||||
const rawMethod = originalFactory(methodName, logLevel, loggerName);
|
const rawMethod = originalFactory(methodName, logLevel, loggerName);
|
||||||
|
|
||||||
return function (...msg: any[]) {
|
return function (...msg: any[]) {
|
||||||
|
|||||||
@ -831,8 +831,7 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
|||||||
|
|
||||||
dropdown
|
dropdown
|
||||||
.setValue(
|
.setValue(
|
||||||
`${
|
`${this.plugin.settings.s3.bypassCorsLocally ? "enable" : "disable"
|
||||||
this.plugin.settings.s3.bypassCorsLocally ? "enable" : "disable"
|
|
||||||
}`
|
}`
|
||||||
)
|
)
|
||||||
.onChange(async (value) => {
|
.onChange(async (value) => {
|
||||||
@ -1517,6 +1516,67 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
new Setting(basicDiv)
|
||||||
|
.setName(t("settings_saverun"))
|
||||||
|
.setDesc(t("settings_saverun_desc"))
|
||||||
|
.addDropdown((dropdown) => {
|
||||||
|
dropdown.addOption("-1", t("settings_saverun_notset"));
|
||||||
|
dropdown.addOption(`${1000 * 1}`, t("settings_saverun_1sec"));
|
||||||
|
dropdown.addOption(`${1000 * 5}`, t("settings_saverun_5sec"));
|
||||||
|
dropdown.addOption(`${1000 * 10}`, t("settings_saverun_10sec"));
|
||||||
|
dropdown.addOption(`${1000 * 60}`, t("settings_saverun_1min"));
|
||||||
|
let runScheduled = false
|
||||||
|
dropdown
|
||||||
|
.setValue(`${this.plugin.settings.syncOnSaveAfterMilliseconds}`)
|
||||||
|
.onChange(async (val: string) => {
|
||||||
|
const realVal = parseInt(val);
|
||||||
|
this.plugin.settings.syncOnSaveAfterMilliseconds = realVal;
|
||||||
|
await this.plugin.saveSettings();
|
||||||
|
if (
|
||||||
|
(realVal === undefined || realVal === null || realVal <= 0) &&
|
||||||
|
this.plugin.syncOnSaveIntervalID !== undefined
|
||||||
|
) {
|
||||||
|
// clear
|
||||||
|
window.clearInterval(this.plugin.syncOnSaveIntervalID);
|
||||||
|
this.plugin.syncOnSaveIntervalID = undefined;
|
||||||
|
} else if (
|
||||||
|
realVal !== undefined &&
|
||||||
|
realVal !== null &&
|
||||||
|
realVal > 0
|
||||||
|
) {
|
||||||
|
const intervalID = window.setInterval(() => {
|
||||||
|
const currentFile = this.app.workspace.getActiveFile();
|
||||||
|
|
||||||
|
if (currentFile) {
|
||||||
|
// get the last modified time of the current file
|
||||||
|
// if it has been modified within the last syncOnSaveAfterMilliseconds
|
||||||
|
// then schedule a run for syncOnSaveAfterMilliseconds after it was modified
|
||||||
|
const lastModified = currentFile.stat.mtime;
|
||||||
|
const currentTime = Date.now();
|
||||||
|
log.debug(
|
||||||
|
`Checking if file was modified within last ${this.plugin.settings.syncOnSaveAfterMilliseconds / 1000} seconds, last modified: ${(currentTime - lastModified) / 1000} seconds ago`
|
||||||
|
);
|
||||||
|
if (currentTime - lastModified < this.plugin.settings.syncOnSaveAfterMilliseconds) {
|
||||||
|
if (!runScheduled) {
|
||||||
|
const scheduleTimeFromNow = this.plugin.settings.syncOnSaveAfterMilliseconds - (currentTime - lastModified)
|
||||||
|
log.info(`schedule a run for ${scheduleTimeFromNow} milliseconds later`)
|
||||||
|
runScheduled = true
|
||||||
|
setTimeout(() => {
|
||||||
|
this.plugin.syncRun("auto")
|
||||||
|
runScheduled = false
|
||||||
|
},
|
||||||
|
scheduleTimeFromNow
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, realVal);
|
||||||
|
this.plugin.syncOnSaveIntervalID = intervalID;
|
||||||
|
this.plugin.registerInterval(intervalID);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
new Setting(basicDiv)
|
new Setting(basicDiv)
|
||||||
.setName(t("settings_autorun"))
|
.setName(t("settings_autorun"))
|
||||||
.setDesc(t("settings_autorun_desc"))
|
.setDesc(t("settings_autorun_desc"))
|
||||||
@ -1546,6 +1606,8 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
|||||||
realVal > 0
|
realVal > 0
|
||||||
) {
|
) {
|
||||||
const intervalID = window.setInterval(() => {
|
const intervalID = window.setInterval(() => {
|
||||||
|
log.info("auto run from settings.ts");
|
||||||
|
console.log("auto run from settings.ts");
|
||||||
this.plugin.syncRun("auto");
|
this.plugin.syncRun("auto");
|
||||||
}, realVal);
|
}, realVal);
|
||||||
this.plugin.autoRunIntervalID = intervalID;
|
this.plugin.autoRunIntervalID = intervalID;
|
||||||
@ -1579,6 +1641,7 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
|||||||
await this.plugin.saveSettings();
|
await this.plugin.saveSettings();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
new Setting(basicDiv)
|
new Setting(basicDiv)
|
||||||
.setName(t("settings_skiplargefiles"))
|
.setName(t("settings_skiplargefiles"))
|
||||||
.setDesc(t("settings_skiplargefiles_desc"))
|
.setDesc(t("settings_skiplargefiles_desc"))
|
||||||
|
|||||||
@ -55,6 +55,7 @@ export class SyncAlgoV2Modal extends Modal {
|
|||||||
this.plugin.saveAgreeToUseNewSyncAlgorithm();
|
this.plugin.saveAgreeToUseNewSyncAlgorithm();
|
||||||
this.plugin.enableAutoSyncIfSet();
|
this.plugin.enableAutoSyncIfSet();
|
||||||
this.plugin.enableInitSyncIfSet();
|
this.plugin.enableInitSyncIfSet();
|
||||||
|
this.plugin.enableSyncOnSaveIfSet();
|
||||||
} else {
|
} else {
|
||||||
log.info("do not agree to use the new algorithm");
|
log.info("do not agree to use the new algorithm");
|
||||||
this.plugin.unload();
|
this.plugin.unload();
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
"inlineSourceMap": true,
|
"inlineSourceMap": true,
|
||||||
"inlineSources": true,
|
"inlineSources": true,
|
||||||
"module": "ESNext",
|
"module": "ESNext",
|
||||||
"target": "es6",
|
"target": "ESNext",
|
||||||
"allowJs": true,
|
"allowJs": true,
|
||||||
"noImplicitAny": true,
|
"noImplicitAny": true,
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
@ -13,7 +13,14 @@
|
|||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"importHelpers": true,
|
"importHelpers": true,
|
||||||
"isolatedModules": true,
|
"isolatedModules": true,
|
||||||
"lib": ["dom", "es5", "scripthost", "es2015"]
|
"lib": [
|
||||||
|
"dom",
|
||||||
|
"es5",
|
||||||
|
"scripthost",
|
||||||
|
"es2015"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"include": ["**/*.ts"]
|
"include": [
|
||||||
}
|
"**/*.ts"
|
||||||
|
]
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user