From 28e11252071b6f7da6c341d7d7f5ae97666951a8 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Wed, 17 Apr 2019 22:17:19 -0500 Subject: [PATCH] Open up the Finder window for the new disk after it has been mounted. We have to wait through two cycles of the Finder's event loop before asking for it to be opened. Doing it earlier may cause the Finder to crash, presumably because it hasn't registered that a new disk has been inserted and updated its internal data structures accordingly. --- diskbrowser.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/diskbrowser.c b/diskbrowser.c index e153003..7690f1f 100644 --- a/diskbrowser.c +++ b/diskbrowser.c @@ -107,6 +107,10 @@ char *netBuf = NULL; json_value *json = NULL; +int wantToOpenWindow = 0; +GSString32 devName; +struct tellFinderOpenWindowOut tfowOut; + void InstallMenuItem(void) { static MenuItemTemplate menuItem = { /* .version = */ 0x8000, /* show dividing line */ @@ -429,6 +433,12 @@ void MountFile(char *itemID, char *fileName) { SendRequest(MountURL, sendToName|stopAfterOne, (Long)NETDISK_REQUEST_NAME, (Long)&mountURLRec, NULL); + if (mountURLRec.result == OPERATION_SUCCESSFUL) { + devName.length = snprintf(devName.text, sizeof(devName.text), ".D%u", + mountURLRec.devNum); + wantToOpenWindow = 2; + } + free(fileURL); } @@ -457,6 +467,8 @@ void DoMount(void) { enum NetDiskError result = 0; json_value *filesJSON = NULL; + WaitCursor(); + if (itemNumber == 0) { // shouldn't happen result = 1; @@ -492,11 +504,13 @@ void DoMount(void) { processArray(resultJSON, json_object, processFile); errorReturn: - if (result != 0) - ShowErrorAlert(result, mountErrorAlert); if (filesJSON != NULL) json_value_free(filesJSON); free(filesURL); + + InitCursor(); + if (result != 0) + ShowErrorAlert(result, mountErrorAlert); } @@ -673,6 +687,8 @@ void ShowBrowserWindow(void) { lastTargetCtlID = 0; defaultButtonIsSearch = true; + + wantToOpenWindow = 0; cleanup: if (resourceFileOpened && !windowOpened) { @@ -708,6 +724,17 @@ static pascal Word requestProc(Word reqCode, Long dataIn, void *dataOut) { return 0x8000; } break; + + case finderSaysIdle: + /* + * Wait till the Finder has had time to recognize the new disk + * before opening the window for it. Otherwise, it may crash. + */ + if (wantToOpenWindow && --wantToOpenWindow == 0) { + SendRequest(tellFinderOpenWindow, sendToName|stopAfterOne, + (Long)NAME_OF_FINDER, (Long)&devName, (Ptr)&tfowOut); + } + break; case srqGoAway: DoGoAway();