Skip to content

Commit fc030ef

Browse files
committed
feat: warn about usage of removed properties
1 parent 0c17af0 commit fc030ef

File tree

3 files changed

+101
-30
lines changed

3 files changed

+101
-30
lines changed

packages/companion-module-host/src/internal/actions.ts

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from '@companion-module/base'
1010
import type { ActionInstance, HostActionDefinition } from '../context.js'
1111
import { ExecuteActionResult } from '../instance.js'
12+
import { hasAnyOldIsVisibleFunctions } from './util.js'
1213

1314
function convertActionInstanceToEvent(action: ActionInstance): CompanionActionInfo {
1415
return {
@@ -169,25 +170,58 @@ export class ActionManager {
169170

170171
this.#actionDefinitions.clear()
171172

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[] = []
184176

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)
188200
}
189201

190202
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+
}
191225
}
192226

193227
subscribeActions(actionIds: string[]): void {

packages/companion-module-host/src/internal/feedback.ts

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from '@companion-module/base'
1212
import debounceFn from 'debounce-fn'
1313
import type { FeedbackInstance, HostFeedbackDefinition, HostFeedbackValue } from '../context.js'
14+
import { hasAnyOldIsVisibleFunctions } from './util.js'
1415

1516
function convertFeedbackInstanceToEvent(
1617
type: 'boolean' | 'value' | 'advanced',
@@ -257,26 +258,49 @@ export class FeedbackManager {
257258

258259
this.#feedbackDefinitions.clear()
259260

261+
const definitionsWithSubscribeMethod: string[] = []
262+
const definitionsWithOldIsVisible: string[] = []
263+
260264
for (const [feedbackId, feedback] of Object.entries(feedbacks)) {
261-
if (feedback) {
262-
hostFeedbacks.push({
263-
id: feedbackId,
264-
name: feedback.name,
265-
description: feedback.description,
266-
options: feedback.options,
267-
type: feedback.type,
268-
defaultStyle: feedback.type === 'boolean' ? feedback.defaultStyle : undefined,
269-
hasLearn: !!feedback.learn,
270-
learnTimeout: feedback.learnTimeout,
271-
showInvert: feedback.type === 'boolean' ? feedback.showInvert : false,
272-
})
265+
if (!feedback) continue
266+
267+
hostFeedbacks.push({
268+
id: feedbackId,
269+
name: feedback.name,
270+
description: feedback.description,
271+
options: feedback.options,
272+
type: feedback.type,
273+
defaultStyle: feedback.type === 'boolean' ? feedback.defaultStyle : undefined,
274+
hasLearn: !!feedback.learn,
275+
learnTimeout: feedback.learnTimeout,
276+
showInvert: feedback.type === 'boolean' ? feedback.showInvert : false,
277+
})
273278

274-
// Remember the definition locally
275-
this.#feedbackDefinitions.set(feedbackId, feedback)
276-
}
279+
// Remember the definition locally
280+
this.#feedbackDefinitions.set(feedbackId, feedback)
281+
282+
// Check for old subscribe method
283+
if ('subscribe' in feedback && typeof feedback.subscribe === 'function')
284+
definitionsWithSubscribeMethod.push(feedbackId)
285+
if (hasAnyOldIsVisibleFunctions(feedback.options)) definitionsWithOldIsVisible.push(feedbackId)
277286
}
278287

279288
this.#setFeedbackDefinitions(hostFeedbacks)
289+
290+
if (definitionsWithSubscribeMethod.length > 0) {
291+
this.#logger.warn(
292+
`The following feedback definitions have a subscribe method, which is no longer supported: ${definitionsWithSubscribeMethod
293+
.sort()
294+
.join(', ')}`,
295+
)
296+
}
297+
if (definitionsWithOldIsVisible.length > 0) {
298+
this.#logger.warn(
299+
`The following feedback definitions have options with the old isVisible functions. These should be replaced with isVisibleExpression to continue to operate. The definitions: ${definitionsWithOldIsVisible
300+
.sort()
301+
.join(', ')}`,
302+
)
303+
}
280304
}
281305

282306
checkFeedbacks(feedbackTypes: string[]): void {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { SomeCompanionActionInputField, SomeCompanionFeedbackInputField } from '../main.js'
2+
3+
export function hasAnyOldIsVisibleFunctions(
4+
options: (SomeCompanionActionInputField | SomeCompanionFeedbackInputField)[] | undefined,
5+
): boolean {
6+
if (!options) return false
7+
8+
for (const option of options) {
9+
if ('isVisible' in option && !!option.isVisible) return true
10+
}
11+
12+
return false
13+
}

0 commit comments

Comments
 (0)