Skip to content

Commit

Permalink
feat: disable plugin per device
Browse files Browse the repository at this point in the history
close #301
  • Loading branch information
Vinzent03 committed Sep 7, 2022
1 parent 5818320 commit 82b2c1a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/localStorageSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,12 @@ export class LocalStorageSettings {
setGitPath(value: string): void {
return localStorage.setItem(this.prefix + ":gitPath", value);
}

getPluginDisabled(): boolean {
return localStorage.getItem(this.prefix + ":pluginDisabled") == "true";
}

setPluginDisabled(value: boolean): void {
return localStorage.setItem(this.prefix + ":pluginDisabled", `${value}`);
}
}
11 changes: 9 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ export default class ObsidianGit extends Plugin {
await this.loadSettings();
this.migrateSettings();

this.addSettingTab(new ObsidianGitSettingsTab(this.app, this));

if (!this.localStorage.getPluginDisabled()) {
this.loadPlugin();
}
}

async loadPlugin() {
addEventListener("git-refresh", this.refresh.bind(this));

this.registerView(GIT_VIEW_CONFIG.type, (leaf) => {
Expand All @@ -95,7 +103,6 @@ export default class ObsidianGit extends Plugin {
defaultMod: true,
});

this.addSettingTab(new ObsidianGitSettingsTab(this.app, this));

this.addCommand({
id: 'edit-gitignore',
Expand Down Expand Up @@ -424,7 +431,7 @@ export default class ObsidianGit extends Plugin {
let data: ObsidianGitSettings = await this.loadData();
//Check for existing settings
if (data == undefined) {
data = { showedMobileNotice: true };
data = { showedMobileNotice: true } as any;
}
this.settings = Object.assign({}, DEFAULT_SETTINGS, data);
}
Expand Down
16 changes: 16 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,22 @@ export class ObsidianGitSettingsTab extends PluginSettingTab {
});
});

new Setting(containerEl)
.setName("Disable on this device")
.addToggle((toggle) =>
toggle
.setValue(plugin.localStorage.getPluginDisabled())
.onChange((value) => {
plugin.localStorage.setPluginDisabled(value);
if (value) {
plugin.unloadPlugin();
} else {
plugin.loadPlugin();
}
new Notice("Obsidian must be restarted for the changes to take affect");
})
);


new Setting(containerEl)
.setName('Donate')
Expand Down

0 comments on commit 82b2c1a

Please sign in to comment.