From 2a1ae0a07c40f81e836c65cc757a023ec00fbc32 Mon Sep 17 00:00:00 2001
From: Damien Iriberry <damien.iriberry@artal.fr>
Date: Wed, 21 Feb 2024 10:46:38 +0100
Subject: [PATCH] [ivette] [tests] - E2e tests are successful

---
 ivette/src/dome/main/dome.ts   | 10 ++--------
 ivette/src/dome/misc/system.ts |  1 -
 ivette/src/frama-c/server.ts   |  2 +-
 ivette/src/preload/index.d.ts  |  5 +----
 ivette/src/preload/index.ts    | 13 +------------
 5 files changed, 5 insertions(+), 26 deletions(-)

diff --git a/ivette/src/dome/main/dome.ts b/ivette/src/dome/main/dome.ts
index 948d7d76ef9..337d9bb2f18 100644
--- a/ivette/src/dome/main/dome.ts
+++ b/ivette/src/dome/main/dome.ts
@@ -414,6 +414,7 @@ function createBrowserWindow(
       nodeIntegration: true,
       sandbox: false,
       additionalArguments: [...browserArguments],
+      preload: path.join(__dirname, '../preload/index.js'),
     },
     ...config,
   };
@@ -538,6 +539,7 @@ function createBrowserWindow(
     });
   }
 
+
   return theWindow;
 }
 
@@ -554,11 +556,6 @@ interface Cmd { wdir: string; argv: string[] }
 
 // [LC]: this is buggy, process.argv has no command line arguments
 function stripElectronArgv(cmd: Cmd): Cmd {
-  console.log("DEVEL", DEVEL);
-  console.log("Is Dev", is.dev);
-  console.log("LOCAL", LOCAL);
-  console.log("Vite Mode", import.meta.env.MODE);
-
   const devel = import.meta.env.MODE === "development";
   const wdir = devel ? cmd.argv[2] : cmd.wdir;
   const argv = cmd.argv
@@ -578,10 +575,7 @@ function createPrimaryWindow(): void {
   //  });
   const cwd = process.cwd();
   const wdir = cwd === '/' ? app.getPath('home') : cwd;
-  console.log("Process argv: ", process.argv);
-  console.log("Before", { wdir, argv: process.argv });
   const cmd = stripElectronArgv({ wdir, argv: process.argv });
-  console.log("After", cmd);
 
   // Reset Settings if the associated argument is provided
   const settingsIdx = cmd.argv.indexOf(CLI_OPTION_SETTINGS.name);
diff --git a/ivette/src/dome/misc/system.ts b/ivette/src/dome/misc/system.ts
index f998ca46957..b1287d0fa7f 100644
--- a/ivette/src/dome/misc/system.ts
+++ b/ivette/src/dome/misc/system.ts
@@ -564,7 +564,6 @@ export function spawn(
   options?: ProcessOptions,
 ): Promise<Exec.ChildProcess> {
   return new Promise((result, reject) => {
-
     const cwd = options ? options.cwd : undefined;
     const opt = options ? options.env : undefined;
     const env = // Forces 'PWD' env. variable for executing a non-shell process
diff --git a/ivette/src/frama-c/server.ts b/ivette/src/frama-c/server.ts
index 1364e16daac..06a0706c052 100644
--- a/ivette/src/frama-c/server.ts
+++ b/ivette/src/frama-c/server.ts
@@ -491,7 +491,7 @@ async function _launch(): Promise<void> {
     cwd: working,
     stdout: { path: logout, pipe: true },
     stderr: { path: logerr, pipe: true },
-    env,
+    env: { ...env, ... window.electron.process.env },
   };
   // Launch Process
   System.atExit(() => {
diff --git a/ivette/src/preload/index.d.ts b/ivette/src/preload/index.d.ts
index 909e10c3bf6..bc2ee9237f1 100644
--- a/ivette/src/preload/index.d.ts
+++ b/ivette/src/preload/index.d.ts
@@ -2,9 +2,6 @@ import { ElectronAPI } from '@electron-toolkit/preload';
 
 declare global {
   interface Window {
-    electron: ElectronAPI
-    api: {
-      readDir(path: string): Promise<string[]>
-    }
+    electron: ElectronAPI;
   }
 }
diff --git a/ivette/src/preload/index.ts b/ivette/src/preload/index.ts
index d9df9b5fbea..680cfe2b09c 100644
--- a/ivette/src/preload/index.ts
+++ b/ivette/src/preload/index.ts
@@ -1,13 +1,5 @@
-import { contextBridge } from 'electron';
 import { electronAPI } from '@electron-toolkit/preload';
-import fs from 'fs/promises';
-
-// Custom APIs for renderer
-const api = {
-  readDir: async (path: string) => {
-    return await fs.readdir(path);
-  },
-};
+import { contextBridge } from 'electron';
 
 // Use `contextBridge` APIs to expose Electron APIs to
 // renderer only if context isolation is enabled, otherwise
@@ -15,7 +7,6 @@ const api = {
 if (process.contextIsolated) {
   try {
     contextBridge.exposeInMainWorld('electron', electronAPI);
-    contextBridge.exposeInMainWorld('api', api);
   } catch (error) {
     // eslint-disable-next-line no-console
     console.error(error);
@@ -23,6 +14,4 @@ if (process.contextIsolated) {
 } else {
   // @ts-expect-error (define in dts)
   window.electron = electronAPI;
-  // @ts-expect-error (define in dts)
-  window.api = api;
 }
-- 
GitLab