|
9 | 9 | } from '@companion-module/base' |
10 | 10 | import type { ActionInstance, HostActionDefinition } from '../context.js' |
11 | 11 | import { ExecuteActionResult } from '../instance.js' |
| 12 | +import { hasAnyOldIsVisibleFunctions } from './util.js' |
12 | 13 |
|
13 | 14 | function convertActionInstanceToEvent(action: ActionInstance): CompanionActionInfo { |
14 | 15 | return { |
@@ -169,25 +170,58 @@ export class ActionManager { |
169 | 170 |
|
170 | 171 | this.#actionDefinitions.clear() |
171 | 172 |
|
172 | | - for (const [actionId, action] of Object.entries(actions)) { |
173 | | - if (action) { |
174 | | - hostActions.push({ |
175 | | - id: actionId, |
176 | | - name: action.name, |
177 | | - description: action.description, |
178 | | - options: action.options, |
179 | | - optionsToMonitorForSubscribe: action.optionsToMonitorForSubscribe, |
180 | | - hasLearn: !!action.learn, |
181 | | - learnTimeout: action.learnTimeout, |
182 | | - hasLifecycleFunctions: !!action.subscribe || !!action.unsubscribe, |
183 | | - }) |
| 173 | + const definitionsWantingOptionsToMonitor: string[] = [] |
| 174 | + const definitionsWithOptionsToIgnore: string[] = [] |
| 175 | + const definitionsWithOldIsVisible: string[] = [] |
184 | 176 |
|
185 | | - // Remember the definition locally |
186 | | - this.#actionDefinitions.set(actionId, action) |
187 | | - } |
| 177 | + for (const [actionId, action] of Object.entries(actions)) { |
| 178 | + if (!action) continue |
| 179 | + |
| 180 | + const hasSubscriptionMethods = !!action.subscribe || !!action.unsubscribe |
| 181 | + |
| 182 | + hostActions.push({ |
| 183 | + id: actionId, |
| 184 | + name: action.name, |
| 185 | + description: action.description, |
| 186 | + options: action.options, |
| 187 | + optionsToMonitorForSubscribe: action.optionsToMonitorForSubscribe, |
| 188 | + hasLearn: !!action.learn, |
| 189 | + learnTimeout: action.learnTimeout, |
| 190 | + hasLifecycleFunctions: hasSubscriptionMethods, |
| 191 | + }) |
| 192 | + |
| 193 | + // Remember the definition locally |
| 194 | + this.#actionDefinitions.set(actionId, action) |
| 195 | + |
| 196 | + // Check for old removed properties |
| 197 | + if (hasSubscriptionMethods && !action.optionsToMonitorForSubscribe) definitionsWithOptionsToIgnore.push(actionId) |
| 198 | + if ('optionsToIgnoreForSubscribe' in action) definitionsWithOptionsToIgnore.push(actionId) |
| 199 | + if (hasAnyOldIsVisibleFunctions(action.options)) definitionsWithOldIsVisible.push(actionId) |
188 | 200 | } |
189 | 201 |
|
190 | 202 | this.#setActionDefinitions(hostActions) |
| 203 | + |
| 204 | + if (definitionsWantingOptionsToMonitor.length > 0) { |
| 205 | + this.#logger.warn( |
| 206 | + `Some actions definitions have a subscribe or unsubscribe method without a optionsToMonitorForSubscribe property. This is not recommended and will cause more calls of those methods than is necessary.\nThe affected actions are: ${definitionsWantingOptionsToMonitor |
| 207 | + .sort() |
| 208 | + .join(', ')}`, |
| 209 | + ) |
| 210 | + } |
| 211 | + if (definitionsWantingOptionsToMonitor.length > 0) { |
| 212 | + this.#logger.warn( |
| 213 | + `The following action definitions have a removed optionsToIgnoreForSubscribe property. Please use optionsToMonitorForSubscribe instead: ${definitionsWithOptionsToIgnore |
| 214 | + .sort() |
| 215 | + .join(', ')}`, |
| 216 | + ) |
| 217 | + } |
| 218 | + if (definitionsWithOldIsVisible.length > 0) { |
| 219 | + this.#logger.warn( |
| 220 | + `The following action definitions have options with the old isVisible functions. These should be replaced with isVisibleExpression to continue to operate. The definitions: ${definitionsWithOldIsVisible |
| 221 | + .sort() |
| 222 | + .join(', ')}`, |
| 223 | + ) |
| 224 | + } |
191 | 225 | } |
192 | 226 |
|
193 | 227 | subscribeActions(actionIds: string[]): void { |
|
0 commit comments