Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Choose your themes in the settings.

---

Thanks to user ProudBenzene for suggesting an improvement to the plugin.
Thanks <3 to ProudBenzene and TyceHerrmann for contributing improvements to the plugin.

# Sources
This plugin is based on
Expand Down
50 changes: 49 additions & 1 deletion main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { App, Plugin, PluginSettingTab, Setting } from 'obsidian';
import { App, Plugin, PluginSettingTab, Setting, type SettingDefinitionItem } from 'obsidian';

interface DoubleSwitchSettings {
myDarkModeThemeName: string;
Expand Down Expand Up @@ -71,6 +71,44 @@ class MySettingTab extends PluginSettingTab {
this.plugin = plugin;
}

// 1.13.0+: Obsidian calls this and skips the legacy `display()` implementation below
getSettingDefinitions(): SettingDefinitionItem[] {
const themeOptions = this.buildThemeOptions();

Comment thread
carlrobert marked this conversation as resolved.
return [
{
name: 'Theme to use with dark mode',
desc: 'Pick from your installed themes',
control: {
type: 'dropdown',
key: 'myDarkModeThemeName',
defaultValue: DEFAULT_SETTINGS.myDarkModeThemeName,
options: themeOptions,
},
},
{
name: 'Theme to use with light mode',
desc: 'Pick from your installed themes',
control: {
type: 'dropdown',
key: 'myLightModeThemeName',
defaultValue: DEFAULT_SETTINGS.myLightModeThemeName,
options: themeOptions,
},
},
{
name: 'Check dark/light mode at startup',
desc: 'Useful if "Base color scheme" is set to "Adapt to system"',
control: {
type: 'toggle',
key: 'startupCheck',
defaultValue: DEFAULT_SETTINGS.startupCheck,
},
},
];
}

// < 1.13.0: Obsidian calls this legacy implementation
display(): void {
const { containerEl } = this;

Expand Down Expand Up @@ -115,6 +153,16 @@ class MySettingTab extends PluginSettingTab {
});
}

private buildThemeOptions(): Record<string, string> {
const themeOptions: Record<string, string> = {
[NOSWITCH]: NOSWITCH,
};
for (const key of this.getThemes()) {
themeOptions[key] = this.getThemeNames(key);
}
return themeOptions;
}

getThemes(): string[] {
//@ts-ignore
return [this.DEFAULT_THEME_KEY, ...Object.keys(this.app.customCss.themes), ...this.app.customCss.oldThemes];
Expand Down
10 changes: 0 additions & 10 deletions manifest-beta.json

This file was deleted.

4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"id": "double-switch",
"name": "Auto switch themes between dark and light mode",
"version": "0.9.2",
"version": "0.9.3",
"minAppVersion": "0.15.0",
"description": "Toggling dark/light mode switches themes automatically",
"description": "Toggling dark/light mode switches themes automatically.",
"author": "Robert Storlind",
"authorUrl": "https://github.com/carlrobert",
"isDesktopOnly": false
Expand Down
82 changes: 65 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@typescript-eslint/eslint-plugin": "5.29.0",
"@typescript-eslint/parser": "5.29.0",
"esbuild": "^0.25.0",
"obsidian": "latest",
"obsidian": "^1.13.0",
"tslib": "2.4.0",
"typescript": "4.7.4"
}
Expand Down