Skip to content

Commit e5bffe0

Browse files
Fixed custom colors not working in multiple windows
1 parent d26d666 commit e5bffe0

15 files changed

+103
-54
lines changed

src/canvas-extensions/collapsible-groups-canvas-extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default class CollapsibleGroupsCanvasExtension {
1212
constructor(plugin: AdvancedCanvasPlugin) {
1313
this.plugin = plugin
1414

15-
if (!this.plugin.settingsManager.getSetting('collapsibleGroupsFeatureEnabled')) return
15+
if (!this.plugin.settings.getSetting('collapsibleGroupsFeatureEnabled')) return
1616

1717
this.plugin.registerEvent(this.plugin.app.workspace.on(
1818
CanvasEvent.CanvasChanged,

src/canvas-extensions/color-palette-canvas-extension.ts

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { WorkspaceWindow } from "obsidian"
12
import { Canvas } from "src/@types/Canvas"
23
import { CanvasEvent } from "src/events/events"
34
import AdvancedCanvasPlugin from "src/main"
@@ -12,11 +13,18 @@ export default class ColorPaletteCanvasExtension {
1213
constructor(plugin: AdvancedCanvasPlugin) {
1314
this.plugin = plugin
1415

16+
this.plugin.registerEvent(this.plugin.app.workspace.on(
17+
'advanced-canvas:window-open',
18+
() => this.updateCustomColorModStyleClasses()
19+
))
20+
1521
this.plugin.registerEvent(this.plugin.app.workspace.on(
1622
'css-change',
1723
() => this.updateCustomColorModStyleClasses()
1824
))
1925

26+
this.updateCustomColorModStyleClasses()
27+
2028
this.plugin.registerEvent(this.plugin.app.workspace.on(
2129
CanvasEvent.PopupMenuCreated,
2230
(canvas: Canvas) => this.patchColorSelection(canvas)
@@ -26,19 +34,22 @@ export default class ColorPaletteCanvasExtension {
2634
}
2735

2836
private updateCustomColorModStyleClasses() {
29-
document.getElementById(CUSTOM_COLORS_MOD_STYLES_ID)?.remove()
30-
31-
const customColorModStyle = document.createElement('style')
32-
customColorModStyle.id = CUSTOM_COLORS_MOD_STYLES_ID
33-
document.body.appendChild(customColorModStyle)
34-
35-
for (const colorId of this.getCustomColors()) {
36-
// Add mod-canvas-color-<colorId> style to the css
37-
customColorModStyle.innerHTML += `
38-
.mod-canvas-color-${colorId} {
39-
--canvas-color: var(--canvas-color-${colorId});
40-
}
41-
`
37+
const customCss = this.getCustomColors().map((colorId) => `
38+
.mod-canvas-color-${colorId} {
39+
--canvas-color: var(--canvas-color-${colorId});
40+
}
41+
`).join('')
42+
43+
for (const win of this.plugin.windowsManager.windows) {
44+
const doc = win.document
45+
46+
doc.getElementById(CUSTOM_COLORS_MOD_STYLES_ID)?.remove()
47+
48+
const customColorModStyle = doc.createElement('style')
49+
customColorModStyle.id = CUSTOM_COLORS_MOD_STYLES_ID
50+
doc.head.appendChild(customColorModStyle)
51+
52+
customColorModStyle.textContent = customCss
4253
}
4354
}
4455

@@ -58,8 +69,6 @@ export default class ColorPaletteCanvasExtension {
5869
const submenu = canvas.menu.menuEl.querySelector('.canvas-submenu')
5970
if (!submenu) return
6071

61-
this.updateCustomColorModStyleClasses()
62-
6372
const currentNodeColor = canvas.getSelectionData().nodes.map(node => node.color).last()
6473
for (const colorId of this.getCustomColors()) {
6574
const customColorMenuItem = this.createColorMenuItem(canvas, colorId)

src/canvas-extensions/commands-canvas-extension.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default class CommandsCanvasExtension {
1717
constructor(plugin: AdvancedCanvasPlugin) {
1818
this.plugin = plugin
1919

20-
if (!this.plugin.settingsManager.getSetting('commandsFeatureEnabled')) return
20+
if (!this.plugin.settings.getSetting('commandsFeatureEnabled')) return
2121

2222
this.plugin.addCommand({
2323
id: 'create-text-node',
@@ -74,7 +74,7 @@ export default class CommandsCanvasExtension {
7474
if (!sourceNode) return
7575
const sourceNodeData = sourceNode.getData()
7676

77-
const nodeMargin = this.plugin.settingsManager.getSetting('cloneNodeMargin')
77+
const nodeMargin = this.plugin.settings.getSetting('cloneNodeMargin')
7878
const offset = {
7979
x: (sourceNode.width + nodeMargin) * (cloneDirection === 'left' ? -1 : (cloneDirection === 'right' ? 1 : 0)),
8080
y: (sourceNode.height + nodeMargin) * (cloneDirection === 'up' ? -1 : (cloneDirection === 'down' ? 1 : 0))
@@ -97,15 +97,15 @@ export default class CommandsCanvasExtension {
9797
shape: sourceNodeData.shape
9898
})
9999

100-
if (this.plugin.settingsManager.getSetting('zoomToClonedNode'))
100+
if (this.plugin.settings.getSetting('zoomToClonedNode'))
101101
canvas.zoomToBbox(clonedNode.getBBox())
102102
}
103103

104104
private expandNode(canvas: Canvas, expandDirection: Direction) {
105105
const node = canvas.selection.values().next().value
106106
if (!node) return
107107

108-
const expandNodeStepSize = this.plugin.settingsManager.getSetting('expandNodeStepSize')
108+
const expandNodeStepSize = this.plugin.settings.getSetting('expandNodeStepSize')
109109
const expand = {
110110
x: expandDirection === 'left' ? -1 : (expandDirection === 'right' ? 1 : 0),
111111
y: expandDirection === 'up' ? -1 : (expandDirection === 'down' ? 1 : 0)

src/canvas-extensions/edge-data-tagger-canvas-extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default class EdgeDataTaggerCanvasExtension {
2424
const edgeData = edge?.getData()
2525
if (!edgeData) return
2626

27-
for (const dataKey of getExposedEdgeData(this.plugin.settingsManager)) {
27+
for (const dataKey of getExposedEdgeData(this.plugin.settings)) {
2828
const dataValue = edgeData[dataKey]
2929

3030
if (!dataValue) delete edge.path.display.dataset[dataKey]

src/canvas-extensions/edges-style-canvas-extension.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export default class EdgesStyleCanvasExtension {
5353
constructor(plugin: AdvancedCanvasPlugin) {
5454
this.plugin = plugin
5555

56-
if (!this.plugin.settingsManager.getSetting('edgesStylingFeatureEnabled')) return
56+
if (!this.plugin.settings.getSetting('edgesStylingFeatureEnabled')) return
5757

5858
this.plugin.registerEvent(this.plugin.app.workspace.on(
5959
CanvasEvent.PopupMenuCreated,
@@ -176,7 +176,7 @@ export default class EdgesStyleCanvasExtension {
176176
y: (fromPos.y + toPos.y) / 2
177177
}
178178
} else if (pathRouteType === 'a-star') {
179-
if (canvas.isDragging && !this.plugin.settingsManager.getSetting('edgeStylePathfinderPathLiveUpdate')) return
179+
if (canvas.isDragging && !this.plugin.settings.getSetting('edgeStylePathfinderPathLiveUpdate')) return
180180

181181
const nodeBBoxes = [...canvas.nodes.values()]
182182
.filter(node => {
@@ -188,11 +188,11 @@ export default class EdgesStyleCanvasExtension {
188188
return !isGroup && !isOpenPortal
189189
}).map(node => node.getBBox())
190190

191-
const gridResolution = this.plugin.settingsManager.getSetting('edgeStylePathfinderGridResolution')
191+
const gridResolution = this.plugin.settings.getSetting('edgeStylePathfinderGridResolution')
192192
const pathArray = AStarHelper.aStar(fromPos, edge.from.side, toPos, edge.to.side, nodeBBoxes, gridResolution)
193193
if (!pathArray) return // No path found - use default path
194194

195-
const roundedPath = this.plugin.settingsManager.getSetting('edgeStylePathfinderPathRounded')
195+
const roundedPath = this.plugin.settings.getSetting('edgeStylePathfinderPathRounded')
196196
const svgPath = SvgPathHelper.pathArrayToSvgPath(pathArray, roundedPath)
197197

198198
newPath = svgPath

src/canvas-extensions/encapsulate-canvas-extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default class EncapsulateCanvasExtension {
1212
constructor(plugin: AdvancedCanvasPlugin) {
1313
this.plugin = plugin
1414

15-
if (!this.plugin.settingsManager.getSetting('canvasEncapsulationEnabled')) return
15+
if (!this.plugin.settings.getSetting('canvasEncapsulationEnabled')) return
1616

1717
/* Add command to encapsulate selection */
1818
this.plugin.addCommand({

src/canvas-extensions/interaction-tagger-canvas-extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default class InteractionTaggerCanvasExtension {
1818
const interactionEl = canvas.nodeInteractionLayer.interactionEl
1919
if (!interactionEl) return
2020

21-
for (const dataKey of getExposedNodeData(this.plugin.settingsManager)) {
21+
for (const dataKey of getExposedNodeData(this.plugin.settings)) {
2222
const datasetKey = TARGET_NODE_DATASET_PREFIX + dataKey.toString().charAt(0).toUpperCase() + dataKey.toString().slice(1)
2323

2424
const dataValue = node?.getData()[dataKey]

src/canvas-extensions/node-data-tagger-canvas-extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default class NodeDataTaggerCanvasExtension {
2727
const nodeData = node?.getData()
2828
if (!nodeData) return
2929

30-
for (const dataKey of getExposedNodeData(this.plugin.settingsManager)) {
30+
for (const dataKey of getExposedNodeData(this.plugin.settings)) {
3131
const dataValue = nodeData[dataKey]
3232

3333
if (!dataValue) delete node.nodeEl.dataset[dataKey]

src/canvas-extensions/portals-canvas-extension.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default class PortalsCanvasExtension {
1313
constructor(plugin: AdvancedCanvasPlugin) {
1414
this.plugin = plugin
1515

16-
if (!this.plugin.settingsManager.getSetting('portalsFeatureEnabled')) return
16+
if (!this.plugin.settings.getSetting('portalsFeatureEnabled')) return
1717

1818
this.plugin.registerEvent(this.plugin.app.workspace.on(
1919
CanvasEvent.PopupMenuCreated,
@@ -286,7 +286,7 @@ export default class PortalsCanvasExtension {
286286
if (portalNodeData.type !== 'file') continue
287287

288288
// Reset portal size
289-
if (this.plugin.settingsManager.getSetting('maintainClosedPortalSize')) {
289+
if (this.plugin.settings.getSetting('maintainClosedPortalSize')) {
290290
portalNodeData.width = portalNodeData.closedPortalWidth ?? portalNodeData.width
291291
portalNodeData.height = portalNodeData.closedPortalHeight ?? portalNodeData.height
292292
}
@@ -336,7 +336,7 @@ export default class PortalsCanvasExtension {
336336
})))
337337

338338
delete originNodeData.edgesToNodeFromPortal![portalId]
339-
} else if (this.plugin.settingsManager.getSetting('showEdgesIntoDisabledPortals')) {
339+
} else if (this.plugin.settings.getSetting('showEdgesIntoDisabledPortals')) {
340340
// If portal is closed, add alternative edges directly to portal
341341
// But don't delete the edges
342342

src/canvas-extensions/presentation-canvas-extension.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default class PresentationCanvasExtension {
1717
constructor(plugin: any) {
1818
this.plugin = plugin
1919

20-
if (!this.plugin.settingsManager.getSetting('presentationFeatureEnabled')) return
20+
if (!this.plugin.settings.getSetting('presentationFeatureEnabled')) return
2121

2222
this.plugin.addCommand({
2323
id: 'create-new-slide',
@@ -124,7 +124,7 @@ export default class PresentationCanvasExtension {
124124
}
125125

126126
private getSlideSize(): Size {
127-
const slideSizeString = this.plugin.settingsManager.getSetting('defaultSlideSize')
127+
const slideSizeString = this.plugin.settings.getSetting('defaultSlideSize')
128128
const slideSizeArray = slideSizeString.split('x').map((value: string) => parseInt(value))
129129
return { width: slideSizeArray[0], height: slideSizeArray[1] }
130130
}
@@ -146,11 +146,11 @@ export default class PresentationCanvasExtension {
146146
}
147147

148148
private async animateNodeTransition(canvas: Canvas, fromNode: CanvasNode|undefined, toNode: CanvasNode) {
149-
const useCustomZoomFunction = this.plugin.settingsManager.getSetting('zoomToSlideWithoutPadding')
150-
const animationDurationMs = this.plugin.settingsManager.getSetting('slideTransitionAnimationDuration') * 1000
149+
const useCustomZoomFunction = this.plugin.settings.getSetting('zoomToSlideWithoutPadding')
150+
const animationDurationMs = this.plugin.settings.getSetting('slideTransitionAnimationDuration') * 1000
151151

152152
if (animationDurationMs > 0 && fromNode) {
153-
const animationIntensity = this.plugin.settingsManager.getSetting('slideTransitionAnimationIntensity')
153+
const animationIntensity = this.plugin.settings.getSetting('slideTransitionAnimationIntensity')
154154

155155
const currentNodeBBoxEnlarged = BBoxHelper.scaleBBox(fromNode.getBBox(), animationIntensity)
156156
if (useCustomZoomFunction) CanvasHelper.zoomToBBox(canvas, currentNodeBBoxEnlarged)
@@ -193,7 +193,7 @@ export default class PresentationCanvasExtension {
193193
canvas.setReadonly(true)
194194

195195
// Register event handler for keyboard navigation
196-
if (this.plugin.settingsManager.getSetting('useArrowKeysToChangeSlides')) {
196+
if (this.plugin.settings.getSetting('useArrowKeysToChangeSlides')) {
197197
canvas.wrapperEl.onkeydown = (e: any) => {
198198
if (e.key === 'ArrowRight') this.nextNode(canvas)
199199
else if (e.key === 'ArrowLeft') this.previousNode(canvas)

0 commit comments

Comments
 (0)