diff --git a/README.md b/README.md index e4606df..ca7a509 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/main.ts b/main.ts index 54f485e..c757483 100644 --- a/main.ts +++ b/main.ts @@ -1,4 +1,4 @@ -import { App, Plugin, PluginSettingTab, Setting } from 'obsidian'; +import { App, Plugin, PluginSettingTab, Setting, type SettingDefinitionItem } from 'obsidian'; interface DoubleSwitchSettings { myDarkModeThemeName: string; @@ -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(); + + 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; @@ -115,6 +153,16 @@ class MySettingTab extends PluginSettingTab { }); } + private buildThemeOptions(): Record { + const themeOptions: Record = { + [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]; diff --git a/manifest-beta.json b/manifest-beta.json deleted file mode 100644 index 21dd4e6..0000000 --- a/manifest-beta.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "id": "double-switch", - "name": "Auto switch themes between dark/light mode", - "version": "0.7.0", - "minAppVersion": "0.15.0", - "description": "Toggling dark/light mode switches themes automatically", - "author": "Robert Storlind", - "authorUrl": "https://github.com/carlrobert", - "isDesktopOnly": false -} diff --git a/manifest.json b/manifest.json index 38a0019..5f8f83a 100644 --- a/manifest.json +++ b/manifest.json @@ -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 diff --git a/package-lock.json b/package-lock.json index 50ef601..be70b36 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,24 +13,32 @@ "@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" } }, "node_modules/@codemirror/state": { - "version": "6.4.1", + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/@codemirror/state/-/state-6.5.0.tgz", + "integrity": "sha512-MwBHVK60IiIHDcoMet78lxt6iw5gJOGSbNbOIVBHWVXIH4/Nq1+GQgLLGgI1KlnN86WDXsPudVaqYHKBIx7Eyw==", "dev": true, "license": "MIT", - "peer": true + "peer": true, + "dependencies": { + "@marijn/find-cluster-break": "^1.0.0" + } }, "node_modules/@codemirror/view": { - "version": "6.34.2", + "version": "6.38.6", + "resolved": "https://registry.npmjs.org/@codemirror/view/-/view-6.38.6.tgz", + "integrity": "sha512-qiS0z1bKs5WOvHIAC0Cybmv4AJSkAXgX5aD6Mqd2epSLlVJsQl8NG23jCVouIgkh4All/mrbdsf2UOLFnJw0tw==", "dev": true, "license": "MIT", "peer": true, "dependencies": { - "@codemirror/state": "^6.4.0", + "@codemirror/state": "^6.5.0", + "crelt": "^1.0.6", "style-mod": "^4.1.0", "w3c-keyname": "^2.2.4" } @@ -545,6 +553,13 @@ "dev": true, "license": "BSD-3-Clause" }, + "node_modules/@marijn/find-cluster-break": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@marijn/find-cluster-break/-/find-cluster-break-1.0.3.tgz", + "integrity": "sha512-FY+MKLBoTsLNJF/eLWaOsXGdz6uh3Iu1axjPf6TUq92IYumcTcXWHoS747JARLkcdlJ/Waiaxc5wQfFO8jC6NA==", + "dev": true, + "license": "MIT" + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "dev": true, @@ -811,7 +826,9 @@ } }, "node_modules/ajv": { - "version": "6.12.6", + "version": "6.15.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.15.0.tgz", + "integrity": "sha512-fgFx7Hfoq60ytK2c7DhnF8jIvzYgOMxfugjLOSMHjLIPgenqa7S7oaagATUq99mV6IYvN2tRmC0wnTYX6iPbMw==", "dev": true, "license": "MIT", "dependencies": { @@ -866,7 +883,9 @@ "license": "MIT" }, "node_modules/brace-expansion": { - "version": "1.1.11", + "version": "1.1.16", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.16.tgz", + "integrity": "sha512-IDw48K2/2kRkg9LdJxurvq3lV3aBgq0REY89duEqFRthjlPdXHKMj7EnQOXVckxzgisinf3nHfrcE2FufFLXMw==", "dev": true, "license": "MIT", "dependencies": { @@ -929,6 +948,13 @@ "dev": true, "license": "MIT" }, + "node_modules/crelt": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/crelt/-/crelt-1.0.7.tgz", + "integrity": "sha512-aK6BbWfhf4U/wCcLHKPJl/xa6VkVstRaPywWtMKGwuOLc/wZTyQYuoxgvZnNsBvv7Kg3YTBQYYBCggcviQczuA==", + "dev": true, + "license": "MIT" + }, "node_modules/cross-spawn": { "version": "7.0.5", "dev": true, @@ -1333,7 +1359,9 @@ } }, "node_modules/flatted": { - "version": "3.3.1", + "version": "3.4.3", + "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.4.3.tgz", + "integrity": "sha512-/zipXxyO6rGvuNGDiULY9MvEGSkb2gaG4GGH4ygMi0ZZzyMHdUZBmntJmx5x1G2VuPytCwGN4xsJP6cw+sK+vQ==", "dev": true, "license": "ISC" }, @@ -1509,8 +1537,20 @@ "license": "ISC" }, "node_modules/js-yaml": { - "version": "4.1.0", + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.3.0.tgz", + "integrity": "sha512-1td788aAnnZ5qs7V2QIRl1owjtYpbKt749Y3xauqQgwIIGF/xXWz1wMTEBx5O3LK3lXLVuqXPdPxj2BoFHaW9Q==", "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/puzrin" + }, + { + "type": "github", + "url": "https://github.com/sponsors/nodeca" + } + ], "license": "MIT", "dependencies": { "argparse": "^2.0.1" @@ -1594,7 +1634,9 @@ } }, "node_modules/minimatch": { - "version": "3.1.2", + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.5.tgz", + "integrity": "sha512-VgjWUsnnT6n+NUk6eZq77zeFdpW2LWDzP6zFGrCbHXiYNul5Dzqk2HHQ5uFH2DNW5Xbp8+jVzaeNt94ssEEl4w==", "dev": true, "license": "ISC", "dependencies": { @@ -1623,9 +1665,9 @@ "license": "MIT" }, "node_modules/obsidian": { - "version": "1.7.2", - "resolved": "https://registry.npmjs.org/obsidian/-/obsidian-1.7.2.tgz", - "integrity": "sha512-k9hN9brdknJC+afKr5FQzDRuEFGDKbDjfCazJwpgibwCAoZNYHYV8p/s3mM8I6AsnKrPKNXf8xGuMZ4enWelZQ==", + "version": "1.13.1", + "resolved": "https://registry.npmjs.org/obsidian/-/obsidian-1.13.1.tgz", + "integrity": "sha512-qtTEA2pmhJzhuhJqzbBFRYhpIOqvW+krDYjtFynv66KbxBbumHBlsJfWw3I4jtnK/6fZwbQhCrmmDdRwXmX56w==", "dev": true, "license": "MIT", "dependencies": { @@ -1633,8 +1675,8 @@ "moment": "2.29.4" }, "peerDependencies": { - "@codemirror/state": "^6.0.0", - "@codemirror/view": "^6.0.0" + "@codemirror/state": "6.5.0", + "@codemirror/view": "6.38.6" } }, "node_modules/once": { @@ -1733,7 +1775,9 @@ } }, "node_modules/picomatch": { - "version": "2.3.1", + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.2.tgz", + "integrity": "sha512-V7+vQEJ06Z+c5tSye8S+nHUfI51xoXIXjHQ99cQtKUkQqqO1kO/KCJUfZXuB47h/YBlDhah2H3hdUGXn8ie0oA==", "dev": true, "license": "MIT", "engines": { @@ -1903,7 +1947,9 @@ } }, "node_modules/style-mod": { - "version": "4.1.2", + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/style-mod/-/style-mod-4.1.3.tgz", + "integrity": "sha512-i/n8VsZydrugj3Iuzll8+x/00GH2vnYsk1eomD8QiRrSAeW6ItbCQDtfXCeJHd0iwiNagqjQkvpvREEPtW3IoQ==", "dev": true, "license": "MIT" }, @@ -2003,6 +2049,8 @@ }, "node_modules/w3c-keyname": { "version": "2.2.8", + "resolved": "https://registry.npmjs.org/w3c-keyname/-/w3c-keyname-2.2.8.tgz", + "integrity": "sha512-dpojBhNsCNN7T82Tm7k26A6G9ML3NkhDsnw9n/eoxSRlVBB4CEtIQ/KTCLI2Fwf3ataSXRhYFkQi3SlnFwPvPQ==", "dev": true, "license": "MIT" }, diff --git a/package.json b/package.json index c6b67bf..b357fd7 100644 --- a/package.json +++ b/package.json @@ -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" }