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";
|
import { syncLocallyUpdatedFile } from "src/sync-functions/sync-locally-updated-file";
|
||||||
|
|
||||||
export class SyncEventHandler implements FileEventHandler {
|
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> {
|
async onCreate(file: TAbstractFile): Promise<void> {
|
||||||
if (file instanceof TFile) {
|
if (file instanceof TFile) {
|
||||||
Logger.getInstance().info(`File created: ${file.path}`);
|
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,
|
database: this.database,
|
||||||
syncServer: this.syncServer,
|
syncServer: this.syncServer,
|
||||||
file,
|
file,
|
||||||
|
|
@ -25,17 +36,38 @@ export class SyncEventHandler implements FileEventHandler {
|
||||||
async onDelete(file: TAbstractFile): Promise<void> {
|
async onDelete(file: TAbstractFile): Promise<void> {
|
||||||
if (file instanceof TFile) {
|
if (file instanceof TFile) {
|
||||||
Logger.getInstance().info(`File deleted: ${file.path}`);
|
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 {
|
} else {
|
||||||
Logger.getInstance().info(`Folder deleted: ${file.path}, ignored`);
|
Logger.getInstance().info(`Folder deleted: ${file.path}, ignored`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async onRename(file: TAbstractFile, oldPath: string): Promise<void> {
|
async onRename(file: TAbstractFile, oldPath: string): Promise<void> {
|
||||||
Logger.getInstance().info(`File renamed: ${oldPath} -> ${file.path}`);
|
|
||||||
|
|
||||||
if (file instanceof TFile) {
|
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,
|
database: this.database,
|
||||||
syncServer: this.syncServer,
|
syncServer: this.syncServer,
|
||||||
file,
|
file,
|
||||||
|
|
@ -49,10 +81,17 @@ export class SyncEventHandler implements FileEventHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
async onModify(file: TAbstractFile): Promise<void> {
|
async onModify(file: TAbstractFile): Promise<void> {
|
||||||
Logger.getInstance().info(`File modified: ${file.path}`);
|
|
||||||
|
|
||||||
if (file instanceof TFile) {
|
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,
|
database: this.database,
|
||||||
syncServer: this.syncServer,
|
syncServer: this.syncServer,
|
||||||
file,
|
file,
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,11 @@
|
||||||
import {
|
import { App, Notice, PluginSettingTab, Setting } from "obsidian";
|
||||||
App,
|
|
||||||
Editor,
|
|
||||||
MarkdownView,
|
|
||||||
Modal,
|
|
||||||
Notice,
|
|
||||||
Plugin,
|
|
||||||
PluginSettingTab,
|
|
||||||
Setting,
|
|
||||||
} from "obsidian";
|
|
||||||
|
|
||||||
import SyncPlugin from "src/plugin";
|
import SyncPlugin from "src/plugin";
|
||||||
import { Database } from "src/database/database";
|
import { Database } from "src/database/database";
|
||||||
import { SyncServer } from "src/services/sync_service";
|
import { SyncServer } from "src/services/sync_service";
|
||||||
|
|
||||||
export class SyncSettingsTab extends PluginSettingTab {
|
export class SyncSettingsTab extends PluginSettingTab {
|
||||||
constructor(
|
public constructor(
|
||||||
app: App,
|
app: App,
|
||||||
plugin: SyncPlugin,
|
plugin: SyncPlugin,
|
||||||
private database: Database,
|
private database: Database,
|
||||||
|
|
@ -59,6 +50,14 @@ export class SyncSettingsTab extends PluginSettingTab {
|
||||||
new Notice("Failed to connect to server: " + e);
|
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)
|
new Setting(containerEl)
|
||||||
|
|
@ -84,9 +83,9 @@ export class SyncSettingsTab extends PluginSettingTab {
|
||||||
.setTooltip("todo, links to docs")
|
.setTooltip("todo, links to docs")
|
||||||
.addToggle((toggle) =>
|
.addToggle((toggle) =>
|
||||||
toggle
|
toggle
|
||||||
.setValue(this.database.getSettings().fullScanEnabled)
|
.setValue(this.database.getSettings().isSyncEnabled)
|
||||||
.onChange((value) =>
|
.onChange((value) =>
|
||||||
this.database.setSetting("fullScanEnabled", value)
|
this.database.setSetting("isSyncEnabled", value)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.addSlider((text) =>
|
.addSlider((text) =>
|
||||||
|
|
@ -94,11 +93,11 @@ export class SyncSettingsTab extends PluginSettingTab {
|
||||||
.setLimits(1, 3600, 1)
|
.setLimits(1, 3600, 1)
|
||||||
.setDynamicTooltip()
|
.setDynamicTooltip()
|
||||||
.setValue(
|
.setValue(
|
||||||
this.database.getSettings().fullScanIntervalInSeconds
|
this.database.getSettings().fetchChangesUpdateInterval
|
||||||
)
|
)
|
||||||
.onChange((value) =>
|
.onChange((value) =>
|
||||||
this.database.setSetting(
|
this.database.setSetting(
|
||||||
"fullScanIntervalInSeconds",
|
"fetchChangesUpdateInterval",
|
||||||
value
|
value
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue