Lagrange [release]

macOS: Fixed crash when opening URL via system handler

=> 92ee58bcb1b3eeba2527271896cae6dad66cd11d

diff --git a/res/about/version.gmi b/res/about/version.gmi
index c7ec17a3..8e05e71f 100644
--- a/res/about/version.gmi
+++ b/res/about/version.gmi
@@ -8,6 +8,7 @@
 
 ## 1.13.8
 * Fixed issues with text selection and range visualization.
+* macOS: Fixed crash when opening URLs via system handler when no windows open.
 
 ## 1.13.7
 * Fixed reporting of errors related to a proxy server certificate.
diff --git a/src/app.c b/src/app.c
index ad9eb46b..94462763 100644
--- a/src/app.c
+++ b/src/app.c
@@ -182,6 +182,8 @@ struct Impl_App {
 
 static iApp app_;
 
+static iBool handleNonWindowRelatedCommand_App_(iApp *d, const char *cmd);
+    
 /*----------------------------------------------------------------------------------------------*/
 
 iDeclareType(Ticker)
@@ -1578,11 +1580,18 @@ void processEvents_App(enum iAppEventMode eventMode) {
                 d->isSuspended = iTrue;
                 break;
             case SDL_APP_TERMINATING:
-                setFreezeDraw_MainWindow(d->window, iTrue);
+                if (d->window) {
+                    setFreezeDraw_MainWindow(d->window, iTrue);
+                }
                 savePrefs_App_(d);
                 saveState_App_(d);
                 break;
             case SDL_DROPFILE: {
+                if (!d->window) {
+                    /* Need to open an empty window now. */
+                    handleNonWindowRelatedCommand_App_(d, "window.new url:");
+                    iAssert(d->window);
+                }
                 iBool wasUsed = processEvent_Window(as_Window(d->window), &ev);
                 if (!wasUsed) {
                     iBool newTab = iFalse;
@@ -2249,12 +2258,14 @@ size_t windowIndex_App(const iMainWindow *win) {
     return indexOf_PtrArray(&app_.mainWindows, win); 
 }
 
+#if 0
 iMainWindow *newMainWindow_App(void) {
     iApp *d = &app_;
     iMainWindow *win = new_MainWindow(initialWindowRect_App_(d, size_PtrArray(&d->mainWindows)));
     addWindow_App(win);
     return win;
 }
+#endif
 
 const iPtrArray *mainWindows_App(void) {
     return &app_.mainWindows;
@@ -3249,7 +3260,10 @@ static iBool handleNonWindowRelatedCommand_App_(iApp *d, const char *cmd) {
             loadState_App_(d);
         }
         if (hasLabel_Command(cmd, "url")) {
-            postCommandf_Root(newWin->base.roots[0], "~open %s", cmd + 11 /* all arguments passed on */);
+            const char *urlAndArgs = cmd + 11; /* all arguments to "window.new" passed on */
+            if (strlen(suffixPtr_Command(cmd, "url")) /* not empty URL */) {
+                postCommandf_Root(newWin->base.roots[0], "~open %s", urlAndArgs);
+            }
         }
         else {
             postCommand_Root(newWin->base.roots[0], "~navigate.home");
diff --git a/src/app.h b/src/app.h
index fffa304d..137f07cb 100644
--- a/src/app.h
+++ b/src/app.h
@@ -134,7 +134,7 @@ void        setActiveWindow_App (iMainWindow *win);
 void        closeWindow_App     (iMainWindow *win);
 size_t      numWindows_App      (void);
 size_t      windowIndex_App     (const iMainWindow *win);
-iMainWindow *newMainWindow_App  (void);
+//iMainWindow *newMainWindow_App  (void);
 const iPtrArray *mainWindows_App(void);
 iMainWindow *    mainWindow_App (void); /* currently active main window */
 void        addPopup_App        (iWindow *popup);
Proxy Information
Original URL
gemini://git.skyjake.fi/lagrange/release/cdiff/92ee58bcb1b3eeba2527271896cae6dad66cd11d
Status Code
Success (20)
Meta
text/gemini; charset=utf-8
Capsule Response Time
26.130289 milliseconds
Gemini-to-HTML Time
0.188245 milliseconds

This content has been proxied by September (ba2dc).