Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions companion/lib/Controls/ControlStore.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { SomeControlModel } from '@companion-app/shared/Model/Controls.js'
import type { VariableValues } from '@companion-app/shared/Model/Variables.js'
import type { DataDatabase } from '../Data/Database.js'
import type { DataStoreTableView } from '../Data/StoreBase.js'
import type { VariablesValues } from '../Variables/Values.js'
Expand Down Expand Up @@ -166,15 +165,16 @@ export class ControlStore implements IControlStore {

createVariablesAndExpressionParser(
controlId: string | null | undefined,
overrideVariableValues: VariableValues | null
surfaceId: string | undefined
): VariablesAndExpressionParser {
const control = controlId && this.getControl(controlId)

// If the control exists and supports entities, use its parser for local variables
if (control && control.supportsEntities)
return control.entities.createVariablesAndExpressionParser(overrideVariableValues)
if (control && control.supportsEntities) {
return control.entities.createVariablesAndExpressionParser(surfaceId)
}

// Otherwise create a generic one
return this.#variablesValues.createVariablesAndExpressionParser(null, null, overrideVariableValues)
return this.#variablesValues.createStandaloneParser(surfaceId, null)
}
}
6 changes: 3 additions & 3 deletions companion/lib/Controls/ControlTypes/Button/Base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ export abstract class ButtonControlBase<TJson, TOptions extends ButtonOptionsBas
this.sendRuntimePropsChange.bind(this),
(expression, requiredType) =>
deps.variableValues
.createVariablesAndExpressionParser(
.createParserForControl(
deps.pageStore.getLocationOfControlId(this.controlId),
this.entities.getLocalVariableEntities(),
null
undefined,
this.entities.getLocalVariableEntities()
)
.executeExpression(expression, requiredType),
isLayered
Expand Down
11 changes: 5 additions & 6 deletions companion/lib/Controls/ControlTypes/Button/Layered.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
type ButtonStyleProperties,
type DrawStyleLayeredButtonModel,
} from '@companion-app/shared/Model/StyleModel.js'
import type { VariableValues } from '@companion-app/shared/Model/Variables.js'
import { ConvertSomeButtonGraphicsElementForDrawing } from '../../../Graphics/ConvertGraphicsElements.js'
import { ElementConversionCache } from '../../../Graphics/ElementConversionCache.js'
import type { ImageResult } from '../../../Graphics/ImageResult.js'
Expand Down Expand Up @@ -257,18 +256,18 @@ export class ControlButtonLayered
*/
async getDrawStyle(): Promise<DrawStyleLayeredButtonModel | null> {
// Block out the button text
const injectedVariableValues: VariableValues = {}
const location = this.deps.pageStore.getLocationOfControlId(this.controlId)
if (location) {
// Ensure we don't enter into an infinite loop
// TODO - legacy location variables?
// injectedVariableValues[`internal:b_text_${location.pageNumber}_${location.row}_${location.column}`] = '$RE'
// would mean creating a createParserForLayeredButton that adds them as
// another contextual variables set possibility
}

const parser = this.deps.variableValues.createVariablesAndExpressionParser(
const parser = this.deps.variableValues.createParserForControl(
location,
this.entities.getLocalVariableEntities(),
injectedVariableValues
undefined,
this.entities.getLocalVariableEntities()
)

const locationStr = location ? formatLocation(location) : null
Expand Down
12 changes: 4 additions & 8 deletions companion/lib/Controls/ControlTypes/Button/Preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ export class ControlButtonPreset
this.sendRuntimePropsChange.bind(this),
(expression, requiredType) =>
deps.variableValues
.createVariablesAndExpressionParser(
.createParserForControl(
deps.pageStore.getLocationOfControlId(this.controlId),
null, // This doesn't support local variables
null
undefined,
null // This doesn't support local variables
)
.executeExpression(expression, requiredType),
false
Expand Down Expand Up @@ -237,11 +237,7 @@ export class ControlButtonPreset
* @returns the processed style of the button
*/
async getDrawStyle(): Promise<DrawStyleLayeredButtonModel | null> {
const parser = this.deps.variableValues.createVariablesAndExpressionParser(
null,
this.entities.getLocalVariableEntities(),
null
)
const parser = this.deps.variableValues.createStandaloneParser(undefined, this.entities.getLocalVariableEntities())

const feedbackOverrides = this.entities.getFeedbackStyleOverrides()

Expand Down
2 changes: 1 addition & 1 deletion companion/lib/Controls/ControlTypes/PageButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export abstract class ControlButtonPage<TJson>
*/
async getDrawStyle(): Promise<DrawStyleLayeredButtonModel | null> {
const location = this.deps.pageStore.getLocationOfControlId(this.controlId)
const parser = this.deps.variableValues.createVariablesAndExpressionParser(location, null, null)
const parser = this.deps.variableValues.createParserForControl(location, undefined, null)

const { drawType, elements: rawElements } = this.getDrawElements()

Expand Down
2 changes: 1 addition & 1 deletion companion/lib/Controls/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,6 @@ export class ControlsController {
}

createVariablesAndExpressionParser(controlId: string | null | undefined): VariablesAndExpressionParser {
return this.#store.createVariablesAndExpressionParser(controlId, null)
return this.#store.createVariablesAndExpressionParser(controlId, undefined)
}
}
10 changes: 3 additions & 7 deletions companion/lib/Controls/Entities/EntityListPoolBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export abstract class ControlEntityListPoolBase {

this.#specialExpressionManager = new EntityPoolSpecialExpressionManager(
props.controlId,
this.createVariablesAndExpressionParser.bind(this),
this.createVariablesAndExpressionParser.bind(this, undefined),
{
isInverted: this.updateIsInvertedValues.bind(this),
storeResult: this.updateStoreResultValues.bind(this),
Expand Down Expand Up @@ -174,15 +174,11 @@ export abstract class ControlEntityListPoolBase {
})
}

createVariablesAndExpressionParser(overrideVariableValues: VariableValues | null): VariablesAndExpressionParser {
createVariablesAndExpressionParser(surfaceId: string | undefined): VariablesAndExpressionParser {
const controlLocation = this.#pageStore.getLocationOfControlId(this.controlId)
const variableEntities = this.getLocalVariableEntities()

return this.#variableValues.createVariablesAndExpressionParser(
controlLocation,
variableEntities,
overrideVariableValues
)
return this.#variableValues.createParserForControl(controlLocation, surfaceId, variableEntities)
}

/**
Expand Down
3 changes: 1 addition & 2 deletions companion/lib/Controls/IControlStore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { VariableValues } from '@companion-app/shared/Model/Variables.js'
import type { VariablesAndExpressionParser } from '../Variables/VariablesAndExpressionParser.js'
import type { NewFeedbackValue } from './Entities/Types.js'
import type { SomeControl } from './IControlFragments.js'
Expand Down Expand Up @@ -47,7 +46,7 @@ export interface IControlStore {

createVariablesAndExpressionParser(
controlId: string | null | undefined,
overrideVariableValues: VariableValues | null
surfaceId: string | undefined
): VariablesAndExpressionParser

/**
Expand Down
2 changes: 1 addition & 1 deletion companion/lib/ImportExport/Backups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ export class BackupController {
await fs.mkdir(backupDir, { recursive: true })

// Generate backup filename
const parser = this.#variableValuesController.createVariablesAndExpressionParser(null, null, null)
const parser = this.#variableValuesController.createStandaloneParser(undefined, null)
const backupName = parser.parseVariables(rule.backupNamePattern).text
if (!backupName) {
logger.info('No backup name generated, skipping backup')
Expand Down
2 changes: 1 addition & 1 deletion companion/lib/ImportExport/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ export class ImportExportController {
return null
}

const parser = this.#variablesController.values.createVariablesAndExpressionParser(null, null, null)
const parser = this.#variablesController.values.createStandaloneParser(undefined, null)

// Compute the new drawing
const { elements } = await ConvertSomeButtonGraphicsElementForDrawing(
Expand Down
2 changes: 1 addition & 1 deletion companion/lib/ImportExport/Export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ export class ExportController {
#generateFilename(filename: string, exportType: string, fileExt: string): string {
//If the user isn't using their default file name, don't append any extra info in file name since it was a manual choice
const useDefault = filename == this.#userConfigController.getKey('default_export_filename')
const parser = this.#variablesController.values.createVariablesAndExpressionParser(null, null, null)
const parser = this.#variablesController.values.createStandaloneParser(undefined, null)
const parsedName = parser.parseVariables(filename).text

return parsedName && parsedName !== 'undefined'
Expand Down
4 changes: 2 additions & 2 deletions companion/lib/Instance/Connection/ChildHandlerLegacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ export class ConnectionChildHandlerLegacy implements ChildProcessHandlerBase, Co
if (!actionDefinition) throw new Error(`Failed to find action definition for ${action.definitionId}`)

// Note: for actions, this doesn't need to be reactive
const parser = this.#deps.controls.createVariablesAndExpressionParser(extras.controlId, null)
const parser = this.#deps.controls.createVariablesAndExpressionParser(extras.controlId, undefined)
const parseRes = parser.parseEntityOptions(actionDefinition, action.options)
Comment thread
jswalden marked this conversation as resolved.
if (!parseRes.ok) {
this.logger.warn(
Expand Down Expand Up @@ -938,7 +938,7 @@ export class ConnectionChildHandlerLegacy implements ChildProcessHandlerBase, Co
msg: ParseVariablesInStringMessage
): Promise<ParseVariablesInStringResponseMessage> {
try {
const parser = this.#deps.controls.createVariablesAndExpressionParser(msg.controlId, null)
const parser = this.#deps.controls.createVariablesAndExpressionParser(msg.controlId, undefined)
const result = parser.parseVariables(msg.text)

return {
Expand Down
4 changes: 2 additions & 2 deletions companion/lib/Instance/Connection/ChildHandlerNew.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ export class ConnectionChildHandlerNew implements ChildProcessHandlerBase, Conne
}
const learnTimeout = entityDefinition.learnTimeout

const parser = this.#deps.controls.createVariablesAndExpressionParser(controlId, null)
const parser = this.#deps.controls.createVariablesAndExpressionParser(controlId, undefined)
const parseRes = parser.parseEntityOptions(entityDefinition, entity.options)
if (!parseRes.ok) {
this.logger.warn(
Expand Down Expand Up @@ -376,7 +376,7 @@ export class ConnectionChildHandlerNew implements ChildProcessHandlerBase, Conne
if (!actionDefinition) throw new Error(`Failed to find action definition for ${action.definitionId}`)

// Note: for actions, this doesn't need to be reactive
const parser = this.#deps.controls.createVariablesAndExpressionParser(extras.controlId, null)
const parser = this.#deps.controls.createVariablesAndExpressionParser(extras.controlId, undefined)
const parseRes = parser.parseEntityOptions(actionDefinition, action.options)
Comment thread
jswalden marked this conversation as resolved.
if (!parseRes.ok) {
let location = 'Unknown'
Expand Down
2 changes: 1 addition & 1 deletion companion/lib/Instance/Connection/EntityManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export class ConnectionEntityManager {
let updateOptions: CompanionOptionValues | undefined
try {
// Parse the options and track the variables referenced
const parser = this.controlsStore.createVariablesAndExpressionParser(wrapper.controlId, null)
const parser = this.controlsStore.createVariablesAndExpressionParser(wrapper.controlId, undefined)
const parseRes = parser.parseEntityOptions(entityDefinition, entityModel.options)
if (!parseRes.ok) {
this.#logger.warn(
Expand Down
9 changes: 3 additions & 6 deletions companion/lib/Internal/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
type SomeEntityModel,
} from '@companion-app/shared/Model/EntityModel.js'
import { convertExpressionOptionsWithoutParsing } from '@companion-app/shared/Model/Options.js'
import type { VariableValue, VariableValues } from '@companion-app/shared/Model/Variables.js'
import type { VariableValue } from '@companion-app/shared/Model/Variables.js'
import { stringifyError } from '@companion-app/shared/Stringify.js'
import { assertNever } from '@companion-app/shared/Util.js'
import type { CompanionOptionValues, Complete } from '@companion-module/base'
Expand Down Expand Up @@ -315,7 +315,7 @@ export class InternalController {
return undefined
}

const parser = this.#controlsStore.createVariablesAndExpressionParser(feedbackState.controlId, null)
const parser = this.#controlsStore.createVariablesAndExpressionParser(feedbackState.controlId, undefined)

// Parse the options if enabled
let parsedOptions: CompanionOptionValues
Expand Down Expand Up @@ -462,10 +462,7 @@ export class InternalController {
)
if (!entityDefinition) return

const overrideVariableValues: VariableValues = {
'this:surface_id': extras.surfaceId,
}
const parser = this.#controlsStore.createVariablesAndExpressionParser(extras.controlId, overrideVariableValues)
const parser = this.#controlsStore.createVariablesAndExpressionParser(extras.controlId, extras.surfaceId)

let parsedOptions: CompanionOptionValues
if (entityDefinition.optionsSupportExpressions) {
Expand Down
26 changes: 2 additions & 24 deletions companion/lib/Surface/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ import type {
SurfacePanelConfig,
SurfacesUpdate,
} from '@companion-app/shared/Model/Surfaces.js'
import type { VariableValues } from '@companion-app/shared/Model/Variables.js'
import { stringifyError } from '@companion-app/shared/Stringify.js'
import { VARIABLE_UNKNOWN_VALUE } from '@companion-app/shared/Variables.js'
import type { Complete } from '@companion-module/base'
import type { HIDDevice } from '@companion-surface/host'
import type { DataDatabase } from '../Data/Database.js'
Expand Down Expand Up @@ -1415,32 +1413,12 @@ export class SurfaceController extends EventEmitter<SurfaceControllerEvents> {
}

surfaceExecuteExpression(str: string, surfaceId: string): ExecuteExpressionResult {
const parser = this.#handlerDependencies.variables.values.createVariablesAndExpressionParser(
null,
null,
this.#getInjectedVariablesForSurfaceId(surfaceId)
)
const surfacePageNumber = this.devicePageGet(surfaceId)
const parser = this.#handlerDependencies.variables.values.createParserForSurface(surfaceId, surfacePageNumber)

return parser.executeExpression(str, undefined)
}

/**
* Variables to inject based on location
*/
#getInjectedVariablesForSurfaceId(surfaceId: string): VariableValues {
const pageNumber = this.devicePageGet(surfaceId)

return {
'this:surface_id': surfaceId,

// Reactivity is triggered manually
'this:page': pageNumber,

// Reactivity happens for these because of references to the inner variables
'this:page_name': pageNumber ? `$(internal:page_number_${pageNumber}_name)` : VARIABLE_UNKNOWN_VALUE,
}
}

exportAll(): Record<number, SurfaceConfig> {
return this.#dbTableSurfaces.all()
}
Expand Down
Loading
Loading