From e5fcc81ee3cd14335c95a4d1f0cd0150a29cacff Mon Sep 17 00:00:00 2001 From: monofuel Date: Fri, 9 Jan 2026 18:28:42 -0500 Subject: [PATCH 1/2] add a function to get a platform-specific home directory --- src/windy/platforms/emscripten/platform.nim | 3 +++ src/windy/platforms/linux/x11.nim | 12 +++++++++++- src/windy/platforms/macos/platform.nim | 7 ++++++- src/windy/platforms/win32/platform.nim | 7 ++++++- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/windy/platforms/emscripten/platform.nim b/src/windy/platforms/emscripten/platform.nim index 62b9d2f..cfdc10d 100644 --- a/src/windy/platforms/emscripten/platform.nim +++ b/src/windy/platforms/emscripten/platform.nim @@ -788,6 +788,9 @@ proc `onDownloadProgress=`*(handle: HttpRequestHandle, callback: HttpProgressCal if state == nil: return state.onDownloadProgress = callback +proc getConfigHome*(appName: string): string = + raise newException(Exception, "getConfigHome is not supported on emscripten") + proc openTempTextFile*(title, text: string) = ## Open a new tab in the browser. open_temp_text_file(title.cstring, text.cstring) diff --git a/src/windy/platforms/linux/x11.nim b/src/windy/platforms/linux/x11.nim index 56c812b..ea8537c 100644 --- a/src/windy/platforms/linux/x11.nim +++ b/src/windy/platforms/linux/x11.nim @@ -1,5 +1,5 @@ import - std/[os, sequtils, sets, strformat, strutils, times, unicode, uri], + std/[os, sequtils, sets, strformat, strutils, times, unicode, uri, pathnorm], ../../[common, internal], vmath, pixie, x11/[glx, keysym, x, xevent, xlib, xcursor] @@ -1327,6 +1327,16 @@ proc url*(window: Window): string = ## Url cannot be gotten on linux. warn "Url cannot be gotten on linux" +proc getConfigHome*(appName: string): string = + ## Returns the platform-appropriate user config directory for the given app name. + ## For Linux: Honors XDG_CONFIG_HOME, defaults to ~/.config/. + let xdgConfigHome = getEnv("XDG_CONFIG_HOME") + if xdgConfigHome != "": + result = (xdgConfigHome / appName).normalizePath + else: + result = (getHomeDir() / ".config" / appName).normalizePath + + proc openUrl*(url: string) = ## Open a URL in the default browser. discard execShellCmd("xdg-open " & url) diff --git a/src/windy/platforms/macos/platform.nim b/src/windy/platforms/macos/platform.nim index 6081c3c..df5fe99 100644 --- a/src/windy/platforms/macos/platform.nim +++ b/src/windy/platforms/macos/platform.nim @@ -1,5 +1,5 @@ import - std/[os, times, unicode], + std/[os, times, unicode, pathnorm], opengl, pixie/fileformats/png, pixie/images, utils, vmath, ../../[common, internal], macdefs @@ -1094,6 +1094,11 @@ proc getScreens*(): seq[Screen] = primary: i == 0 ) +proc getConfigHome*(appName: string): string = + ## Returns the platform-appropriate user config directory for the given app name. + ## For macOS: Returns ~/Library/Application Support/. + result = (getHomeDir() / "Library" / "Application Support" / appName).normalizePath + proc openTempTextFile*(title, text: string) = ## Open a text file in the default text editor. if not dirExists("tmp"): diff --git a/src/windy/platforms/win32/platform.nim b/src/windy/platforms/win32/platform.nim index 37582c2..47e6e99 100644 --- a/src/windy/platforms/win32/platform.nim +++ b/src/windy/platforms/win32/platform.nim @@ -1,5 +1,5 @@ import - std/[os, times, unicode, strutils, tables], + std/[os, times, unicode, strutils, tables, pathnorm], ../../[common, internal], flatty/binny, pixie/fileformats/png, pixie/fileformats/bmp, pixie/images, urlly, utils, vmath, windefs, zippy @@ -2492,6 +2492,11 @@ proc forceButtonReleased*(window: Window, button: Button) = ## This is used for simulating UI tests. window.handleButtonRelease(button) +proc getConfigHome*(appName: string): string = + ## Returns the platform-appropriate user config directory for the given app name. + ## For Windows: Returns %APPDATA%\. + result = (getEnv("APPDATA") / appName).normalizePath + proc openTempTextFile*(title, text: string) = ## Open a text file in the default text editor. if not dirExists("tmp"): From 870b81de054d9e23fa4c46fa755dcf0338cd70fb Mon Sep 17 00:00:00 2001 From: monofuel Date: Mon, 12 Jan 2026 19:19:18 -0500 Subject: [PATCH 2/2] rm newline --- src/windy/platforms/linux/x11.nim | 1 - 1 file changed, 1 deletion(-) diff --git a/src/windy/platforms/linux/x11.nim b/src/windy/platforms/linux/x11.nim index ea8537c..528d559 100644 --- a/src/windy/platforms/linux/x11.nim +++ b/src/windy/platforms/linux/x11.nim @@ -1336,7 +1336,6 @@ proc getConfigHome*(appName: string): string = else: result = (getHomeDir() / ".config" / appName).normalizePath - proc openUrl*(url: string) = ## Open a URL in the default browser. discard execShellCmd("xdg-open " & url)