From 0fd311f7d876df4d5c8d2d29a54d825954059d70 Mon Sep 17 00:00:00 2001 From: Vinzent Date: Wed, 9 Oct 2024 23:33:01 +0200 Subject: [PATCH] wip --- eslint.config.mjs | 13 +- package.json | 2 +- src/automaticsManager.ts | 5 +- src/commands.ts | 22 +-- src/gitManager/gitManager.ts | 2 +- src/gitManager/simpleGit.ts | 14 +- src/main.ts | 56 +++--- src/setting/settings.ts | 162 +++++++++--------- src/ui/history/historyView.ts | 1 + .../components/treeComponent.svelte | 1 + src/ui/sourceControl/sourceControl.svelte | 18 +- src/ui/sourceControl/sourceControl.ts | 1 + src/utils.ts | 1 + 13 files changed, 166 insertions(+), 132 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 1468408c..a935d431 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -19,7 +19,18 @@ export default tseslint.config( }, }, rules: { - "@typescript-eslint/no-unused-vars": "warn", + "@typescript-eslint/no-unused-vars": [ + "error", + { + args: "all", + argsIgnorePattern: "^_", + caughtErrors: "all", + caughtErrorsIgnorePattern: "^_", + destructuredArrayIgnorePattern: "^_", + varsIgnorePattern: "^_", + ignoreRestSiblings: true, + }, + ], }, }, { diff --git a/package.json b/package.json index c627ba91..54f8247c 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "dev": "node esbuild.config.mjs dev", "build": "node esbuild.config.mjs production", "release": "standard-version", - "lint": "eslint", + "lint": "eslint src", "format": "prettier --check src", "tsc": "tsc --noEmit", "svelte": "svelte-check", diff --git a/src/automaticsManager.ts b/src/automaticsManager.ts index c0aa4183..8fa7ac8d 100644 --- a/src/automaticsManager.ts +++ b/src/automaticsManager.ts @@ -29,7 +29,7 @@ export default class AutomaticsManager { } async init() { - this.setUpAutoCommitAndSync(); + await this.setUpAutoCommitAndSync(); const lastAutos = this.loadLastAuto(); if ( @@ -155,7 +155,6 @@ export default class AutomaticsManager { } }); this.saveLastAuto(new Date(), "backup"); - this.plugin.saveSettings(); this.startAutoCommitAndSync(); } @@ -169,7 +168,6 @@ export default class AutomaticsManager { this.plugin.pullChangesFromRemote() ); this.saveLastAuto(new Date(), "pull"); - this.plugin.saveSettings(); this.startAutoPull(); }, time); } @@ -182,7 +180,6 @@ export default class AutomaticsManager { this.timeoutIDPush = window.setTimeout(() => { this.plugin.promiseQueue.addTask(() => this.plugin.push()); this.saveLastAuto(new Date(), "push"); - this.plugin.saveSettings(); this.startAutoPush(); }, time); } diff --git a/src/commands.ts b/src/commands.ts index ed1637d3..9c2d3f79 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -21,14 +21,14 @@ export function addCommmands(plugin: ObsidianGit) { callback: async () => { const path = plugin.gitManager.getRelativeVaultPath(".gitignore"); if (!(await app.vault.adapter.exists(path))) { - app.vault.adapter.write(path, ""); + await app.vault.adapter.write(path, ""); } const content = await app.vault.adapter.read(path); const modal = new IgnoreModal(app, content); const res = await modal.open(); if (res !== undefined) { await app.vault.adapter.write(path, res); - plugin.refresh(); + await plugin.refresh(); } }, }); @@ -50,7 +50,7 @@ export function addCommmands(plugin: ObsidianGit) { } else { leaf = leafs.first()!; } - app.workspace.revealLeaf(leaf); + await app.workspace.revealLeaf(leaf); }, }); plugin.addCommand({ @@ -71,7 +71,7 @@ export function addCommmands(plugin: ObsidianGit) { } else { leaf = leafs.first()!; } - app.workspace.revealLeaf(leaf); + await app.workspace.revealLeaf(leaf); }, }); @@ -83,7 +83,7 @@ export function addCommmands(plugin: ObsidianGit) { if (checking) { return file !== null; } else { - getNewLeaf(app)?.setViewState({ + void getNewLeaf(app)?.setViewState({ type: DIFF_VIEW_CONFIG.type, active: true, state: { @@ -142,7 +142,9 @@ export function addCommmands(plugin: ObsidianGit) { if (checking) { return file !== null; } else { - plugin.addFileToGitignore(file!); + plugin + .addFileToGitignore(file!) + .catch((e) => plugin.displayError(e)); } }, }); @@ -310,7 +312,7 @@ export function addCommmands(plugin: ObsidianGit) { "Successfully deleted repository. Reloading plugin..." ); plugin.unloadPlugin(); - plugin.init(); + await plugin.init(); } } else { new Notice("No repository found"); @@ -352,7 +354,7 @@ export function addCommmands(plugin: ObsidianGit) { id: "switch-branch", name: "Switch branch", callback: () => { - plugin.switchBranch(); + plugin.switchBranch().catch((e) => plugin.displayError(e)); }, }); @@ -360,7 +362,7 @@ export function addCommmands(plugin: ObsidianGit) { id: "create-branch", name: "Create new branch", callback: () => { - plugin.createBranch(); + plugin.createBranch().catch((e) => plugin.displayError(e)); }, }); @@ -368,7 +370,7 @@ export function addCommmands(plugin: ObsidianGit) { id: "delete-branch", name: "Delete branch", callback: () => { - plugin.deleteBranch(); + plugin.deleteBranch().catch((e) => plugin.displayError(e)); }, }); diff --git a/src/gitManager/gitManager.ts b/src/gitManager/gitManager.ts index c7700d51..0e8eec73 100644 --- a/src/gitManager/gitManager.ts +++ b/src/gitManager/gitManager.ts @@ -75,7 +75,7 @@ export abstract class GitManager { value: string | number | boolean | undefined ): Promise; - abstract getConfig(path: string): Promise; + abstract getConfig(path: string): Promise; abstract fetch(remote?: string): Promise; diff --git a/src/gitManager/simpleGit.ts b/src/gitManager/simpleGit.ts index aeb036e5..3b779e8a 100644 --- a/src/gitManager/simpleGit.ts +++ b/src/gitManager/simpleGit.ts @@ -716,7 +716,7 @@ export class SimpleGit extends GitManager { ); } - async setConfig(path: string, value: any): Promise { + async setConfig(path: string, value: string): Promise { if (value == undefined) { await this.git.raw(["config", "--local", "--unset", path]); } else { @@ -724,11 +724,19 @@ export class SimpleGit extends GitManager { } } - async getConfig(path: string): Promise { + async getConfig(path: string): Promise { const config = await this.git.listConfig("local", (err) => this.onError(err) ); - return config.all[path]; + const res = config.all[path]; + if (typeof res === "string") { + return res; + } else { + const error = new Error("Config value is not a string"); + + this.onError(error); + throw error; + } } async fetch(remote?: string): Promise { diff --git a/src/main.ts b/src/main.ts index 347a0399..8e1be309 100644 --- a/src/main.ts +++ b/src/main.ts @@ -221,7 +221,10 @@ export default class ObsidianGit extends Plugin { const branchStatusBarEl = this.addStatusBarItem(); this.branchBar = new BranchStatusBar(branchStatusBarEl, this); this.registerInterval( - window.setInterval(() => this.branchBar?.display(), 60000) + window.setInterval( + () => void this.branchBar?.display().catch(console.error), + 60000 + ) ); } @@ -233,7 +236,7 @@ export default class ObsidianGit extends Plugin { this.debRefresh = debounce( () => { if (this.settings.refreshSourceControl) { - this.refresh(); + this.refresh().catch(console.error); } }, this.settings.refreshSourceControlTimer, @@ -244,9 +247,9 @@ export default class ObsidianGit extends Plugin { async addFileToGitignore(file: TAbstractFile): Promise { await this.app.vault.adapter.append( this.gitManager.getRelativeVaultPath(".gitignore"), - "\n" + this.gitManager.getRelativeRepoPath(file!.path, true) + "\n" + this.gitManager.getRelativeRepoPath(file.path, true) ); - this.refresh(); + return this.refresh(); } handleFileMenu(menu: Menu, file: TAbstractFile, source: string): void { @@ -303,7 +306,9 @@ export default class ObsidianGit extends Plugin { .setIcon("file-x") .setSection("action") .onClick((_) => { - this.addFileToGitignore(file); + this.addFileToGitignore(file).catch((e) => + this.displayError(e) + ); }); }); } @@ -314,7 +319,9 @@ export default class ObsidianGit extends Plugin { .setIcon("file-x") .setSection("action") .onClick((_) => { - this.addFileToGitignore(file); + this.addFileToGitignore(file).catch((e) => + this.displayError(e) + ); }); }); } @@ -359,10 +366,6 @@ export default class ObsidianGit extends Plugin { } onunload() { - (this.app.workspace as any).unregisterHoverLinkSource( - SOURCE_CONTROL_VIEW_CONFIG.type - ); - this.unloadPlugin(); console.log("unloading " + this.manifest.name + " plugin"); @@ -440,7 +443,7 @@ export default class ObsidianGit extends Plugin { this.registerEvent(this.createEvent); this.registerEvent(this.renameEvent); - this.branchBar?.display(); + await this.branchBar?.display(); this.lineAuthoringFeature.conditionallyActivateBySettings(); @@ -457,6 +460,7 @@ export default class ObsidianGit extends Plugin { default: this.log( "Something weird happened. The 'checkRequirements' result is " + + /* eslint-disable-next-line @typescript-eslint/restrict-plus-operands */ result ); } @@ -553,14 +557,14 @@ export default class ObsidianGit extends Plugin { await this.gitManager.clone(url, dir, depthInt); } catch (error) { this.settings.basePath = oldBase; - this.saveSettings(); + await this.saveSettings(); throw error; } new Notice("Cloned new repo."); new Notice("Please restart Obsidian"); if (customDir) { - this.saveSettings(); + await this.saveSettings(); } } } @@ -582,7 +586,7 @@ export default class ObsidianGit extends Plugin { if (!(await this.isAllInitialized())) return; const filesUpdated = await this.pull(); - this.automaticsManager.setUpAutoCommitAndSync(); + await this.automaticsManager.setUpAutoCommitAndSync(); if (filesUpdated === false) { return; } @@ -598,7 +602,7 @@ export default class ObsidianGit extends Plugin { status.conflicted.length == 1 ? "file" : "files" }` ); - this.handleConflict(status.conflicted); + await this.handleConflict(status.conflicted); } } @@ -674,7 +678,7 @@ export default class ObsidianGit extends Plugin { let unstagedFiles: UnstagedFile[] | undefined; if (this.gitManager instanceof SimpleGit) { - this.mayDeleteConflictFile(); + await this.mayDeleteConflictFile(); status = await this.updateCachedStatus(); //Should not be necessary, but just in case @@ -692,7 +696,7 @@ export default class ObsidianGit extends Plugin { status.conflicted.length == 1 ? "file" : "files" }. Please resolve them and commit per command.` ); - this.handleConflict(status.conflicted); + await this.handleConflict(status.conflicted); return false; } changedFiles = [...status.changed, ...status.staged]; @@ -782,7 +786,7 @@ export default class ObsidianGit extends Plugin { roughly = true; committedFiles = changedFiles.length; } - this.automaticsManager.setUpAutoCommitAndSync(); + await this.automaticsManager.setUpAutoCommitAndSync(); this.displayMessage( `Committed${roughly ? " approx." : ""} ${committedFiles} ${ committedFiles == 1 ? "file" : "files" @@ -807,7 +811,7 @@ export default class ObsidianGit extends Plugin { await this.mayDeleteConflictFile(); // Refresh because of pull - let status: any; + let status: Status; if ( this.gitManager instanceof SimpleGit && (status = await this.updateCachedStatus()).conflicted.length > 0 @@ -817,7 +821,7 @@ export default class ObsidianGit extends Plugin { status.conflicted.length } ${status.conflicted.length == 1 ? "file" : "files"}` ); - this.handleConflict(status.conflicted); + await this.handleConflict(status.conflicted); return false; } else if (this.gitManager instanceof IsomorphicGit && hadConflict) { this.displayError(`Cannot push. You have conflicts`); @@ -930,7 +934,7 @@ export default class ObsidianGit extends Plugin { if (selectedBranch != undefined) { await this.gitManager.checkout(selectedBranch); this.displayMessage(`Switched to ${selectedBranch}`); - this.branchBar?.display(); + await this.branchBar?.display(); return selectedBranch; } } @@ -945,7 +949,7 @@ export default class ObsidianGit extends Plugin { if (branch != undefined && remote != undefined) { await this.gitManager.checkout(branch, remote); this.displayMessage(`Switched to ${selectedBranch}`); - this.branchBar?.display(); + await this.branchBar?.display(); return selectedBranch; } } @@ -959,7 +963,7 @@ export default class ObsidianGit extends Plugin { if (newBranch != undefined) { await this.gitManager.createBranch(newBranch); this.displayMessage(`Created new branch ${newBranch}`); - this.branchBar?.display(); + await this.branchBar?.display(); return newBranch; } } @@ -992,7 +996,7 @@ export default class ObsidianGit extends Plugin { } await this.gitManager.deleteBranch(branch, force); this.displayMessage(`Deleted branch ${branch}`); - this.branchBar?.display(); + await this.branchBar?.display(); return branch; } } @@ -1075,7 +1079,7 @@ I strongly recommend to use "Source mode" for viewing the conflicted files. For \`\`\``, ]; } - this.tools.writeAndOpenFile(lines?.join("\n")); + await this.tools.writeAndOpenFile(lines?.join("\n")); } async editRemotes(): Promise { @@ -1146,7 +1150,7 @@ I strongly recommend to use "Source mode" for viewing the conflicted files. For const remoteName = await nameModal.open(); if (remoteName) { - this.gitManager.removeRemote(remoteName); + await this.gitManager.removeRemote(remoteName); } } diff --git a/src/setting/settings.ts b/src/setting/settings.ts index d8b7f6f2..3365e7f0 100644 --- a/src/setting/settings.ts +++ b/src/setting/settings.ts @@ -75,10 +75,10 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { .setValue( plugin.settings.differentIntervalCommitAndPush ) - .onChange((value) => { + .onChange(async (value) => { plugin.settings.differentIntervalCommitAndPush = value; - plugin.saveSettings(); + await plugin.saveSettings(); plugin.automaticsManager.reload("commit", "push"); this.display(); }) @@ -96,11 +96,11 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { .addText((text) => text .setValue(String(plugin.settings.autoSaveInterval)) - .onChange((value) => { + .onChange(async (value) => { if (!isNaN(Number(value))) { plugin.settings.autoSaveInterval = Number(value); - plugin.saveSettings(); + await plugin.saveSettings(); plugin.automaticsManager.reload("commit"); if (plugin.settings.autoSaveInterval > 0) { @@ -134,10 +134,10 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { .addToggle((toggle) => toggle .setValue(plugin.settings.autoBackupAfterFileChange) - .onChange((value) => { + .onChange(async (value) => { plugin.settings.autoBackupAfterFileChange = value; this.display(); - plugin.saveSettings(); + await plugin.saveSettings(); plugin.automaticsManager.reload("commit"); }) ); @@ -156,7 +156,7 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { .setValue(plugin.settings.setLastSaveToLastCommit) .onChange(async (value) => { plugin.settings.setLastSaveToLastCommit = value; - plugin.saveSettings(); + await plugin.saveSettings(); plugin.automaticsManager.reload("commit"); this.display(); }) @@ -174,11 +174,11 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { .addText((text) => text .setValue(String(plugin.settings.autoPushInterval)) - .onChange((value) => { + .onChange(async (value) => { if (!isNaN(Number(value))) { plugin.settings.autoPushInterval = Number(value); - plugin.saveSettings(); + await plugin.saveSettings(); if (plugin.settings.autoPushInterval > 0) { plugin.automaticsManager.reload("push"); @@ -210,11 +210,11 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { .addText((text) => text .setValue(String(plugin.settings.autoPullInterval)) - .onChange((value) => { + .onChange(async (value) => { if (!isNaN(Number(value))) { plugin.settings.autoPullInterval = Number(value); - plugin.saveSettings(); + await plugin.saveSettings(); if (plugin.settings.autoPullInterval > 0) { plugin.automaticsManager.reload("pull"); @@ -242,9 +242,9 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { .addToggle((toggle) => toggle .setValue(plugin.settings.customMessageOnAutoBackup) - .onChange((value) => { + .onChange(async (value) => { plugin.settings.customMessageOnAutoBackup = value; - plugin.saveSettings(); + await plugin.saveSettings(); this.display(); }) ); @@ -259,9 +259,9 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { text .setPlaceholder("vault backup: {{date}}") .setValue(plugin.settings.autoCommitMessage) - .onChange((value) => { + .onChange(async (value) => { plugin.settings.autoCommitMessage = value; - plugin.saveSettings(); + await plugin.saveSettings(); }) ); this.mayDisableSetting( @@ -285,9 +285,9 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { ? plugin.settings.commitMessage : "" ) - .onChange((value) => { + .onChange(async (value) => { plugin.settings.commitMessage = value; - plugin.saveSettings(); + await plugin.saveSettings(); }) ); @@ -311,7 +311,7 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { .addText((text) => text .setValue(plugin.localStorage.getHostname() ?? "") - .onChange(async (value) => { + .onChange((value) => { plugin.localStorage.setHostname(value); }) ); @@ -333,10 +333,10 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { .addToggle((toggle) => toggle .setValue(plugin.settings.listChangedFilesInMessageBody) - .onChange((value) => { + .onChange(async (value) => { plugin.settings.listChangedFilesInMessageBody = value; - plugin.saveSettings(); + await plugin.saveSettings(); }) ); @@ -359,7 +359,7 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { dropdown.onChange(async (option: SyncMethod) => { plugin.settings.syncMethod = option; - plugin.saveSettings(); + await plugin.saveSettings(); }); }); @@ -369,9 +369,9 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { .addToggle((toggle) => toggle .setValue(plugin.settings.autoPullOnBoot) - .onChange((value) => { + .onChange(async (value) => { plugin.settings.autoPullOnBoot = value; - plugin.saveSettings(); + await plugin.saveSettings(); }) ); @@ -390,9 +390,9 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { .addToggle((toggle) => toggle .setValue(!plugin.settings.disablePush) - .onChange((value) => { + .onChange(async (value) => { plugin.settings.disablePush = !value; - plugin.saveSettings(); + await plugin.saveSettings(); }) ); @@ -404,9 +404,9 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { .addToggle((toggle) => toggle .setValue(plugin.settings.pullBeforePush) - .onChange((value) => { + .onChange(async (value) => { plugin.settings.pullBeforePush = value; - plugin.saveSettings(); + await plugin.saveSettings(); }) ); @@ -434,8 +434,8 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { dropdown.setValue(plugin.settings.authorInHistoryView); dropdown.onChange(async (option: ShowAuthorInHistoryView) => { plugin.settings.authorInHistoryView = option; - plugin.saveSettings(); - plugin.refresh(); + await plugin.saveSettings(); + await plugin.refresh(); }); }); @@ -447,10 +447,10 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { .addToggle((toggle) => toggle .setValue(plugin.settings.dateInHistoryView) - .onChange((value) => { + .onChange(async (value) => { plugin.settings.dateInHistoryView = value; - plugin.saveSettings(); - plugin.refresh(); + await plugin.saveSettings(); + await plugin.refresh(); }) ); @@ -466,9 +466,9 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { .addToggle((toggle) => toggle .setValue(plugin.settings.refreshSourceControl) - .onChange((value) => { + .onChange(async (value) => { plugin.settings.refreshSourceControl = value; - plugin.saveSettings(); + await plugin.saveSettings(); }) ); @@ -483,12 +483,12 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { plugin.settings.refreshSourceControlTimer.toString() ) .setPlaceholder("7000") - .onChange((value) => { + .onChange(async (value) => { plugin.settings.refreshSourceControlTimer = Math.max( parseInt(value), 500 ); - plugin.saveSettings(); + await plugin.saveSettings(); plugin.setRefreshDebouncer(); }) ); @@ -502,10 +502,10 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { .addToggle((toggle) => toggle .setValue(plugin.settings.disablePopups) - .onChange((value) => { + .onChange(async (value) => { plugin.settings.disablePopups = value; this.display(); - plugin.saveSettings(); + await plugin.saveSettings(); }) ); @@ -518,9 +518,9 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { .addToggle((toggle) => toggle .setValue(plugin.settings.disablePopupsForNoChanges) - .onChange((value) => { + .onChange(async (value) => { plugin.settings.disablePopupsForNoChanges = value; - plugin.saveSettings(); + await plugin.saveSettings(); }) ); @@ -532,9 +532,9 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { .addToggle((toggle) => toggle .setValue(plugin.settings.showStatusBar) - .onChange((value) => { + .onChange(async (value) => { plugin.settings.showStatusBar = value; - plugin.saveSettings(); + await plugin.saveSettings(); }) ); @@ -543,9 +543,9 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { .addToggle((toggle) => toggle .setValue(plugin.settings.showFileMenu) - .onChange((value) => { + .onChange(async (value) => { plugin.settings.showFileMenu = value; - plugin.saveSettings(); + await plugin.saveSettings(); }) ); @@ -557,9 +557,9 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { .addToggle((toggle) => toggle .setValue(plugin.settings.showBranchStatusBar) - .onChange((value) => { + .onChange(async (value) => { plugin.settings.showBranchStatusBar = value; - plugin.saveSettings(); + await plugin.saveSettings(); }) ); @@ -568,9 +568,9 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { .addToggle((toggle) => toggle .setValue(plugin.settings.changedFilesInStatusBar) - .onChange((value) => { + .onChange(async (value) => { plugin.settings.changedFilesInStatusBar = value; - plugin.saveSettings(); + await plugin.saveSettings(); }) ); @@ -614,8 +614,8 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { .setName("Author name for commit") .addText(async (cb) => { cb.setValue(await plugin.gitManager.getConfig("user.name")); - cb.onChange((value) => { - plugin.gitManager.setConfig( + cb.onChange(async (value) => { + await plugin.gitManager.setConfig( "user.name", value == "" ? undefined : value ); @@ -629,8 +629,8 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { cb.setValue( await plugin.gitManager.getConfig("user.email") ); - cb.onChange((value) => { - plugin.gitManager.setConfig( + cb.onChange(async (value) => { + await plugin.gitManager.setConfig( "user.email", value == "" ? undefined : value ); @@ -653,9 +653,9 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { .addToggle((toggle) => toggle .setValue(plugin.settings.updateSubmodules) - .onChange((value) => { + .onChange(async (value) => { plugin.settings.updateSubmodules = value; - plugin.saveSettings(); + await plugin.saveSettings(); }) ); if (plugin.settings.updateSubmodules) { @@ -667,10 +667,10 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { .addToggle((toggle) => toggle .setValue(plugin.settings.submoduleRecurseCheckout) - .onChange((value) => { + .onChange(async (value) => { plugin.settings.submoduleRecurseCheckout = value; - plugin.saveSettings(); + await plugin.saveSettings(); }) ); } @@ -721,8 +721,8 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { .addButton((cb) => { cb.setButtonText("Reload"); cb.setCta(); - cb.onClick(() => { - (plugin.gitManager as SimpleGit).setGitInstance(); + cb.onClick(async () => { + await (plugin.gitManager as SimpleGit).setGitInstance(); }); }); @@ -737,9 +737,9 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { .addText((cb) => { cb.setValue(plugin.settings.basePath); cb.setPlaceholder("directory/directory-with-git-repo"); - cb.onChange((value) => { + cb.onChange(async (value) => { plugin.settings.basePath = value; - plugin.saveSettings(); + await plugin.saveSettings(); plugin.gitManager.updateBasePath(value || ""); }); }); @@ -752,9 +752,9 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { .addText((cb) => { cb.setValue(plugin.settings.gitDir); cb.setPlaceholder(".git"); - cb.onChange((value) => { + cb.onChange(async (value) => { plugin.settings.gitDir = value; - plugin.saveSettings(); + await plugin.saveSettings(); }); }); @@ -796,8 +796,8 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { const debugButton = debugDiv.createEl("button"); debugButton.setText("Copy Debug Information"); - debugButton.onclick = () => { - window.navigator.clipboard.writeText( + debugButton.onclick = async () => { + await window.navigator.clipboard.writeText( JSON.stringify( { settings: this.plugin.settings, @@ -838,7 +838,7 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { public configureLineAuthorShowStatus(show: boolean) { this.settings.lineAuthor.show = show; - this.plugin.saveSettings(); + void this.plugin.saveSettings(); if (show) this.plugin.lineAuthoringFeature.activateFeature(); else this.plugin.lineAuthoringFeature.deactivateFeature(); @@ -848,11 +848,11 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { * Persists the setting {@link key} with value {@link value} and * refreshes the line author info views. */ - public lineAuthorSettingHandler< + public async lineAuthorSettingHandler< K extends keyof ObsidianGitSettings["lineAuthor"], - >(key: K, value: ObsidianGitSettings["lineAuthor"][K]) { + >(key: K, value: ObsidianGitSettings["lineAuthor"][K]): Promise { this.settings.lineAuthor[key] = value; - this.plugin.saveSettings(); + await this.plugin.saveSettings(); this.plugin.lineAuthoringFeature.refreshLineAuthorViews(); } @@ -925,7 +925,7 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { .setName("Show commit hash") .addToggle((tgl) => { tgl.setValue(this.settings.lineAuthor.showCommitHash); - tgl.onChange(async (value: boolean) => + tgl.onChange((value: boolean) => this.lineAuthorSettingHandler("showCommitHash", value) ); }); @@ -972,7 +972,7 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { dropdown.onChange( async (value: LineAuthorDateTimeFormatOptions) => { - this.lineAuthorSettingHandler( + await this.lineAuthorSettingHandler( "dateTimeFormatOptions", value ); @@ -994,8 +994,8 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { ); cb.setPlaceholder("YYYY-MM-DD HH:mm"); - cb.onChange((value) => { - this.lineAuthorSettingHandler( + cb.onChange(async (value) => { + await this.lineAuthorSettingHandler( "dateTimeFormatCustomString", value ); @@ -1047,12 +1047,15 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { oldestAgeSetting.addText((text) => { text.setPlaceholder("1y"); text.setValue(this.settings.lineAuthor.coloringMaxAge); - text.onChange((value) => { + text.onChange(async (value) => { const [preview, valid] = this.previewOldestAgeDescriptionHtml(value); oldestAgeSetting.descEl.innerHTML = preview; if (valid) { - this.lineAuthorSettingHandler("coloringMaxAge", value); + await this.lineAuthorSettingHandler( + "coloringMaxAge", + value + ); this.refreshColorSettingsName("oldest"); } }); @@ -1065,8 +1068,11 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { .setName("Text color") .addText((field) => { field.setValue(this.settings.lineAuthor.textColorCss); - field.onChange((value) => { - this.lineAuthorSettingHandler("textColorCss", value); + field.onChange(async (value) => { + await this.lineAuthorSettingHandler( + "textColorCss", + value + ); }); }).descEl.innerHTML = ` The CSS color of the gutter text.
@@ -1117,12 +1123,12 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { ); text.setPlaceholder(rgbToString(defaultColor)); text.setValue(rgbToString(color)); - text.onChange((colorNew) => { + text.onChange(async (colorNew) => { const rgb = convertToRgb(colorNew); if (rgb !== undefined) { const key = which === "newest" ? "colorNew" : "colorOld"; - this.lineAuthorSettingHandler(key, rgb); + await this.lineAuthorSettingHandler(key, rgb); } this.refreshColorSettingsDesc(which, rgb); }); diff --git a/src/ui/history/historyView.ts b/src/ui/history/historyView.ts index f4b3fb0d..db66771e 100644 --- a/src/ui/history/historyView.ts +++ b/src/ui/history/historyView.ts @@ -28,6 +28,7 @@ export default class HistoryView extends ItemView implements HoverParent { } onClose(): Promise { + this._view.$destroy(); return super.onClose(); } diff --git a/src/ui/sourceControl/components/treeComponent.svelte b/src/ui/sourceControl/components/treeComponent.svelte index c15485c7..0c2586c0 100644 --- a/src/ui/sourceControl/components/treeComponent.svelte +++ b/src/ui/sourceControl/components/treeComponent.svelte @@ -16,6 +16,7 @@ export let fileType: FileType; export let topLevel = false; const closed: Record = {}; + /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */ $: side = (view.leaf.getRoot() as any).side == "left" ? "right" : "left"; function stage(path: string) { diff --git a/src/ui/sourceControl/sourceControl.svelte b/src/ui/sourceControl/sourceControl.svelte index 14f26ff2..72fdd3c9 100644 --- a/src/ui/sourceControl/sourceControl.svelte +++ b/src/ui/sourceControl/sourceControl.svelte @@ -41,8 +41,10 @@ setIcon(layoutBtn, showTree ? "list" : "folder"); } } - refreshRef = view.app.workspace.on("obsidian-git:view-refresh", refresh); - refresh(); + refreshRef = view.app.workspace.on("obsidian-git:view-refresh", () => { + refresh().catch(console.error); + }); + refresh().catch(console.error); //This should go in the onMount callback, for some reason it doesn't fire though //setTimeout's callback will execute after the current event loop finishes. plugin.app.workspace.onLayoutReady(() => { @@ -65,18 +67,18 @@ plugin.promiseQueue.addTask(() => plugin.gitManager .commit({ message: commitMessage }) - .then(() => { + .then(async () => { if (commitMessage !== plugin.settings.commitMessage) { commitMessage = ""; } - plugin.automaticsManager.setUpAutoCommitAndSync(); + await plugin.automaticsManager.setUpAutoCommitAndSync(); }) .finally(triggerRefresh) ); } } - async function backup() { + function backup() { loading = true; if (status) { plugin.promiseQueue.addTask(() => @@ -92,7 +94,7 @@ } } - async function refresh() { + async function refresh(): Promise { if (!plugin.gitReady) { status = undefined; return; @@ -222,7 +224,7 @@ }) ); } - }); + }, console.error); } $: rows = (commitMessage.match(/\n/g) || []).length + 1 || 1; @@ -289,7 +291,7 @@ on:click={() => { showTree = !showTree; plugin.settings.treeStructure = showTree; - plugin.saveSettings(); + void plugin.saveSettings(); }} />
{ + this._view.$destroy(); return super.onClose(); } diff --git a/src/utils.ts b/src/utils.ts index 82b3b0a7..6ae94f8f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -55,6 +55,7 @@ export function mayTriggerFileMenu( * During runtime, an error will be thrown, if executed. */ export function impossibleBranch(x: never): never { + /* eslint-disable-next-line @typescript-eslint/restrict-plus-operands */ throw new Error("Impossible branch: " + x); }