Allow disabling scan
This commit is contained in:
parent
cfa1412e80
commit
6e6ba4f3c2
2 changed files with 62 additions and 24 deletions
|
|
@ -7,12 +7,23 @@ import { syncLocallyDeletedFile } from "src/sync-functions/sync-locally-deleted-
|
|||
import { syncLocallyUpdatedFile } from "src/sync-functions/sync-locally-updated-file";
|
||||
|
||||
export class SyncEventHandler implements FileEventHandler {
|
||||
constructor(private database: Database, private syncServer: SyncServer) {}
|
||||
public constructor(
|
||||
private database: Database,
|
||||
private syncServer: SyncServer
|
||||
) {}
|
||||
|
||||
async onCreate(file: TAbstractFile): Promise<void> {
|
||||
if (file instanceof TFile) {
|
||||
Logger.getInstance().info(`File created: ${file.path}`);
|
||||
syncLocallyUpdatedFile({
|
||||
|
||||
if (!this.database.getSettings().isSyncEnabled) {
|
||||
Logger.getInstance().info(
|
||||
`Sync is disabled, not syncing ${file.path}`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
await syncLocallyUpdatedFile({
|
||||
database: this.database,
|
||||
syncServer: this.syncServer,
|
||||
file,
|
||||
|
|
@ -25,17 +36,38 @@ export class SyncEventHandler implements FileEventHandler {
|
|||
async onDelete(file: TAbstractFile): Promise<void> {
|
||||
if (file instanceof TFile) {
|
||||
Logger.getInstance().info(`File deleted: ${file.path}`);
|
||||
syncLocallyDeletedFile(this.database, this.syncServer, file.path);
|
||||
|
||||
if (!this.database.getSettings().isSyncEnabled) {
|
||||
Logger.getInstance().info(
|
||||
`Sync is disabled, not syncing ${file.path}`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
await syncLocallyDeletedFile(
|
||||
this.database,
|
||||
this.syncServer,
|
||||
file.path
|
||||
);
|
||||
} else {
|
||||
Logger.getInstance().info(`Folder deleted: ${file.path}, ignored`);
|
||||
}
|
||||
}
|
||||
|
||||
async onRename(file: TAbstractFile, oldPath: string): Promise<void> {
|
||||
Logger.getInstance().info(`File renamed: ${oldPath} -> ${file.path}`);
|
||||
|
||||
if (file instanceof TFile) {
|
||||
syncLocallyUpdatedFile({
|
||||
Logger.getInstance().info(
|
||||
`File renamed: ${oldPath} -> ${file.path}`
|
||||
);
|
||||
|
||||
if (!this.database.getSettings().isSyncEnabled) {
|
||||
Logger.getInstance().info(
|
||||
`Sync is disabled, not syncing ${file.path}`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
await syncLocallyUpdatedFile({
|
||||
database: this.database,
|
||||
syncServer: this.syncServer,
|
||||
file,
|
||||
|
|
@ -49,10 +81,17 @@ export class SyncEventHandler implements FileEventHandler {
|
|||
}
|
||||
|
||||
async onModify(file: TAbstractFile): Promise<void> {
|
||||
Logger.getInstance().info(`File modified: ${file.path}`);
|
||||
|
||||
if (file instanceof TFile) {
|
||||
syncLocallyUpdatedFile({
|
||||
Logger.getInstance().info(`File modified: ${file.path}`);
|
||||
|
||||
if (!this.database.getSettings().isSyncEnabled) {
|
||||
Logger.getInstance().info(
|
||||
`Sync is disabled, not syncing ${file.path}`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
await syncLocallyUpdatedFile({
|
||||
database: this.database,
|
||||
syncServer: this.syncServer,
|
||||
file,
|
||||
|
|
|
|||
|
|
@ -1,20 +1,11 @@
|
|||
import {
|
||||
App,
|
||||
Editor,
|
||||
MarkdownView,
|
||||
Modal,
|
||||
Notice,
|
||||
Plugin,
|
||||
PluginSettingTab,
|
||||
Setting,
|
||||
} from "obsidian";
|
||||
import { App, Notice, PluginSettingTab, Setting } from "obsidian";
|
||||
|
||||
import SyncPlugin from "src/plugin";
|
||||
import { Database } from "src/database/database";
|
||||
import { SyncServer } from "src/services/sync_service";
|
||||
|
||||
export class SyncSettingsTab extends PluginSettingTab {
|
||||
constructor(
|
||||
public constructor(
|
||||
app: App,
|
||||
plugin: SyncPlugin,
|
||||
private database: Database,
|
||||
|
|
@ -59,6 +50,14 @@ export class SyncSettingsTab extends PluginSettingTab {
|
|||
new Notice("Failed to connect to server: " + e);
|
||||
}
|
||||
})
|
||||
)
|
||||
.addButton((button) =>
|
||||
button.setButtonText("Reset sync state").onClick(async () => {
|
||||
await this.database.resetSyncState();
|
||||
new Notice(
|
||||
"Sync state has been reset, you will need to resync"
|
||||
);
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
|
|
@ -84,9 +83,9 @@ export class SyncSettingsTab extends PluginSettingTab {
|
|||
.setTooltip("todo, links to docs")
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(this.database.getSettings().fullScanEnabled)
|
||||
.setValue(this.database.getSettings().isSyncEnabled)
|
||||
.onChange((value) =>
|
||||
this.database.setSetting("fullScanEnabled", value)
|
||||
this.database.setSetting("isSyncEnabled", value)
|
||||
)
|
||||
)
|
||||
.addSlider((text) =>
|
||||
|
|
@ -94,11 +93,11 @@ export class SyncSettingsTab extends PluginSettingTab {
|
|||
.setLimits(1, 3600, 1)
|
||||
.setDynamicTooltip()
|
||||
.setValue(
|
||||
this.database.getSettings().fullScanIntervalInSeconds
|
||||
this.database.getSettings().fetchChangesUpdateInterval
|
||||
)
|
||||
.onChange((value) =>
|
||||
this.database.setSetting(
|
||||
"fullScanIntervalInSeconds",
|
||||
"fetchChangesUpdateInterval",
|
||||
value
|
||||
)
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue