@@ -567,7 +567,7 @@ export default class InitiativeTracker extends Plugin {
567567 )
568568 ) ;
569569 this . registerEvent (
570- app . workspace . on (
570+ this . app . workspace . on (
571571 "initiative-tracker:save-state" ,
572572 async ( state : InitiativeViewState ) => {
573573 this . data . state = state ;
@@ -618,19 +618,22 @@ export default class InitiativeTracker extends Plugin {
618618
619619 async onunload ( ) {
620620 await this . saveSettings ( ) ;
621+
622+ this . app . workspace . detachLeavesOfType ( INITIATIVE_TRACKER_VIEW ) ;
623+ this . app . workspace . detachLeavesOfType ( PLAYER_VIEW_VIEW ) ;
624+ this . app . workspace . detachLeavesOfType ( CREATURE_TRACKER_VIEW ) ;
625+ this . app . workspace . detachLeavesOfType ( BUILDER_VIEW ) ;
626+
621627 this . app . workspace . trigger ( "initiative-tracker:unloaded" ) ;
622628 console . log ( "Initiative Tracker unloaded" ) ;
623629 }
624630
625631 async addTrackerView ( ) {
626- if (
627- this . app . workspace . getLeavesOfType ( INITIATIVE_TRACKER_VIEW ) ?. length
628- ) {
629- return ;
630- }
631- await this . app . workspace . getRightLeaf ( false ) . setViewState ( {
632- type : INITIATIVE_TRACKER_VIEW
633- } ) ;
632+ await this . app . workspace . ensureSideLeaf (
633+ INITIATIVE_TRACKER_VIEW ,
634+ "right" ,
635+ { active : false }
636+ ) ;
634637 }
635638 get builder ( ) {
636639 const leaves = this . app . workspace . getLeavesOfType ( BUILDER_VIEW ) ;
@@ -721,12 +724,12 @@ export default class InitiativeTracker extends Plugin {
721724 }
722725 async openCombatant ( creature : Creature ) {
723726 if ( ! this . canUseStatBlocks ) return ;
724- const view = this . combatant ;
725- if ( ! view ) {
726- const leaf = this . app . workspace . getRightLeaf ( true ) ;
727- await leaf . setViewState ( {
728- type : CREATURE_TRACKER_VIEW
729- } ) ;
727+ if ( ! this . combatant ) {
728+ await this . app . workspace . ensureSideLeaf (
729+ CREATURE_TRACKER_VIEW ,
730+ "right" ,
731+ { active : true }
732+ ) ;
730733 }
731734
732735 await this . combatant . render ( creature ) ;
0 commit comments