Skip to content

Commit eb0b2fd

Browse files
authored
Add scene logs (#442)
* move bin module stdout & stderr to circular buffer * add circular buffer for run function * refactor window implementation * add logs window * add logging logic to renderer * fix styles * properly manage lifecycle of debugger * scroll to bottom on new logs * fix tests * add button for preview options * update @dcl/sdk * fix prod build for debugger * send all current logs buffer to debugger * update to @dcl/sdk@7.7.6 * fix comments
1 parent 0d81837 commit eb0b2fd

40 files changed

+1033
-528
lines changed

package-lock.json

+136-303
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"@types/semver": "^7.5.8",
4545
"@typescript-eslint/eslint-plugin": "7.15.0",
4646
"@vitejs/plugin-react": "^4.3.1",
47+
"ansi-to-html": "^0.7.2",
4748
"classnames": "^2.5.1",
4849
"cross-env": "7.0.3",
4950
"decentraland-ui2": "^0.6.1",
@@ -70,7 +71,7 @@
7071
"dependencies": {
7172
"@dcl/mini-rpc": "^1.0.7",
7273
"@dcl/schemas": "^11.10.4",
73-
"@dcl/sdk": "^7.7.5",
74+
"@dcl/sdk": "^7.7.6",
7475
"@ethersproject/hash": "^5.7.0",
7576
"@segment/analytics-node": "^2.1.2",
7677
"cmd-shim": "^6.0.3",

packages/main/src/index.ts

+12-14
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import { app } from 'electron';
2-
import { restoreOrCreateWindow } from '/@/mainWindow';
32
import { platform } from 'node:process';
43
import updater from 'electron-updater';
54
import log from 'electron-log/main';
65

7-
import { initIpc } from './modules/ipc';
8-
import { deployServer, killPreview, previewCache } from './modules/cli';
9-
import { inspectorServer } from './modules/inspector';
10-
import { getAnalytics, track } from './modules/analytics';
11-
import './security-restrictions';
12-
import { runMigrations } from './modules/migrations';
6+
import { restoreOrCreateMainWindow } from '/@/mainWindow';
7+
import { initIpc } from '/@/modules/ipc';
8+
import { deployServer, killAllPreviews } from '/@/modules/cli';
9+
import { inspectorServer } from '/@/modules/inspector';
10+
import { getAnalytics, track } from '/@/modules/analytics';
11+
import { runMigrations } from '/@/modules/migrations';
12+
13+
import '/@/security-restrictions';
1314

1415
log.initialize();
1516

@@ -21,7 +22,7 @@ if (!isSingleInstance) {
2122
app.quit();
2223
process.exit(0);
2324
}
24-
app.on('second-instance', restoreOrCreateWindow);
25+
app.on('second-instance', restoreOrCreateMainWindow);
2526

2627
/**
2728
* Shut down background process if all windows was closed
@@ -36,7 +37,7 @@ app.on('window-all-closed', async () => {
3637
/**
3738
* @see https://www.electronjs.org/docs/latest/api/app#event-activate-macos Event: 'activate'.
3839
*/
39-
app.on('activate', restoreOrCreateWindow);
40+
app.on('activate', restoreOrCreateMainWindow);
4041

4142
/**
4243
* Create the application window when app is ready.
@@ -49,7 +50,7 @@ app
4950
log.info(`[App] Ready v${app.getVersion()}`);
5051
initIpc();
5152
log.info('[IPC] Ready');
52-
await restoreOrCreateWindow();
53+
await restoreOrCreateMainWindow();
5354
log.info('[BrowserWindow] Ready');
5455
const analytics = await getAnalytics();
5556
if (analytics) {
@@ -103,10 +104,7 @@ if (import.meta.env.PROD) {
103104
}
104105

105106
export async function killAll() {
106-
const promises: Promise<unknown>[] = [];
107-
for (const key in previewCache.keys()) {
108-
promises.push(killPreview(key));
109-
}
107+
const promises: Promise<unknown>[] = [killAllPreviews()];
110108
if (deployServer) {
111109
promises.push(deployServer.kill());
112110
}

packages/main/src/mainWindow.ts

+28-29
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
1-
import { app, BrowserWindow } from 'electron';
2-
import { join } from 'node:path';
1+
import { type BrowserWindow } from 'electron';
32
import { fileURLToPath } from 'node:url';
43

5-
async function createWindow() {
6-
const browserWindow = new BrowserWindow({
7-
show: false, // Use the 'ready-to-show' event to show the instantiated BrowserWindow.
8-
webPreferences: {
9-
nodeIntegration: false,
10-
contextIsolation: true,
11-
sandbox: false, // Sandbox disabled because the demo of preload script depend on the Node.js api
12-
webviewTag: false, // The webview tag is not recommended. Consider alternatives like an iframe or Electron's BrowserView. @see https://www.electronjs.org/docs/latest/api/webview-tag#warning
13-
preload: join(app.getAppPath(), 'packages/preload/dist/index.mjs'),
14-
},
15-
});
4+
import { createWindow, focusWindow, getWindow } from './modules/window';
165

17-
browserWindow.setMenuBarVisibility(false);
18-
browserWindow.maximize();
6+
async function createMainWindow(id: string) {
7+
const window = createWindow(id);
8+
window.setMenuBarVisibility(false);
9+
window.maximize();
1910

2011
/**
2112
* If the 'show' property of the BrowserWindow's constructor is omitted from the initialization options,
@@ -25,11 +16,11 @@ async function createWindow() {
2516
*
2617
* @see https://github.com/electron/electron/issues/25012 for the afford mentioned issue.
2718
*/
28-
browserWindow.on('ready-to-show', () => {
29-
browserWindow?.show();
19+
window.on('ready-to-show', () => {
20+
window.show();
3021

3122
if (import.meta.env.DEV) {
32-
browserWindow?.webContents.openDevTools();
23+
window?.webContents.openDevTools();
3324
}
3425
});
3526

@@ -40,7 +31,7 @@ async function createWindow() {
4031
/**
4132
* Load from the Vite dev server for development.
4233
*/
43-
await browserWindow.loadURL(import.meta.env.VITE_DEV_SERVER_URL);
34+
await window.loadURL(import.meta.env.VITE_DEV_SERVER_URL);
4435
} else {
4536
/**
4637
* Load from the local file system for production and test.
@@ -51,27 +42,35 @@ async function createWindow() {
5142
* @see https://github.com/nodejs/node/issues/12682
5243
* @see https://github.com/electron/electron/issues/6869
5344
*/
54-
await browserWindow.loadFile(
45+
await window.loadFile(
5546
fileURLToPath(new URL('./../../renderer/dist/index.html', import.meta.url)),
5647
);
5748
}
5849

59-
return browserWindow;
50+
return window;
6051
}
6152

6253
/**
63-
* Restore an existing BrowserWindow or Create a new BrowserWindow.
54+
* Restores an existing main window or creates a new one if none exists.
55+
* This function ensures only one main window is active at a time.
56+
*
57+
* The function will:
58+
* 1. Check if a main window already exists
59+
* 2. Create a new window if none exists
60+
* 3. Restore the window if it's minimized
61+
* 4. Focus the window to bring it to the foreground
62+
*
63+
* @returns {Promise<Electron.BrowserWindow>} A promise that resolves to the main window instance
6464
*/
65-
export async function restoreOrCreateWindow() {
66-
let window = BrowserWindow.getAllWindows().find(w => !w.isDestroyed());
65+
export async function restoreOrCreateMainWindow(): Promise<BrowserWindow> {
66+
const id = 'main';
67+
let window = getWindow(id);
6768

6869
if (window === undefined) {
69-
window = await createWindow();
70+
window = await createMainWindow(id);
7071
}
7172

72-
if (window.isMinimized()) {
73-
window.restore();
74-
}
73+
focusWindow(window);
7574

76-
window.focus();
75+
return window;
7776
}

0 commit comments

Comments
 (0)