Skip to content

Commit 98adf4f

Browse files
joa-quimclaude
andcommitted
iview_app.vbs: own-folder fast path + depot fallback, no double Julia launch
Previous version asked Julia (a second julia.exe subprocess) to resolve the install path on every single launch -- correct, but doubled startup time. Now: use this script's own folder if iview_app.jl sits right next to it (dev checkout, or running in place inside a live Pkg folder -- zero overhead, one julia.exe launch, same as before). Only a detached copy (e.g. on Desktop) falls back to scanning ~/.julia/packages/InteractiveGMT/* for the newest-modified folder -- a plain filesystem check, still no second Julia process. Fixed a real VBScript bug along the way: `sub` is a reserved keyword, can't be a variable name. Add deps/installer/make_desktop_shortcut.vbs: one-time setup script for a plain `Pkg.add` install (no NSIS) that copies iview_app.vbs + igmt.ico to the Desktop once and creates a real .lnk shortcut with the icon set -- needed because a .lnk's icon path can't be resolved dynamically like the launch target can. Deliberately does NOT use sh.SpecialFolders("Desktop"): verified live on this machine that it silently resolves into an OneDrive-redirected path (C:\Users\j\OneDrive - Universidade do Algarve\Ambiente de Trabalho) instead of the real local Desktop. Forces %USERPROFILE%\Desktop instead. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent d6f78fa commit 98adf4f

2 files changed

Lines changed: 80 additions & 22 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
' ONE-TIME SETUP for a `] add`/`Pkg.update` install (no NSIS): creates a real Desktop .lnk
2+
' shortcut, with the iGMT icon, that survives every future Pkg.update. Run this once (from
3+
' wherever InteractiveGMT currently lives — find it with `pathof(InteractiveGMT)` in Julia if
4+
' unsure). Safe to re-run anytime; it just overwrites the same two files + shortcut.
5+
'
6+
' Why a plain shortcut-to-the-package-tree doesn't work: a .lnk's ICON path is read once, when
7+
' the shortcut is opened — unlike iview_app.vbs's own launch target, which it re-resolves live
8+
' via Julia every run, a .lnk can't dynamically look up its icon file, so an icon path pointing
9+
' into the Pkg-hash-changing tree would eventually show a broken icon.
10+
'
11+
' Fix: copy the two files that need a truly permanent, unchanging home — iview_app.vbs (which
12+
' re-resolves InteractiveGMT's actual location at every launch, so ITS content never goes stale)
13+
' and igmt.ico (a static asset that doesn't change between versions) — to the Desktop ONCE, then
14+
' point the shortcut at those local copies. After this, the Desktop icon never needs touching
15+
' again, no matter how many times InteractiveGMT's Pkg-hash directory changes underneath it.
16+
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
17+
Dim sh : Set sh = CreateObject("WScript.Shell")
18+
19+
Dim tmp : tmp = sh.ExpandEnvironmentStrings("%TEMP%") & "\igmt_locate_" & CStr(Timer) & ".jl"
20+
Dim f : Set f = fso.CreateTextFile(tmp, True)
21+
f.WriteLine "p = Base.find_package(" & Chr(34) & "InteractiveGMT" & Chr(34) & ")"
22+
f.WriteLine "print(p === nothing ? " & Chr(34) & Chr(34) & " : dirname(dirname(p)))"
23+
f.Close
24+
25+
Dim ex : Set ex = sh.Exec("julia --startup-file=no " & Chr(34) & tmp & Chr(34))
26+
Dim pkgRoot : pkgRoot = Trim(ex.StdOut.ReadAll())
27+
fso.DeleteFile tmp, True
28+
29+
If pkgRoot = "" Then
30+
MsgBox "Could not locate InteractiveGMT." & vbCrLf & _
31+
"Is it added ('] add https://github.com/GenericMappingTools/InteractiveGMT') or dev'd in Julia's default environment?", _
32+
vbExclamation, "iGMT"
33+
WScript.Quit 1
34+
End If
35+
36+
' NEVER sh.SpecialFolders("Desktop") -- if Windows/OneDrive has Desktop redirected into OneDrive
37+
' ("Known Folder Move", common on managed machines), that call silently returns the OneDrive path
38+
' and everything below would get copied straight into cloud sync. Force the real local Desktop.
39+
Dim desktop : desktop = sh.ExpandEnvironmentStrings("%USERPROFILE%") & "\Desktop"
40+
fso.CopyFile pkgRoot & "\iview_app.vbs", desktop & "\iview_app.vbs", True
41+
fso.CopyFile pkgRoot & "\deps\assets\igmt.ico", desktop & "\igmt.ico", True
42+
43+
Dim link : Set link = sh.CreateShortcut(desktop & "\iGMT.lnk")
44+
link.TargetPath = desktop & "\iview_app.vbs"
45+
link.IconLocation = desktop & "\igmt.ico"
46+
link.WindowStyle = 7
47+
link.Save
48+
49+
MsgBox "iGMT Desktop shortcut created (or refreshed). You can run this setup script again anytime -- it's idempotent.", vbInformation, "iGMT"

iview_app.vbs

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,48 @@
22
' STARTUPINFO SW_HIDE, which the Qt GUI window would inherit and stay invisible. iview_app.jl
33
' hides its own console on startup, so only the viewer window remains.
44
'
5-
' Resolves InteractiveGMT's install path by ASKING JULIA at every launch (Base.find_package —
6-
' just reads the active project's Manifest, does not load/precompile the package) instead of
7-
' hardcoding a location. This matters because a git-based Pkg install lives in a content-hashed
8-
' folder (~/.julia/packages/InteractiveGMT/<hash>/) that gets a NEW <hash> on every
9-
' `Pkg.update("InteractiveGMT")` — a script that instead finds its OWN folder (fso.GetParentFolderName)
10-
' would go stale the moment you copy it to a Desktop shortcut and then update. Asking Julia fresh
11-
' every time means the SAME copy of this file — wherever you put it, including a Desktop shortcut
12-
' — keeps working across every future update, no re-copying, ever.
5+
' Path resolution, fast path first:
6+
' 1. If iview_app.jl sits right next to this script (running in place -- a dev checkout, or
7+
' inside a live Pkg package folder), use this script's own folder. Zero overhead, exactly
8+
' one julia.exe launch, same speed as always.
9+
' 2. Only if this is a DETACHED copy (e.g. sitting on your Desktop, so iview_app.jl is NOT next
10+
' to it) does it fall back to scanning ~/.julia/packages/InteractiveGMT/* for the
11+
' newest-modified folder -- a git-based Pkg install lives in a content-hashed folder that
12+
' gets a NEW hash on every Pkg.update, so a Desktop copy of this file needs SOME way to find
13+
' the current one. This is a plain filesystem scan, not a Julia subprocess -- still only one
14+
' julia.exe launch total, never two.
1315
'
14-
' Also works unmodified for a plain dev checkout (this file run in place): Base.find_package
15-
' resolves `dev`ed packages from the Manifest too, same as `add`ed ones.
16-
'
17-
' The lookup expression is written to a temp .jl file rather than passed inline on the command
18-
' line, to sidestep Windows/VBScript quote-escaping entirely.
16+
' (An earlier version asked Julia itself, via a second julia.exe subprocess, to resolve the path
17+
' on every launch -- correct, but doubled startup time. Don't reintroduce that.)
1918
'
2019
' Files dropped ONTO the desktop shortcut arrive here as WScript.Arguments; we forward each path
2120
' to Julia, and iview_app.jl opens it (otherwise, with no args, it opens an empty launcher).
2221
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
2322
Dim sh : Set sh = CreateObject("WScript.Shell")
2423

25-
Dim tmp : tmp = sh.ExpandEnvironmentStrings("%TEMP%") & "\igmt_locate_" & CStr(Timer) & ".jl"
26-
Dim f : Set f = fso.CreateTextFile(tmp, True)
27-
f.WriteLine "p = Base.find_package(" & Chr(34) & "InteractiveGMT" & Chr(34) & ")"
28-
f.WriteLine "print(p === nothing ? " & Chr(34) & Chr(34) & " : dirname(dirname(p)))"
29-
f.Close
24+
Dim here : here = fso.GetParentFolderName(WScript.ScriptFullName)
3025

31-
Dim ex : Set ex = sh.Exec("julia --startup-file=no " & Chr(34) & tmp & Chr(34))
32-
Dim here : here = Trim(ex.StdOut.ReadAll())
33-
fso.DeleteFile tmp, True
26+
If Not fso.FileExists(here & "\iview_app.jl") Then
27+
' Detached copy -- find the newest InteractiveGMT folder in the Pkg depot.
28+
Dim depot : depot = sh.ExpandEnvironmentStrings("%USERPROFILE%") & "\.julia\packages\InteractiveGMT"
29+
here = ""
30+
If fso.FolderExists(depot) Then
31+
Dim subFolder, best
32+
best = -1
33+
For Each subFolder In fso.GetFolder(depot).SubFolders
34+
If fso.FileExists(subFolder.Path & "\iview_app.jl") Then
35+
If CDbl(subFolder.DateLastModified) > best Then
36+
best = CDbl(subFolder.DateLastModified)
37+
here = subFolder.Path
38+
End If
39+
End If
40+
Next
41+
End If
42+
End If
3443

3544
If here = "" Then
3645
MsgBox "Could not locate InteractiveGMT." & vbCrLf & _
37-
"Is it added ('] add https://github.com/GenericMappingTools/InteractiveGMT') or dev'd in Julia's default environment?", _
46+
"Is it added ('] add https://github.com/GenericMappingTools/InteractiveGMT') in Julia's default environment?", _
3847
vbExclamation, "iGMT"
3948
WScript.Quit 1
4049
End If

0 commit comments

Comments
 (0)