Skip to content

Commit

Permalink
Implemented roDeviceInfoEvent (#429)
Browse files Browse the repository at this point in the history
* Improved `roDeviceInfo`

* Implemented `roDeviceInfoEvent`

* Prevent CLI to print syslog messages

* Static analysis fix

* Prettier fix

* Fixed Event and test cases

* Reformatted test case

* Removed unused import
  • Loading branch information
lvcabral authored Dec 30, 2024
1 parent bd86c92 commit 39976c1
Show file tree
Hide file tree
Showing 12 changed files with 355 additions and 339 deletions.
2 changes: 2 additions & 0 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,8 @@ function workerCallback(event: MessageEvent) {
addVideo(event.data.videoPath, new Blob([event.data.videoData], { type: "video/mp4" }));
} else if (typeof event.data.displayEnabled === "boolean") {
setDisplayState(event.data.displayEnabled);
} else if (typeof event.data.captionsMode === "string") {
deviceData.captionsMode = event.data.captionsMode;
} else if (isAppData(event.data)) {
notifyAll("launch", { app: event.data.id, params: event.data.params ?? new Map() });
} else if (isNDKStart(event.data)) {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ function handleStringMessage(message: string) {
if (msg !== AppExitReason.FINISHED) {
process.exitCode = 1;
}
} else if (!["start", "debug", "reset", "video", "audio"].includes(mType)) {
} else if (!["start", "debug", "reset", "video", "audio", "syslog"].includes(mType)) {
console.info(chalk.blueBright(message.trimEnd()));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/brsTypes/components/BrsObjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export const BrsObjects = new BrsObjectsMap([
1,
],
["roAppInfo", (_: Interpreter) => new RoAppInfo()],
["roDeviceInfo", (_: Interpreter) => new RoDeviceInfo()],
["roDeviceInfo", (interpreter: Interpreter) => new RoDeviceInfo(interpreter)],
["roRemoteInfo", (_: Interpreter) => new RoRemoteInfo()],
["roAppMemoryMonitor", (_: Interpreter) => new RoAppMemoryMonitor()],
["roAudioPlayer", (interpreter: Interpreter) => new RoAudioPlayer(interpreter)],
Expand Down
3 changes: 2 additions & 1 deletion src/core/brsTypes/components/RoAppManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ export class RoAppManager extends BrsComponent implements BrsValue {
args: [new StdlibArgument("disabled", ValueKind.Boolean)],
returns: ValueKind.Void,
},
impl: (_: Interpreter, disabled: BrsBoolean) => {
impl: (interpreter: Interpreter, disabled: BrsBoolean) => {
interpreter.displayEnabled = !disabled.toBoolean();
postMessage({ displayEnabled: !disabled.toBoolean() });
return Uninitialized.Instance;
},
Expand Down
403 changes: 163 additions & 240 deletions src/core/brsTypes/components/RoDeviceInfo.ts

Large diffs are not rendered by default.

66 changes: 66 additions & 0 deletions src/core/brsTypes/components/RoDeviceInfoEvent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { BrsValue, ValueKind, BrsBoolean } from "../BrsType";
import { BrsComponent } from "./BrsComponent";
import { BrsType, toAssociativeArray } from "..";
import { Callable } from "../Callable";
import { Interpreter } from "../../interpreter";

export class RoDeviceInfoEvent extends BrsComponent implements BrsValue {
readonly kind = ValueKind.Object;
private readonly data: any;
private readonly isStatusMsg: boolean = false;
private readonly isCaptionModeMsg: boolean = false;

constructor(data: any) {
super("roDeviceInfoEvent");
this.data = data;
if (typeof data.Mode === "string") {
this.isCaptionModeMsg = true;
} else {
this.isStatusMsg = true;
}
this.registerMethods({
ifDeviceInfoEvent: [this.getInfo, this.isStatusMessage, this.isCaptionModeChanged],
});
}

toString(parent?: BrsType): string {
return "<Component: roDeviceInfoEvent>";
}

equalTo(other: BrsType) {
return BrsBoolean.False;
}

/** Checks if the device status has changed. */
private readonly isStatusMessage = new Callable("isStatusMessage", {
signature: {
args: [],
returns: ValueKind.Boolean,
},
impl: (_: Interpreter) => {
return BrsBoolean.from(this.isStatusMsg);
},
});

/** Indicates whether the user has changed the closed caption mode. */
private readonly isCaptionModeChanged = new Callable("isCaptionModeChanged", {
signature: {
args: [],
returns: ValueKind.Boolean,
},
impl: (_: Interpreter) => {
return BrsBoolean.from(this.isCaptionModeMsg);
},
});

/** Returns an roAssociativeArray with the current status of the device or the caption mode. */
private readonly getInfo = new Callable("getInfo", {
signature: {
args: [],
returns: ValueKind.Object,
},
impl: (_: Interpreter) => {
return toAssociativeArray(this.data);
},
});
}
8 changes: 6 additions & 2 deletions src/core/brsTypes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { RoInputEvent } from "./components/RoInputEvent";
import { RoAudioPlayerEvent } from "./components/RoAudioPlayerEvent";
import { RoVideoPlayerEvent } from "./components/RoVideoPlayerEvent";
import { RoChannelStoreEvent } from "./components/RoChannelStoreEvent";
import { RoDeviceInfoEvent } from "./components/RoDeviceInfoEvent";

export * from "./BrsType";
export * from "./Int32";
Expand Down Expand Up @@ -91,6 +92,7 @@ export * from "./components/RoLocalization";
export * from "./components/RoRegistry";
export * from "./components/RoRegistrySection";
export * from "./components/RoDeviceInfo";
export * from "./components/RoDeviceInfoEvent";
export * from "./components/RoRemoteInfo";
export * from "./components/RoAppMemoryMonitor";
export * from "./components/RoFileSystem";
Expand Down Expand Up @@ -224,7 +226,8 @@ export function isBrsEvent(value: BrsType): value is BrsEvent {
value instanceof RoInputEvent ||
value instanceof RoAudioPlayerEvent ||
value instanceof RoVideoPlayerEvent ||
value instanceof RoChannelStoreEvent
value instanceof RoChannelStoreEvent ||
value instanceof RoDeviceInfoEvent
);
}

Expand All @@ -236,7 +239,8 @@ export type BrsEvent =
| RoInputEvent
| RoAudioPlayerEvent
| RoVideoPlayerEvent
| RoChannelStoreEvent;
| RoChannelStoreEvent
| RoDeviceInfoEvent;

/**
* The set of all comparable BrightScript types. Only primitive (i.e. intrinsic * and unboxed)
Expand Down
2 changes: 2 additions & 0 deletions src/core/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface DeviceInfo {
captionLanguage: string;
clockFormat: string;
displayMode: "480p" | "720p" | "1080p";
captionsMode: "Off" | "On" | "Instant replay" | "When mute";
defaultFont: string;
fontPath: string;
fonts?: Map<string, any>;
Expand Down Expand Up @@ -63,6 +64,7 @@ export const defaultDeviceInfo: DeviceInfo = {
captionLanguage: "eng",
clockFormat: "12h",
displayMode: "720p",
captionsMode: "Off",
defaultFont: "Asap",
fontPath: "../fonts/",
fonts: new Map(),
Expand Down
1 change: 1 addition & 0 deletions src/core/interpreter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export class Interpreter implements Expr.Visitor<BrsType>, Stmt.Visitor<BrsType>
return this._creationTime;
}

public displayEnabled: boolean = true;
public lastRemote: number = 0;
public lastKeyTime: number = Date.now();
public currKeyTime: number = Date.now();
Expand Down
Loading

0 comments on commit 39976c1

Please sign in to comment.