Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
msg: SetupData;
}
/* @external */
const envDecoder: Decoder = object({
msgType: constant<'env_init'>('env_init'),
msg: object({
locale: string,
hostRootUrl: string,
assignedRoute: string,
registeredKeys: optional(
array(
object({
key: string,
altKey: optional(boolean),
ctrlKey: optional(boolean),
metaKey: optional(boolean),
shiftKey: optional(boolean)
})
)
),
custom: mixed
})
});
export { startedDecoder, envDecoder };
/**
* Handles new environmental data events.
*/
export type EnvDataHandler = (envData: EnvData) => void;
}
/* @external */
const envDecoder: Decoder = object({
msgType: constant<'env_init'>('env_init'),
msg: object({
locale: string,
hostRootUrl: string,
assignedRoute: string,
registeredKeys: optional(
array(
object({
key: string,
altKey: optional(boolean),
ctrlKey: optional(boolean),
metaKey: optional(boolean),
shiftKey: optional(boolean)
})
)
),
custom: mixed
})
});
export { startedDecoder, envDecoder };
/**
* Handles new environmental data events.
*/
export type EnvDataHandler = (envData: EnvData) => void;
/**
/** Key details */
msg: NativeKey;
}
/** @external */
const decoder: Decoder = object({
msgType: constant<'registeredKeyFired'>('registeredKeyFired'),
msg: object({
altKey: optional(boolean),
charCode: optional(number),
code: optional(string),
ctrlKey: optional(boolean),
key: string,
keyCode: optional(number),
metaKey: optional(boolean),
shiftKey: optional(boolean)
})
});
export { decoder };
* Handler for messages received from workers which should be handled by the host
*/
export type WorkerToHostMessageHandler = (event: WorkerToHost) => void;
/**
* Configuration options for the WorkerManager
*/
export interface WorkerManagerConfig
extends ErrorWindowConfig,
WorkerTerminateConfig {
onWorkerToHostMessage?: WorkerToHostMessageHandler;
}
const validateWorkerManagerConfig: Guard = guard(
object({
errorWindowMillis: optional(integer),
errorWindowCountThreshold: optional(integer),
notifyBeforeTerminate: optional(boolean),
terminateReadyWaitMillis: optional(integer)
})
);
const DEFAULT_ERROR_WINDOW_CONFIG: ErrorWindowConfig = {
errorWindowMillis: 30000,
errorWindowCountThreshold: 10
};
/**
* Minimum number of millis that can be set to allow a worker (spawn or spawned)
* to terminate.
*/
const MIN_WORKERS_TERMINATE_CONFIG = 10000;
* A message used to send key information
* to the host application.
* @external
*/
export interface LabeledKeyDown extends LabeledMsg {
/** Message identifier */
msgType: 'registeredKeyFired';
/** Key details */
msg: NativeKey;
}
/** @external */
const decoder: Decoder = object({
msgType: constant<'registeredKeyFired'>('registeredKeyFired'),
msg: object({
altKey: optional(boolean),
charCode: optional(number),
code: optional(string),
ctrlKey: optional(boolean),
key: string,
keyCode: optional(number),
metaKey: optional(boolean),
shiftKey: optional(boolean)
})
});
export { decoder };
* to the host application.
* @external
*/
export interface LabeledKeyDown extends LabeledMsg {
/** Message identifier */
msgType: 'registeredKeyFired';
/** Key details */
msg: NativeKey;
}
/** @external */
const decoder: Decoder = object({
msgType: constant<'registeredKeyFired'>('registeredKeyFired'),
msg: object({
altKey: optional(boolean),
charCode: optional(number),
code: optional(string),
ctrlKey: optional(boolean),
key: string,
keyCode: optional(number),
metaKey: optional(boolean),
shiftKey: optional(boolean)
})
});
export { decoder };
/**
* Configuration options for the WorkerManager
*/
export interface WorkerManagerConfig
extends ErrorWindowConfig,
WorkerTerminateConfig {
onWorkerToHostMessage?: WorkerToHostMessageHandler;
}
const validateWorkerManagerConfig: Guard = guard(
object({
errorWindowMillis: optional(integer),
errorWindowCountThreshold: optional(integer),
notifyBeforeTerminate: optional(boolean),
terminateReadyWaitMillis: optional(integer)
})
);
const DEFAULT_ERROR_WINDOW_CONFIG: ErrorWindowConfig = {
errorWindowMillis: 30000,
errorWindowCountThreshold: 10
};
/**
* Minimum number of millis that can be set to allow a worker (spawn or spawned)
* to terminate.
*/
const MIN_WORKERS_TERMINATE_CONFIG = 10000;
const DEFAULT_WORKER_TERMINATE_CONFIG: WorkerTerminateConfig = {
notifyBeforeTerminate: true,
export type WorkerToHostMessageHandler = (event: WorkerToHost) => void;
/**
* Configuration options for the WorkerManager
*/
export interface WorkerManagerConfig
extends ErrorWindowConfig,
WorkerTerminateConfig {
onWorkerToHostMessage?: WorkerToHostMessageHandler;
}
const validateWorkerManagerConfig: Guard = guard(
object({
errorWindowMillis: optional(integer),
errorWindowCountThreshold: optional(integer),
notifyBeforeTerminate: optional(boolean),
terminateReadyWaitMillis: optional(integer)
})
);
const DEFAULT_ERROR_WINDOW_CONFIG: ErrorWindowConfig = {
errorWindowMillis: 30000,
errorWindowCountThreshold: 10
};
/**
* Minimum number of millis that can be set to allow a worker (spawn or spawned)
* to terminate.
*/
const MIN_WORKERS_TERMINATE_CONFIG = 10000;
const DEFAULT_WORKER_TERMINATE_CONFIG: WorkerTerminateConfig = {
/** Message identifier */
msgType: 'registeredKeyFired';
/** Key details */
msg: NativeKey;
}
/** @external */
const decoder: Decoder = object({
msgType: constant<'registeredKeyFired'>('registeredKeyFired'),
msg: object({
altKey: optional(boolean),
charCode: optional(number),
code: optional(string),
ctrlKey: optional(boolean),
key: string,
keyCode: optional(number),
metaKey: optional(boolean),
shiftKey: optional(boolean)
})
});
export { decoder };
msgType: 'registeredKeyFired';
/** Key details */
msg: NativeKey;
}
/** @external */
const decoder: Decoder = object({
msgType: constant<'registeredKeyFired'>('registeredKeyFired'),
msg: object({
altKey: optional(boolean),
charCode: optional(number),
code: optional(string),
ctrlKey: optional(boolean),
key: string,
keyCode: optional(number),
metaKey: optional(boolean),
shiftKey: optional(boolean)
})
});
export { decoder };