Skip to content

Commit

Permalink
server: stop console spam if mixin is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed Jan 3, 2024
1 parent 778f0b7 commit 5445311
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion server/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"${workspaceFolder}/**/*.js"
],
"env": {
"SCRYPTED_DEFAULT_AUTHENTICATION": "demo"
// "SCRYPTED_DEFAULT_AUTHENTICATION": "demo"
// force usage of system python because brew python is 3.11
// which has no wheels for coreml tools or tflite-runtime
// "SCRYPTED_PYTHON_PATH": "/usr/bin/python3",
Expand Down
4 changes: 2 additions & 2 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 10 additions & 7 deletions server/src/plugin/plugin-console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface StdPassThroughs {
}

export function getConsole(hook: (stdout: PassThrough, stderr: PassThrough) => Promise<void>,
also?: Console, alsoPrefix?: string) {
also?: Console, alsoPrefix?: string) {

const stdout = new PassThrough();
const stderr = new PassThrough();
Expand Down Expand Up @@ -63,7 +63,7 @@ export function getConsole(hook: (stdout: PassThrough, stderr: PassThrough) => P

export function prepareConsoles(getConsoleName: () => string, systemManager: () => SystemManager, deviceManager: () => DeviceManager, getPlugins: () => Promise<any>) {
const deviceConsoles = new Map<string, Console>();
function getDeviceConsole (nativeId?: ScryptedNativeId) {
function getDeviceConsole(nativeId?: ScryptedNativeId) {
// the the plugin console is simply the default console
// and gets read from stderr/stdout.
if (!nativeId)
Expand Down Expand Up @@ -126,13 +126,16 @@ export function prepareConsoles(getConsoleName: () => string, systemManager: ()

const connect = async () => {
const ds = deviceManager().getDeviceState(nativeId);
if (!ds) {
// deleted?
// device deleted
if (!ds)
return;
}

const plugins = await getPlugins();
const { pluginId, nativeId: mixinNativeId } = await plugins.getDeviceInfo(mixinId);
const mixin = systemManager().getDeviceById(mixinId);
// mixin deleted
if (!mixin)
return;
const { pluginId, nativeId: mixinNativeId } = mixin;
const port = await plugins.getRemoteServicePort(pluginId, 'console-writer');
const socket = net.connect(port);
socket.write(mixinNativeId + '\n');
Expand Down Expand Up @@ -161,7 +164,7 @@ export function prepareConsoles(getConsoleName: () => string, systemManager: ()
nativeIdConsoles.set(mixinId, ret);
return ret;
}

return {
getDeviceConsole,
getMixinConsole,
Expand Down

0 comments on commit 5445311

Please sign in to comment.