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

Flatten Electron file #803

Merged
merged 16 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"test:app": "vitest run --exclude \"**/pipelines.test.ts\"",
"test:tutorial": "vitest tutorial",
"test:pipelines": "vitest pipelines",
"test:metadata": "vitest metadata",
"test:server": "pytest src/pyflask/tests/ -s -vv",
"wait5s": "node -e \"setTimeout(() => process.exit(0),5000)\"",
"test:executable": "concurrently -n EXE,TEST --kill-others --success first \"node tests/testPyinstallerExecutable.js --port 3434 --forever\" \"npm run wait5s && pytest src/pyflask/tests/ -s --target http://localhost:3434\"",
Expand Down
74 changes: 30 additions & 44 deletions src/electron/frontend/utils/electron.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,37 @@
import { updateURLParams } from "./url.js";

var userAgent = navigator.userAgent.toLowerCase();
const userAgent = navigator.userAgent.toLowerCase();
export const isElectron = userAgent.indexOf(" electron/") > -1;

export let port = 4242;
export let SERVER_FILE_PATH = "";
export const electron = globalThis.electron ?? {}; // ipcRenderer, remote, shell, etc.
export let fs = null;
export let os = null;
export let remote = {};
export let app = null;
export let path = null;
export let log = null;
export let crypto = null;

// Used in tests
try {
crypto = require("crypto");
} catch {}

// Node Modules
export const fs = require("fs-extra"); // File System
export const os = require("os");
export const crypto = require("crypto");
export const path = require("path");

// Remote Electron Modules
export const remote = isElectron ? require("@electron/remote") : {};
export const app = remote.app;

// Electron Information
export const port = electron.ipcRenderer ? electron.ipcRenderer.sendSync("get-port") : 4242;
export const SERVER_FILE_PATH = electron.ipcRenderer ? electron.ipcRenderer.sendSync("get-server-file-path") : "";

// Link the renderer to the main process
if (isElectron) {
try {
fs = require("fs-extra"); // File System
os = require("os");
crypto = require("crypto");
remote = require("@electron/remote");
app = remote.app;

electron.ipcRenderer.on("fileOpened", (info, filepath) => {
updateURLParams({ file: filepath });
const dashboard = document.querySelector("nwb-dashboard");
const activePage = dashboard.getAttribute("activePage");
if (activePage === "preview") dashboard.requestUpdate();
else dashboard.setAttribute("activePage", "preview");
});

["log", "warn", "error"].forEach((method) =>
electron.ipcRenderer.on(`console.${method}`, (_, ...args) => console[method](`[main-process]:`, ...args))
);

port = electron.ipcRenderer.sendSync("get-port");
console.log("User OS:", os.type(), os.platform(), "version:", os.release());

SERVER_FILE_PATH = electron.ipcRenderer.sendSync("get-server-file-path");

path = require("path");
} catch (error) {
console.error("Electron API access failed —", error);
}
} else console.warn("Electron API is blocked for web builds");
electron.ipcRenderer.on("fileOpened", (info, filepath) => {
updateURLParams({ file: filepath });
const dashboard = document.querySelector("nwb-dashboard");
const activePage = dashboard.getAttribute("activePage");
if (activePage === "preview") dashboard.requestUpdate();
else dashboard.setAttribute("activePage", "preview");
});

["log", "warn", "error"].forEach((method) =>
electron.ipcRenderer.on(`console.${method}`, (_, ...args) => console[method](`[main-process]:`, ...args))
);

console.log("User OS:", os.type(), os.platform(), "version:", os.release());
}
3 changes: 1 addition & 2 deletions tests/metadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import baseMetadataSchema from '../src/schemas/base-metadata.schema'
import { createMockGlobalState } from './utils'

import { Validator } from 'jsonschema'
import { tempPropertyKey, textToArray } from '../src/electron/frontend/core/components/forms/utils'
import { textToArray } from '../src/electron/frontend/core/components/forms/utils'
import { updateResultsFromSubjects } from '../src/electron/frontend/core/components/pages/guided-mode/setup/utils'
import { JSONSchemaForm } from '../src/electron/frontend/core/components/JSONSchemaForm'

import { validateOnChange } from "../src/electron/frontend/core/validation/index.js";
import { SimpleTable } from '../src/electron/frontend/core/components/SimpleTable'
import { JSONSchemaInput } from '../src/electron/frontend/core/components/JSONSchemaInput.js'

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
Expand Down
Loading