feat: add Disable on this device toggle

This commit is contained in:
Violet Hadley 2026-05-22 09:49:19 -04:00
parent 4573972bf8
commit f3379e9931
2 changed files with 39 additions and 2 deletions

View file

@ -60,6 +60,20 @@ const OVERRIDES = {
opposite: buildOverride("tab", {newTabTabGroupPlacement: "opposite"}),
}
const DISABLED_KEY = "open-tab-settings:disabled-on-device";
export function isDisabledOnDevice(): boolean {
return window.localStorage.getItem(DISABLED_KEY) === "true";
}
export function setDisabledOnDevice(value: boolean): void {
if (value) {
window.localStorage.setItem(DISABLED_KEY, "true");
} else {
window.localStorage.removeItem(DISABLED_KEY);
}
}
export default class OpenTabSettingsPlugin extends Plugin {
settings: OpenTabSettingsPluginSettings = {...DEFAULT_SETTINGS};
@ -69,6 +83,10 @@ export default class OpenTabSettingsPlugin extends Plugin {
this.addSettingTab(new OpenTabSettingsPluginSettingTab(this.app, this));
if (isDisabledOnDevice()) {
return;
}
this.registerMonkeyPatches();
this.registerEvent(

View file

@ -1,5 +1,5 @@
import { App, PluginSettingTab, Setting } from 'obsidian';
import OpenTabSettingsPlugin from "./main"
import { App, Notice, PluginSettingTab, Setting } from 'obsidian';
import OpenTabSettingsPlugin, { isDisabledOnDevice, setDisabledOnDevice } from "./main"
export const NEW_TAB_PLACEMENTS = {
"after-active": "After active tab",
@ -50,6 +50,25 @@ export class OpenTabSettingsPluginSettingTab extends PluginSettingTab {
display(): void {
this.containerEl.empty();
new Setting(this.containerEl)
.setName('Disable on this device')
.setDesc(
'When enabled, this plugin does nothing on the current device. ' +
'This setting is per-device and is not synced. Restart Obsidian or toggle the plugin off and on to apply.'
)
.addToggle(toggle =>
toggle
.setValue(isDisabledOnDevice())
.onChange((value) => {
setDisabledOnDevice(value);
new Notice(
`Open Tab Settings will be ${value ? 'disabled' : 'enabled'} on this device after restart.`,
5000,
);
})
);
new Setting(this.containerEl)
.setName('Always open in new tab')
.setDesc('Open files in a new tab by default.')