Skip to content

Commit

Permalink
Work around theme-switching issue in extra windows
Browse files Browse the repository at this point in the history
Provides a workaround for the issue described in
https://forum.obsidian.md/t/detached-window-doesnt-change-color-scheme-automatically/42642/9
by making secondary windows also listen for theme change events.
  • Loading branch information
pjeby committed Mar 9, 2024
1 parent 0a2ac36 commit b3c61c9
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: ophidian-lib/build@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"id": "pane-relief",
"name": "Pane Relief",
"version": "0.5.2",
"minAppVersion": "1.3.5",
"version": "0.5.3",
"minAppVersion": "1.5.8",
"description": "Per-tab history, hotkeys for pane/tab movement, navigation, sliding workspace, and more",
"author": "PJ Eby",
"authorUrl": "https://github.com/pjeby",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
},
"license": "ISC",
"devDependencies": {
"@ophidian/build": "^1.1.4",
"@ophidian/core": "git://github.com/ophidian-lib/core.git",
"@ophidian/build": "^1.2.1",
"@ophidian/core": "0.0.21",
"monkey-around": "^2.3.0",
"obsidian": "1.2.8"
}
Expand Down
54 changes: 29 additions & 25 deletions pnpm-lock.yaml

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

14 changes: 13 additions & 1 deletion src/Navigator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Menu, Keymap, Component, WorkspaceLeaf, TFile, MenuItem, requireApiVersion, WorkspaceTabs} from 'obsidian';
import {Menu, Keymap, Component, WorkspaceLeaf, TFile, MenuItem, requireApiVersion, WorkspaceTabs, debounce} from 'obsidian';
import {domLeaves, hasTabHistory, History, HistoryEntry} from "./History";
import {PerWindowComponent} from "@ophidian/core";
import {around} from 'monkey-around';
Expand Down Expand Up @@ -31,8 +31,18 @@ declare module "obsidian" {
interface Workspace {
duplicateLeaf(leaf: WorkspaceLeaf, kind: boolean|"window"|"pane"|"tab"): Promise<WorkspaceLeaf>
}
interface App {
adaptToSystemTheme(): void;
}
interface Vault {
getConfig(key: string): any;
}
}

const adaptTheme = debounce(() => {
if (app.vault.getConfig("theme") === "system") app.adaptToSystemTheme();
}, 200, true);

interface FileInfo {
icon: string
title: string
Expand Down Expand Up @@ -142,6 +152,8 @@ export class Navigation extends PerWindowComponent {
return false;
}

this.registerDomEvent(this.win.matchMedia("(prefers-color-scheme: dark)") as any, "change", adaptTheme);

app.workspace.onLayoutReady(() => {
this.addChild(this.back = new Navigator(this, "back", -1));
this.addChild(this.forward = new Navigator(this, "forward", 1));
Expand Down
1 change: 1 addition & 0 deletions versions.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"0.5.3": "1.5.8",
"0.5.2": "1.3.5",
"0.5.1": "1.2.8",
"0.4.2": "0.15.9",
Expand Down

0 comments on commit b3c61c9

Please sign in to comment.