()
| 121 | } |
| 122 | |
| 123 | static override async onLoad(): Promise<void> { |
| 124 | const mediaPlayers = Object.keys(this.engine.mediaPlayers()); |
| 125 | const promises: Promise<unknown>[] = []; |
| 126 | const pausedMedia: { type: string; media: string }[] = []; |
| 127 | |
| 128 | for (const mediaType of mediaPlayers) { |
| 129 | const state = this.engine.state(mediaType as keyof import('../lib/types').StateMap) as MediaStateItem[] | undefined; |
| 130 | |
| 131 | if (typeof state !== 'undefined' && Array.isArray(state)) { |
| 132 | if (state.length > 0) { |
| 133 | for (const s of state) { |
| 134 | const action = this.engine.prepareAction(s.statement, { cycle: 'Application' }) as ActionInstance | null; |
| 135 | if (action !== null) { |
| 136 | const promise = action.willApply().then(() => { |
| 137 | return action.apply().then(() => { |
| 138 | return action.didApply({ updateHistory: false, updateState: false }); |
| 139 | }); |
| 140 | }); |
| 141 | |
| 142 | promises.push(promise); |
| 143 | |
| 144 | // Track media that should be paused after restore |
| 145 | if (s.paused) { |
| 146 | const parts = s.statement.split(' '); |
| 147 | // Statement format: "play <type> <media> [options]" |
| 148 | if (parts.length >= 3) { |
| 149 | pausedMedia.push({ type: parts[1], media: parts[2] }); |
| 150 | } |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | if (promises.length > 0) { |
| 159 | await Promise.all(promises); |
| 160 | } |
| 161 | |
| 162 | // Restore paused state for media that was paused when saved |
| 163 | for (const { type, media } of pausedMedia) { |
| 164 | const player = this.engine.mediaPlayer(type, media); |
| 165 | player?.pause(); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | static override async reset(): Promise<void> { |
| 170 | const players = this.engine.mediaPlayers(); |
no test coverage detected