Skip to content

Commit f171fa6

Browse files
committed
Exit command
1 parent b6c9de3 commit f171fa6

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

packages/server/src/server/services/remoteConfigService/commands.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,35 +70,38 @@ Available Commands:
7070
-> last_fcm_restart: number
7171
-> start_via_terminal: boolean
7272
- show: Show the current configuration for an item -> \`show <config item>\`
73+
- exit: Exit the configurator
7374
\n[===============================================================================]`;
7475

7576

76-
export async function handleLine (line: string) {
77+
export async function handleLine (line: string) : Promise<[string, boolean]> {
7778
line = line.trim();
78-
if (line === "") return;
79+
if (line === "") return ['', true];
7980

8081
// Handle the standard input
8182
const parts = line.split(" ");
82-
if (isEmpty(parts)) return;
83+
if (isEmpty(parts)) return ['', true];
8384

8485
if (!Server()) {
85-
return "Server is not running???????";
86+
return ["Server is not running???????", true];
8687
}
8788

8889
switch (parts[0].toLowerCase()) {
8990
case "help":
90-
return help;
91+
return [help, true];
9192
case "set":
92-
return await handleSet(parts);
93+
return [await handleSet(parts), true];
9394
break;
9495
case "show":
95-
return await handleShow(parts);
96+
return [await handleShow(parts), true];
9697
break;
9798
case "restart":
9899
case "relaunch":
99100
Server().relaunch();
100-
return "Okay, restarting";
101+
return ["Okay, restarting", true];
102+
case "exit":
103+
return ["Thank you for using the Bluebubbles configurator!", false];
101104
default:
102-
return "Unrecognized command. Type 'help' for help.";
105+
return ["Unrecognized command. Type 'help' for help.", true];
103106
}
104107
}

packages/server/src/server/services/remoteConfigService/index.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { app } from "electron";
66
import { handleLine } from "./commands";
77

88

9-
const PROMPT = 'bluebubbles-config>';
9+
const PROMPT = 'bluebubbles-configurator>';
1010

1111

1212
export class RemoteConfigService {
@@ -55,7 +55,7 @@ export class RemoteConfigService {
5555
this.clients.add(client);
5656
const lineExtractor = new LineExtractor();
5757

58-
client.write(`Welcome to the BlueBubbles remote configurator!\nType 'help' for help.\nPress Ctrl-D or Ctrl-C to exit the remote configurator.\n${PROMPT} `);
58+
client.write(`Welcome to the BlueBubbles configurator!\nType 'help' for help.\nType 'exit' to exit.\n${PROMPT} `);
5959

6060
client.on("data", async (data: Buffer) => {
6161
for (const line of lineExtractor.feed(data)) {
@@ -74,19 +74,23 @@ export class RemoteConfigService {
7474

7575
private async handleLine (client: net.Socket, line: string) {
7676
this.log(`Remote Config Service client received line: ${JSON.stringify(line)}`, "debug");
77-
const response = await handleLine(line);
77+
const [response, keepOpen] = await handleLine(line);
7878
if (response) {
7979
client.write(`${response}\n`);
8080
}
81-
client.write(`${PROMPT} `);
81+
if (keepOpen) {
82+
client.write(`${PROMPT} `);
83+
}
84+
else {
85+
client.destroy();
86+
}
8287
}
8388

8489
private closeServer () {
8590
if (this.server === null) {
8691
return;
8792
}
8893
this.server.close();
89-
fs.unlinkSync(this.socketPath);
9094
this.server = null;
9195
}
9296

0 commit comments

Comments
 (0)