aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-client/build/installer.nsh
blob: 15a840f79f81b78b38f60ed7b7c80a4b759a5454 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
; electron-builder NSIS customisation (auto-included: build/installer.nsh).
;
; Per-user install, no elevation (package.json build.nsis). This does two things
; beyond the default: put the bundled daemon on the user's PATH so `meshbay-node`
; works in a terminal, and clean up the one piece of state that lives outside
; the install directory (the W3 "run at sign-in" launcher).
;
; Deliberately NOT touched:
;   - %LOCALAPPDATA%\meshbay\  (node.toml, keystore.enc, unlock.key, data/) --
;     the keystore must survive an uninstall/reinstall; installers place files,
;     never remove secrets.

!include "WinMessages.nsh"
!include "WordFunc.nsh"
!insertmacro WordAdd
!insertmacro un.WordAdd

; The dir electron-builder drops resources into. `meshbay-node.exe` and its
; frozen Python live directly in here. A fixed suffix of $INSTDIR, so both the
; add (install) and the remove (uninstall, where $INSTDIR is still known) match
; the exact same string.
!define MB_NODE_BIN "$INSTDIR\resources\node-runtime"

!macro customInstall
  ; resources\node-runtime\meshbay-node.exe is about to be overwritten; a
  ; daemon still running from a previous version holds the file open.
  nsExec::Exec 'taskkill /IM meshbay-node.exe /F'

  ; Add the daemon dir to the per-user PATH (HKCU\Environment). WordAdd is a
  ; stock NSIS macro over a ';'-delimited list -- it is a no-op if the entry is
  ; already there, so a reinstall does not double it. New shells only; the
  ; broadcast tells already-open Explorer/shells to reload the environment.
  ReadRegStr $0 HKCU "Environment" "Path"
  ${WordAdd} "$0" ";" "+${MB_NODE_BIN}" $1
  WriteRegExpandStr HKCU "Environment" "Path" "$1"
  SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
!macroend

!macro customUnInstall
  nsExec::Exec 'taskkill /IM meshbay-node.exe /F'

  ; Take our entry back out of PATH, leaving the rest of it alone.
  ReadRegStr $0 HKCU "Environment" "Path"
  ${un.WordAdd} "$0" ";" "-${MB_NODE_BIN}" $1
  WriteRegExpandStr HKCU "Environment" "Path" "$1"
  SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000

  ; meshbay_node.platform._startup_vbs() -- if the user ran "meshbay-node
  ; autostart install" (or toggled it in the client), this points wscript at
  ; the binary we are about to delete, and would error at every sign-in.
  Delete "$APPDATA\Microsoft\Windows\Start Menu\Programs\Startup\MeshBay Node.vbs"
!macroend