Attempt to address #479
parent
cfd713c120
commit
398e452308
|
@ -186,6 +186,7 @@ export type AppEvent =
|
|||
| "editor:init"
|
||||
| "editor:pageLoaded" // args: pageName, previousPage, isSynced
|
||||
| "editor:pageReloaded"
|
||||
| "editor:pageSaving"
|
||||
| "editor:pageSaved"
|
||||
| "editor:modeswitch"
|
||||
| "plugs:loaded"
|
||||
|
|
|
@ -667,6 +667,10 @@ export class Client {
|
|||
return resolve();
|
||||
}
|
||||
console.log("Saving page", this.currentPage);
|
||||
this.dispatchAppEvent(
|
||||
"editor:pageSaving",
|
||||
this.currentPage,
|
||||
);
|
||||
this.space
|
||||
.writePage(
|
||||
this.currentPage,
|
||||
|
|
|
@ -46,6 +46,8 @@ export interface ISyncService {
|
|||
export class SyncService implements ISyncService {
|
||||
spaceSync: SpaceSync;
|
||||
lastReportedSyncStatus = Date.now();
|
||||
// If this is set to anything other than undefined, a file is currently saving
|
||||
savingTimeout: number | undefined;
|
||||
|
||||
constructor(
|
||||
readonly localSpacePrimitives: SpacePrimitives,
|
||||
|
@ -75,7 +77,21 @@ export class SyncService implements ISyncService {
|
|||
},
|
||||
);
|
||||
|
||||
eventHook.addLocalListener("editor:pageSaving", () => {
|
||||
console.log("Saving...");
|
||||
this.savingTimeout = setTimeout(() => {
|
||||
this.savingTimeout = undefined;
|
||||
}, 1000 * 5);
|
||||
});
|
||||
|
||||
eventHook.addLocalListener("editor:pageSaved", (name) => {
|
||||
console.log("Done saving...");
|
||||
if (this.savingTimeout) {
|
||||
clearTimeout(this.savingTimeout);
|
||||
this.savingTimeout = undefined;
|
||||
} else {
|
||||
console.warn("This should not happen, savingTimeout was not set");
|
||||
}
|
||||
const path = `${name}.md`;
|
||||
this.scheduleFileSync(path).catch(console.error);
|
||||
});
|
||||
|
@ -88,6 +104,12 @@ export class SyncService implements ISyncService {
|
|||
}
|
||||
|
||||
async isSyncing(): Promise<boolean> {
|
||||
if (this.savingTimeout !== undefined) {
|
||||
console.log(
|
||||
"Saving a file at the moment, so reporting as isSyncing() = true",
|
||||
);
|
||||
return true;
|
||||
}
|
||||
const startTime = await this.ds.get(syncStartTimeKey);
|
||||
if (!startTime) {
|
||||
return false;
|
||||
|
|
Loading…
Reference in New Issue