Skip to content

Commit

Permalink
Fixed canvas not getting patched bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Developer-Mike committed Mar 21, 2024
1 parent 92997ab commit 98e8582
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions src/core/canvas-patcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,23 @@ export default class CanvasPatcher {
const that = this

// Get the current canvas view or wait for it to be created
const canvasView = this.plugin.getCurrentCanvasView() ?? await new Promise<CanvasView>((resolve) => {
// @ts-ignore
const uninstall = around(this.plugin.app.internalPlugins.plugins.canvas.views, {
canvas: (next: any) => function (...args: any) {
const result = next.call(this, ...args)

resolve(result)
uninstall() // Uninstall the patch

return result
}
const canvasView = (
this.plugin.app.workspace.getLeavesOfType('canvas')?.first()?.view ??
await new Promise<CanvasView>((resolve) => {
// @ts-ignore
const uninstall = around(this.plugin.app.internalPlugins.plugins.canvas.views, {
canvas: (next: any) => function (...args: any) {
const result = next.call(this, ...args)

resolve(result)
uninstall() // Uninstall the patch

return result
}
})
this.plugin.register(uninstall)
})
this.plugin.register(uninstall)
})
) as CanvasView

// Patch canvas view
patchObjectPrototype(this.plugin, canvasView, {
Expand Down

0 comments on commit 98e8582

Please sign in to comment.