Skip to content

Commit

Permalink
Add a pref shell.type to use node process instead of websocket (#357)
Browse files Browse the repository at this point in the history
LSP with the shell.type=process does not work at the moment.

Fix #54
  • Loading branch information
ficristo authored Sep 8, 2024
1 parent fdfb68f commit 30d188b
Show file tree
Hide file tree
Showing 10 changed files with 869 additions and 21 deletions.
7 changes: 7 additions & 0 deletions app/appshell/shell.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { BrowserWindow } from "electron";
import _ = require("lodash");
import { readBracketsPreferences } from "../brackets-config";

const bracketsPreferences = readBracketsPreferences();
const shellType = _.get(bracketsPreferences, "shell.type");

export function getMainWindow(): BrowserWindow {
const wins = BrowserWindow.getAllWindows();
Expand All @@ -11,3 +16,5 @@ export function getMainWindow(): BrowserWindow {
export function getProcessArgv(): Array<string> {
return process.argv;
}

export const type = shellType;
29 changes: 16 additions & 13 deletions app/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,6 @@ const saveWindowPosition = _.debounce(_.partial(_saveWindowPosition, false), 100
// Quit when all windows are closed.
let windowAllClosed = false;

// Start the socket server used by Brackets'
const socketServerLog = getLogger("socket-server");
SocketServer.start(function (err: Error, port: number) {
if (err) {
shellState.set("socketServer.state", "ERR_NODE_FAILED");
socketServerLog.error("failed to start: " + errToString(err));
} else {
shellState.set("socketServer.state", "NO_ERROR");
shellState.set("socketServer.port", port);
socketServerLog.info("started on port " + port);
}
});

app.on("window-all-closed", function () {
windowAllClosed = true;
setTimeout(app.quit, 500);
Expand Down Expand Up @@ -250,6 +237,22 @@ export function openMainBracketsWindow(query: {} | string = {}): BrowserWindow {
app.commandLine.appendSwitch("disable-smooth-scrolling");
}

// Start the socket server used by Brackets is shell.type is not `process`.
const shellType = _.get(bracketsPreferences, "shell.type");
if (shellType !== "process") {
const socketServerLog = getLogger("socket-server");
SocketServer.start(function (err: Error, port: number) {
if (err) {
shellState.set("socketServer.state", "ERR_NODE_FAILED");
socketServerLog.error("failed to start: " + errToString(err));
} else {
shellState.set("socketServer.state", "NO_ERROR");
shellState.set("socketServer.port", port);
socketServerLog.info("started on port " + port);
}
});
}

// create the browser window
const win = new BrowserWindow(winOptions);
if (argv.devtools) {
Expand Down
25 changes: 25 additions & 0 deletions app/node-process/BaseDomain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import DomainManager from "./domain-manager";

function init(domainManager: typeof DomainManager): void {
domainManager.registerDomain("base", {major: 0, minor: 1});

domainManager.registerCommand(
"base",
"loadDomainModulesFromPaths",
(paths: Array<string>): boolean => {
return domainManager.loadDomainModulesFromPaths(paths);
},
false,
"Attempt to load command modules from the given paths. The paths should be absolute.",
[{name: "paths", type: "array<string>"}],
[{name: "success", type: "boolean"}]
);

domainManager.registerEvent(
"base",
"newDomains",
[]
);
}

exports.init = init;
21 changes: 21 additions & 0 deletions app/node-process/base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { log } from "./logging";
import DomainManager from "./domain-manager";

// load the base domain
DomainManager.loadDomainModulesFromPaths(["./BaseDomain"], false);

process.on("message", async function (obj: any) {
const _type: string = obj.type;
switch (_type) {
case "message":
DomainManager._receive(obj.message);
break;
default:
log.warn(`no handler for ${_type}`);
}
});

process.on("uncaughtException", (err: Error) => {
log.error(`uncaughtException: ${err.stack}`);
process.exit(1);
});
Loading

0 comments on commit 30d188b

Please sign in to comment.