Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scene logs #442

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
434 changes: 134 additions & 300 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"@types/semver": "^7.5.8",
"@typescript-eslint/eslint-plugin": "7.15.0",
"@vitejs/plugin-react": "^4.3.1",
"ansi-to-html": "^0.7.2",
"classnames": "^2.5.1",
"cross-env": "7.0.3",
"decentraland-ui2": "^0.6.1",
Expand All @@ -70,7 +71,7 @@
"dependencies": {
"@dcl/mini-rpc": "^1.0.7",
"@dcl/schemas": "^11.10.4",
"@dcl/sdk": "^7.7.5",
"@dcl/sdk": "https://sdk-team-cdn.decentraland.org/@dcl/js-sdk-toolchain/branch/rework/ts-watcher/dcl-sdk-7.7.6-13459717133.commit-fe0165b.tgz",
"@ethersproject/hash": "^5.7.0",
"@segment/analytics-node": "^2.1.2",
"cmd-shim": "^6.0.3",
Expand Down
26 changes: 12 additions & 14 deletions packages/main/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { app } from 'electron';
import { restoreOrCreateWindow } from '/@/mainWindow';
import { platform } from 'node:process';
import updater from 'electron-updater';
import log from 'electron-log/main';

import { initIpc } from './modules/ipc';
import { deployServer, killPreview, previewCache } from './modules/cli';
import { inspectorServer } from './modules/inspector';
import { getAnalytics, track } from './modules/analytics';
import './security-restrictions';
import { runMigrations } from './modules/migrations';
import { restoreOrCreateMainWindow } from '/@/mainWindow';
import { initIpc } from '/@/modules/ipc';
import { deployServer, killAllPreviews } from '/@/modules/cli';
import { inspectorServer } from '/@/modules/inspector';
import { getAnalytics, track } from '/@/modules/analytics';
import { runMigrations } from '/@/modules/migrations';

import '/@/security-restrictions';

log.initialize();

Expand All @@ -21,7 +22,7 @@ if (!isSingleInstance) {
app.quit();
process.exit(0);
}
app.on('second-instance', restoreOrCreateWindow);
app.on('second-instance', restoreOrCreateMainWindow);

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

/**
* Create the application window when app is ready.
Expand All @@ -49,7 +50,7 @@ app
log.info(`[App] Ready v${app.getVersion()}`);
initIpc();
log.info('[IPC] Ready');
await restoreOrCreateWindow();
await restoreOrCreateMainWindow();
log.info('[BrowserWindow] Ready');
const analytics = await getAnalytics();
if (analytics) {
Expand Down Expand Up @@ -103,10 +104,7 @@ if (import.meta.env.PROD) {
}

export async function killAll() {
const promises: Promise<unknown>[] = [];
for (const key in previewCache.keys()) {
promises.push(killPreview(key));
}
const promises: Promise<unknown>[] = [killAllPreviews()];
if (deployServer) {
promises.push(deployServer.kill());
}
Expand Down
57 changes: 28 additions & 29 deletions packages/main/src/mainWindow.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
import { app, BrowserWindow } from 'electron';
import { join } from 'node:path';
import { type BrowserWindow } from 'electron';
import { fileURLToPath } from 'node:url';

async function createWindow() {
const browserWindow = new BrowserWindow({
show: false, // Use the 'ready-to-show' event to show the instantiated BrowserWindow.
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
sandbox: false, // Sandbox disabled because the demo of preload script depend on the Node.js api
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
preload: join(app.getAppPath(), 'packages/preload/dist/index.mjs'),
},
});
import { createWindow, focusWindow, getWindow } from './modules/window';

browserWindow.setMenuBarVisibility(false);
browserWindow.maximize();
async function createMainWindow(id: string) {
const window = createWindow(id);
window.setMenuBarVisibility(false);
window.maximize();

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

if (import.meta.env.DEV) {
browserWindow?.webContents.openDevTools();
window?.webContents.openDevTools();
}
});

Expand All @@ -40,7 +31,7 @@ async function createWindow() {
/**
* Load from the Vite dev server for development.
*/
await browserWindow.loadURL(import.meta.env.VITE_DEV_SERVER_URL);
await window.loadURL(import.meta.env.VITE_DEV_SERVER_URL);
} else {
/**
* Load from the local file system for production and test.
Expand All @@ -51,27 +42,35 @@ async function createWindow() {
* @see https://github.com/nodejs/node/issues/12682
* @see https://github.com/electron/electron/issues/6869
*/
await browserWindow.loadFile(
await window.loadFile(
fileURLToPath(new URL('./../../renderer/dist/index.html', import.meta.url)),
);
}

return browserWindow;
return window;
}

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

if (window === undefined) {
window = await createWindow();
window = await createMainWindow(id);
}

if (window.isMinimized()) {
window.restore();
}
focusWindow(window);

window.focus();
return window;
}
Loading
Loading