Skip to content

Commit 98e8582

Browse files
Fixed canvas not getting patched bug
1 parent 92997ab commit 98e8582

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/core/canvas-patcher.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,23 @@ export default class CanvasPatcher {
1717
const that = this
1818

1919
// Get the current canvas view or wait for it to be created
20-
const canvasView = this.plugin.getCurrentCanvasView() ?? await new Promise<CanvasView>((resolve) => {
21-
// @ts-ignore
22-
const uninstall = around(this.plugin.app.internalPlugins.plugins.canvas.views, {
23-
canvas: (next: any) => function (...args: any) {
24-
const result = next.call(this, ...args)
25-
26-
resolve(result)
27-
uninstall() // Uninstall the patch
28-
29-
return result
30-
}
20+
const canvasView = (
21+
this.plugin.app.workspace.getLeavesOfType('canvas')?.first()?.view ??
22+
await new Promise<CanvasView>((resolve) => {
23+
// @ts-ignore
24+
const uninstall = around(this.plugin.app.internalPlugins.plugins.canvas.views, {
25+
canvas: (next: any) => function (...args: any) {
26+
const result = next.call(this, ...args)
27+
28+
resolve(result)
29+
uninstall() // Uninstall the patch
30+
31+
return result
32+
}
33+
})
34+
this.plugin.register(uninstall)
3135
})
32-
this.plugin.register(uninstall)
33-
})
36+
) as CanvasView
3437

3538
// Patch canvas view
3639
patchObjectPrototype(this.plugin, canvasView, {

0 commit comments

Comments
 (0)