From 9e7cc06794f68df0c9ac8f02249080b5d17fb520 Mon Sep 17 00:00:00 2001
From: Benedict Diederich <bene.d@gmx.de>
Date: Sat, 3 Feb 2024 23:08:32 +0100
Subject: [PATCH] Ensure a missing imswitch installation is detected and fixed

---
 main.js | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/main.js b/main.js
index 18c8d07..8cec154 100644
--- a/main.js
+++ b/main.js
@@ -516,22 +516,24 @@ function downloadResources(win, fresh) {
 
 function setupMambaEnv(win) {
     const envName = "imswitch";
-    var miniforgePath, mambaPath, pipPath;
+    var miniforgePath, mambaPath, pipPath, imswitchPath;
 
     if (os.platform == "win32") {
         miniforgePath = path.join(homeDir, 'miniforge');
         mambaPath = path.join(miniforgePath, 'condabin', 'mamba');
         pipPath = path.join(miniforgePath, 'Scripts', 'pip'); // Adjust for Windows if necessary
+        imswitchPath = path.join(miniforgePath, 'site-packages', 'imswitch')
     }
     else {
         miniforgePath = path.join(homeDir, 'miniforge');
         mambaPath = path.join(miniforgePath, 'bin', 'mamba');
         pipPath = path.join(miniforgePath, 'bin', 'pip');
+        imswitchPath = path.join(miniforgePath, 'site-packages', 'imswitch')
     }
     /*
     Install UC2-REST and ImSwitch from github master
     */
-    if (!fs.existsSync(path.join(miniforgePath))) {
+    if (!fs.existsSync(path.join(miniforgePath)) || !fs.existsSync(path.join(imswitchPath))) {
        // win.webContents.send("updateStatus", "Creating Mamba environment...");
         // runCommand(`${mambaPath}`, [`create`, `-n`, `${envName}`, '-y'], win)
         //runCommand(`${mambaPath} create -n ${envName} -y`)