Skip to content

Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.

C++

Windows uninstaller: stop the app, host, node and engine that run from the install folder before files are removed, so the program folder no longer stays behind after use; only processes whose image path is inside the install folder; test with a real process

Niko122136c6dd9ef51e
diff --git a/apps/desktop/src-tauri/nsis/installer.nsi b/apps/desktop/src-tauri/nsis/installer.nsi
index ac3310f47..3d03888ca 100644
--- a/apps/desktop/src-tauri/nsis/installer.nsi
+++ b/apps/desktop/src-tauri/nsis/installer.nsi
@@ -701,6 +701,19 @@ SectionEnd
!macroend
; STRATA-MIGRATE-END
+; STRATA-STOP-BEGIN
+; Stop what Strata itself started from the install folder (the app, its host, the node runtime, the engine) before files are removed:
+; a running copy keeps its files open, so the folder stayed behind after use. Only processes whose image path is inside INSTDIR are
+; stopped; this uninstaller's own process and any program elsewhere are left alone.
+!macro StrataStopOwnProcesses INSTALLDIR
+ System::Call 'kernel32::SetEnvironmentVariableW(w "STRATA_INSTDIR", w "${INSTALLDIR}")'
+ System::Call 'kernel32::GetCurrentProcessId()i.r9'
+ System::Call 'kernel32::SetEnvironmentVariableW(w "STRATA_SELFPID", w "$9")'
+ nsExec::Exec 'powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command "$$d = $$env:STRATA_INSTDIR.TrimEnd([char]92) + [char]92; Get-CimInstance Win32_Process | Where-Object { $$_.ExecutablePath -and $$_.ExecutablePath.StartsWith($$d, [StringComparison]::OrdinalIgnoreCase) -and $$_.ProcessId -ne [int]$$env:STRATA_SELFPID } | ForEach-Object { Stop-Process -Id $$_.ProcessId -Force -ErrorAction SilentlyContinue }; Start-Sleep -Milliseconds 500"'
+ Pop $9
+!macroend
+; STRATA-STOP-END
+
Section Install
SetOutPath $INSTDIR
@@ -847,6 +860,7 @@ Section Uninstall
!insertmacro NSIS_HOOK_PREUNINSTALL
!endif
+ !insertmacro StrataStopOwnProcesses "$INSTDIR"
!insertmacro CheckIfAppIsRunning "$INSTDIR\${MAINBINARYNAME}.exe" "${PRODUCTNAME}"
; Delete the app directory and its content from disk
diff --git a/tests/desktop/test_nsis_layout.py b/tests/desktop/test_nsis_layout.py
index 91cce38f3..e8c222d90 100644
--- a/tests/desktop/test_nsis_layout.py
+++ b/tests/desktop/test_nsis_layout.py
@@ -55,7 +55,8 @@ class TemplateTests(unittest.TestCase):
@unittest.skipUnless(MAKENSIS.is_file(), "NSIS (the Tauri bundler's copy) is not installed here")
class MigrationTests(unittest.TestCase):
def run_nsis(self, body: str, work: Path):
- block = re.search(r"; STRATA-MIGRATE-BEGIN.*?; STRATA-MIGRATE-END", TEMPLATE.read_text(encoding="utf-8"), re.S).group(0)
+ template = TEMPLATE.read_text(encoding="utf-8")
+ block = chr(10).join(re.search(rf"; STRATA-{name}-BEGIN.*?; STRATA-{name}-END", template, re.S).group(0) for name in ("MIGRATE", "STOP"))
script = work / "t.nsi"
script.write_text('Unicode true\nOutFile "t.exe"\nRequestExecutionLevel user\nSilentInstall silent\n' + block + "\nSection\n" + body + "\nSectionEnd\n", encoding="utf-8")
done = subprocess.run([str(MAKENSIS), "/V1", str(script)], cwd=work, capture_output=True, text=True)
@@ -109,5 +110,38 @@ class MigrationTests(unittest.TestCase):
self.assertFalse((old / "strata-desktop.exe").exists())
+ def test_the_uninstaller_stops_only_the_processes_started_from_the_install_folder(self):
+ ping = Path(os.environ.get("SystemRoot", r"C:\Windows")) / "System32" / "PING.EXE"
+ if not ping.is_file():
+ self.skipTest("no PING.EXE to stand in for a running Strata process")
+ with tempfile.TemporaryDirectory() as tmp:
+ base = Path(tmp)
+ inst, other = base / "Programs" / "Strata", base / "Elsewhere"
+ for folder in (inst / "node", other):
+ folder.mkdir(parents=True)
+ mine = inst / "node" / "node.exe"
+ theirs = other / "node.exe"
+ for target in (mine, theirs):
+ target.write_bytes(ping.read_bytes())
+ procs = [subprocess.Popen([str(p), "-t", "127.0.0.1"], stdout=subprocess.DEVNULL) for p in (mine, theirs)]
+ try:
+ self.run_nsis(f'!insertmacro StrataStopOwnProcesses "{inst}"', base)
+ procs[0].wait(timeout=20)
+ self.assertIsNotNone(procs[0].poll(), "the process from the install folder was stopped")
+ self.assertIsNone(procs[1].poll(), "a process of the same name elsewhere is left running")
+ finally:
+ for proc in procs:
+ if proc.poll() is None:
+ proc.kill()
+ proc.wait()
+
+
+class StopOrderTests(unittest.TestCase):
+ def test_the_uninstaller_stops_them_before_it_removes_files(self):
+ text = TEMPLATE.read_text(encoding="utf-8")
+ uninstall = text[text.index("Section Uninstall"):]
+ self.assertLess(uninstall.index("StrataStopOwnProcesses"), uninstall.index(r'Delete "$INSTDIR\${MAINBINARYNAME}.exe"'))
+
+
if __name__ == "__main__":
unittest.main()