Skip to content

Commit f88db86

Browse files
[chore 🎆] editor & socket works perfect 🌸
1 parent e69d6a3 commit f88db86

5 files changed

Lines changed: 17 additions & 38 deletions

File tree

desktop/src/main/index.ts

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,40 +52,36 @@ app.whenReady().then(() => {
5252

5353
// Register the custom protocol to serve Monaco Editor worker files locally
5454
protocol.handle("monaco-editor", (request) => {
55-
const url = request.url.substr("monaco-editor://".length); // e.g., "vs/editor/editor.main.js" or "ts.worker.js"
55+
const url = request.url.substr("monaco-editor://".length);
5656

5757
let monacoBasePath;
5858
if (is.dev) {
59-
// In development, node_modules is usually outside the bundled app path
60-
// __dirname in main.ts is like dist-electron, so ../../node_modules
59+
// Adjust this path based on your dev setup relative to dist-electron/main/index.js
6160
monacoBasePath = join(__dirname, "../../node_modules/monaco-editor/min");
6261
} else {
63-
// In a packaged app, node_modules content is often copied to a resources folder
64-
// or directly into the app.asar. Adjust this path based on your build script.
65-
// A common pattern is to copy 'node_modules/monaco-editor/min' to 'resources/app.asar/monaco-editor-min'
66-
// or similar. For simplicity, let's assume it's directly accessible relative to app.getAppPath().
67-
// If it's copied directly into the root of your packaged app:
62+
// Adjust this path based on where 'monaco-editor/min' is copied in your packaged app.
63+
// Common paths:
64+
// If monaco-editor/min is copied to the root of your packaged app:
6865
monacoBasePath = join(app.getAppPath(), "node_modules/monaco-editor/min");
69-
// Or if your build copies it to a specific subfolder like 'assets/monaco':
66+
// If it's copied to a specific asset folder like 'assets/monaco':
7067
// monacoBasePath = join(app.getAppPath(), 'assets', 'monaco');
7168
}
7269

7370
const filePath = join(monacoBasePath, url);
74-
console.log("Serving monaco-editor:// file:", filePath); // Log for debugging
71+
console.log("Serving monaco-editor:// file:", filePath); // Keep this for debugging!
7572

7673
if (existsSync(filePath)) {
7774
return new Response(readFileSync(filePath));
7875
} else {
79-
console.error("Monaco Editor worker/script file not found:", filePath);
76+
console.error("Monaco Editor file not found:", filePath);
77+
// It's crucial to return a proper 404 or an empty response for missing files.
78+
// Returning a null or undefined can cause issues.
8079
return new Response("File not found", { status: 404 });
8180
}
8281
});
8382
// Set app user model id for windows
8483
electronApp.setAppUserModelId("com.executeme");
8584

86-
// Default open or close DevTools by F12 in development
87-
// and ignore CommandOrControl + R in production.
88-
// see https://github.com/alex8088/electron-toolkit/tree/master/packages/utils
8985
app.on("browser-window-created", (_, window) => {
9086
optimizer.watchWindowShortcuts(window);
9187
});
@@ -96,15 +92,10 @@ app.whenReady().then(() => {
9692
createWindow();
9793

9894
app.on("activate", function () {
99-
// On macOS it's common to re-create a window in the app when the
100-
// dock icon is clicked and there are no other windows open.
10195
if (BrowserWindow.getAllWindows().length === 0) createWindow();
10296
});
10397
});
10498

105-
// Quit when all windows are closed, except on macOS. There, it's common
106-
// for applications and their menu bar to stay active until the user quits
107-
// explicitly with Cmd + Q.
10899
app.on("window-all-closed", () => {
109100
if (process.platform !== "darwin") {
110101
app.quit();

desktop/src/preload/index.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,23 @@ const api = {};
77
// This is crucial for @monaco-editor/react to know where to load its *main* scripts from
88
contextBridge.exposeInMainWorld("monacoConfig", {
99
getMonacoBasePath: () => {
10-
// This path should point to the 'min/vs' directory of your monaco-editor installation.
11-
// It needs to be accessible from the renderer process.
12-
// In a packaged app, node_modules is often bundled, so we adjust the path.
13-
// You might need to adjust `../node_modules/monaco-editor/min/vs` based on your project's build output structure.
14-
return `monaco-editor://vs`; // Use your custom protocol for the base path too
10+
// This is correct. The renderer will ask for 'monaco-editor://vs'
11+
// and your main process protocol handler will resolve it to the local path.
12+
return `monaco-editor://vs`;
1513
}
1614
});
1715

18-
// Use `contextBridge` APIs to expose Electron APIs to
19-
// renderer only if context isolation is enabled, otherwise
20-
// just add to the DOM global.
2116
if (process.contextIsolated) {
2217
try {
2318
contextBridge.exposeInMainWorld("electron", {
2419
ipcRenderer: {
2520
send: (channel: string, args?: any[]) => ipcRenderer.send(channel, args),
2621
on: (channel: string, listener: (...args: any[]) => void) => {
2722
ipcRenderer.on(channel, listener);
28-
// Return a cleanup function for `on` listeners
2923
return () => ipcRenderer.removeListener(channel, listener);
3024
}
3125
}
3226
});
33-
contextBridge.exposeInMainWorld("api", api);
3427
} catch (error) {
3528
console.error(error);
3629
}
@@ -42,6 +35,4 @@ if (process.contextIsolated) {
4235
on: (channel, listener) => ipcRenderer.on(channel, listener)
4336
}
4437
};
45-
// @ts-ignore (define in dts)
46-
window.api = api;
4738
}

desktop/src/renderer/index.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
<meta
88
http-equiv="Content-Security-Policy"
99
content="
10-
default-src 'self' 'unsafe-inline';
11-
script-src 'self' 'unsafe-inline' 'unsafe-eval' https://cdn.jsdelivr.net;
12-
style-src 'self' 'unsafe-inline' https://cdn.jsdelivr.net;
10+
script-src 'self' 'unsafe-inline' 'unsafe-eval' https://cdn.jsdelivr.net monaco-editor:;
11+
style-src 'self' 'unsafe-inline' https://cdn.jsdelivr.net monaco-editor:; /* <-- ADD 'monaco-editor:' HERE, NO ** */
1312
img-src 'self' data:;
1413
font-src 'self' https://cdn.jsdelivr.net https://fonts.gstatic.com;
1514
connect-src 'self' wss://145.223.97.55:9292 https://145.223.97.55:9292;

desktop/src/renderer/src/main.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ loader.config({
1616
}
1717
});
1818

19-
// Your existing getWorkerUrl configuration
20-
// This part is correct for defining *worker* URLs, but the loader.config
21-
// is for the *main* Monaco scripts.
19+
// This part is for the workers, which you already had mostly correct
2220
window.MonacoEnvironment = {
2321
getWorkerUrl: (_moduleId, label) => {
2422
const workerFilenameMap: { [key: string]: string } = {
@@ -36,7 +34,6 @@ window.MonacoEnvironment = {
3634
return `monaco-editor://${workerFile}`;
3735
}
3836
};
39-
4037
createRoot(document.getElementById("root")!).render(
4138
<StrictMode>
4239
<BaseProvider>

origin/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export const allowOrigins = [
22
"http://localhost:3000",
3+
"http://localhost:5173",
34
"https://executeme.vercel.app",
45
];

0 commit comments

Comments
 (0)