show progress
This commit is contained in:
parent
e7c24b55a3
commit
c637038d95
21
src/main.ts
21
src/main.ts
@ -64,6 +64,7 @@ export default class RemotelySavePlugin extends Plugin {
|
|||||||
syncStatus: SyncStatusType;
|
syncStatus: SyncStatusType;
|
||||||
oauth2Info: OAuth2Info;
|
oauth2Info: OAuth2Info;
|
||||||
currLogLevel: string;
|
currLogLevel: string;
|
||||||
|
currSyncMsg?: string;
|
||||||
|
|
||||||
async onload() {
|
async onload() {
|
||||||
log.info(`loading plugin ${this.manifest.id}`);
|
log.info(`loading plugin ${this.manifest.id}`);
|
||||||
@ -76,6 +77,8 @@ export default class RemotelySavePlugin extends Plugin {
|
|||||||
revokeAuthSetting: undefined,
|
revokeAuthSetting: undefined,
|
||||||
}; // init
|
}; // init
|
||||||
|
|
||||||
|
this.currSyncMsg = "";
|
||||||
|
|
||||||
await this.loadSettings();
|
await this.loadSettings();
|
||||||
|
|
||||||
if (this.settings.currLogLevel !== undefined) {
|
if (this.settings.currLogLevel !== undefined) {
|
||||||
@ -282,6 +285,9 @@ export default class RemotelySavePlugin extends Plugin {
|
|||||||
new Notice(
|
new Notice(
|
||||||
`Remotely Save already running in stage ${this.syncStatus}!`
|
`Remotely Save already running in stage ${this.syncStatus}!`
|
||||||
);
|
);
|
||||||
|
if (this.currSyncMsg !== undefined && this.currSyncMsg !== "") {
|
||||||
|
new Notice(this.currSyncMsg);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -349,10 +355,13 @@ export default class RemotelySavePlugin extends Plugin {
|
|||||||
this.db,
|
this.db,
|
||||||
this.app.vault,
|
this.app.vault,
|
||||||
syncPlan,
|
syncPlan,
|
||||||
this.settings.password
|
this.settings.password,
|
||||||
|
(i: number, totalCount: number, pathName: string, decision: string) =>
|
||||||
|
self.setCurrSyncMsg(i, totalCount, pathName, decision)
|
||||||
);
|
);
|
||||||
|
|
||||||
new Notice("7/7 Remotely Save finish!");
|
new Notice("7/7 Remotely Save finish!");
|
||||||
|
this.currSyncMsg = "";
|
||||||
this.syncStatus = "finish";
|
this.syncStatus = "finish";
|
||||||
this.syncStatus = "idle";
|
this.syncStatus = "idle";
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -479,4 +488,14 @@ export default class RemotelySavePlugin extends Plugin {
|
|||||||
destroyDBs() {
|
destroyDBs() {
|
||||||
/* destroyDBs(this.db); */
|
/* destroyDBs(this.db); */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async setCurrSyncMsg(
|
||||||
|
i: number,
|
||||||
|
totalCount: number,
|
||||||
|
pathName: string,
|
||||||
|
decision: string
|
||||||
|
) {
|
||||||
|
const msg = `${i}/${totalCount}, ${decision}, ${pathName}`;
|
||||||
|
this.currSyncMsg = msg;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
11
src/sync.ts
11
src/sync.ts
@ -567,16 +567,23 @@ export const doActualSync = async (
|
|||||||
db: InternalDBs,
|
db: InternalDBs,
|
||||||
vault: Vault,
|
vault: Vault,
|
||||||
syncPlan: SyncPlanType,
|
syncPlan: SyncPlanType,
|
||||||
password: string = ""
|
password: string = "",
|
||||||
|
callbackSyncProcess?: any
|
||||||
) => {
|
) => {
|
||||||
const keyStates = syncPlan.mixedStates;
|
const keyStates = syncPlan.mixedStates;
|
||||||
const foldersCreatedBefore = new Set<string>();
|
const foldersCreatedBefore = new Set<string>();
|
||||||
|
let i = 0;
|
||||||
|
const totalCount = Object.keys(keyStates).length || 0;
|
||||||
for (const [k, v] of Object.entries(keyStates).sort(
|
for (const [k, v] of Object.entries(keyStates).sort(
|
||||||
([k1, v1], [k2, v2]) => k2.length - k1.length
|
([k1, v1], [k2, v2]) => k2.length - k1.length
|
||||||
)) {
|
)) {
|
||||||
|
i += 1;
|
||||||
const k2 = k as string;
|
const k2 = k as string;
|
||||||
const v2 = v as FileOrFolderMixedState;
|
const v2 = v as FileOrFolderMixedState;
|
||||||
log.debug(`start syncing "${k2}" with plan ${JSON.stringify(v2)}`);
|
log.debug(`start syncing "${k2}" with plan ${JSON.stringify(v2)}`);
|
||||||
|
if (callbackSyncProcess !== undefined) {
|
||||||
|
await callbackSyncProcess(i, totalCount, k2, v2.decision);
|
||||||
|
}
|
||||||
await dispatchOperationToActual(
|
await dispatchOperationToActual(
|
||||||
k2,
|
k2,
|
||||||
v2,
|
v2,
|
||||||
@ -586,7 +593,7 @@ export const doActualSync = async (
|
|||||||
password,
|
password,
|
||||||
foldersCreatedBefore
|
foldersCreatedBefore
|
||||||
);
|
);
|
||||||
// log.info(`finished ${k}, with ${setToString(foldersCreatedBefore)}`);
|
log.info(`finished ${k2}`);
|
||||||
}
|
}
|
||||||
// await Promise.all(
|
// await Promise.all(
|
||||||
// Object.entries(keyStates)
|
// Object.entries(keyStates)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user