Skip to content

Commit 880cb51

Browse files
author
Charlie Fenton
committed
Mac: Fix bugs in Mac installer
1 parent ef79b98 commit 880cb51

File tree

7 files changed

+73
-63
lines changed

7 files changed

+73
-63
lines changed

client/check_security.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,11 @@ int use_sandbox, int isManager, char* path_to_error, int len
163163

164164
#ifdef __APPLE__
165165
char DataDirPath[MAXPATHLEN];
166+
#ifdef _MAC_INSTALLER
167+
strlcpy(DataDirPath, dataPath, sizeof(dir_path)); // Installer
168+
#else
166169
getcwd(DataDirPath, sizeof(DataDirPath));
167-
170+
#endif
168171
snprintf(full_path, sizeof(full_path),
169172
"%s/%s", DataDirPath, FIX_BOINC_USERS_FILENAME
170173
);

clientgui/AdvancedFrame.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
#include "ViewProjects.h"
5151
#include "ViewWork.h"
5252
#include "ViewTransfers.h"
53-
#include "ViewMessages.h"
5453
#include "ViewStatistics.h"
5554
#include "ViewResources.h"
5655
#include "DlgAbout.h"
@@ -1567,6 +1566,7 @@ void CAdvancedFrame::OnRefreshView(CFrameEvent& WXUNUSED(event)) {
15671566
if (IsShown()) {
15681567
CMainDocument* pDoc = wxGetApp().GetDocument();
15691568
CBOINCBaseView* pView = NULL;
1569+
wxTimerEvent timerEvent;
15701570
wxString strTabTitle = wxEmptyString;
15711571
int iCount = 0;
15721572
static int iLastCount = 0;
@@ -1996,6 +1996,7 @@ void CAdvancedFrame::OnDarkModeChanged( wxSysColourChangedEvent& WXUNUSED(event)
19961996
CBOINCBaseView* theView = NULL;;
19971997
CBOINCListCtrl* theListCtrl = NULL;
19981998
long bottomItem;
1999+
wxTimerEvent timerEvent;
19992000
int currentPage = _GetCurrentViewPage();
20002001

20012002
StopTimers();

clientgui/BOINCGUIApp.cpp

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is part of BOINC.
22
// http://boinc.berkeley.edu
3-
// Copyright (C) 2024 University of California
3+
// Copyright (C) 2025 University of California
44
//
55
// BOINC is free software; you can redistribute it and/or modify it
66
// under the terms of the GNU Lesser General Public License
@@ -69,33 +69,7 @@ BEGIN_EVENT_TABLE (CBOINCGUIApp, wxApp)
6969
#endif
7070
END_EVENT_TABLE ()
7171

72-
#if defined(__WXGTK__) && defined(BUILD_WITH_VCPKG)
73-
extern "C" {
74-
void _gdk_pixbuf__svg_fill_info (void*);
75-
void _gdk_pixbuf__svg_fill_vtable (void*);
76-
unsigned int rsvg_error_quark (void);
77-
void rsvg_handle_get_pixbuf (void*);
78-
}
79-
80-
typedef void (*GdkPixbufFillInfo) (void*);
81-
typedef void (*GdkPixbufFillVtable) (void*);
82-
typedef unsigned int (*RsvgErrorQuark) (void);
83-
typedef void (*RsvgHandleGetPixbuf) (void*);
84-
#endif
85-
8672
bool CBOINCGUIApp::OnInit() {
87-
#if defined(__WXGTK__) && defined(BUILD_WITH_VCPKG)
88-
try {
89-
GdkPixbufFillInfo fi = _gdk_pixbuf__svg_fill_info;
90-
GdkPixbufFillVtable fv = _gdk_pixbuf__svg_fill_vtable;
91-
RsvgErrorQuark eq = rsvg_error_quark;
92-
RsvgHandleGetPixbuf hp = rsvg_handle_get_pixbuf;
93-
fi(NULL);
94-
fv(NULL);
95-
eq();
96-
hp(NULL);
97-
} catch (...) {}
98-
#endif
9973
// Initialize globals
10074
#ifdef SANDBOX
10175
g_use_sandbox = true;
@@ -149,6 +123,7 @@ bool CBOINCGUIApp::OnInit() {
149123
m_iDisplayAnotherInstanceRunningDialog = 1;
150124
#ifdef __WXMAC__
151125
m_iHideMenuBarIcon = 0;
126+
m_iWasShutDownBySystem = 0;
152127
#endif
153128
m_iGUISelected = BOINC_SIMPLEGUI;
154129
m_bSafeMessageBoxDisplayed = 0;
@@ -232,6 +207,18 @@ bool CBOINCGUIApp::OnInit() {
232207
m_pConfig->Read(wxT("DisplayAnotherInstanceRunningDialog"), &m_iDisplayAnotherInstanceRunningDialog, 1L);
233208
#ifdef __WXMAC__
234209
m_pConfig->Read(wxT("HideMenuBarIcon"), &m_iHideMenuBarIcon, 0L);
210+
m_pConfig->Read(wxT("WasShutDownBySystem"), &m_iWasShutDownBySystem, 0L);
211+
// If Manager was hidden and was shut down by system when user last logged
212+
// out, MacOS's "Reopen windows when logging in" functionality may relaunch
213+
// us visible before our LaunchAgent launches us with the "autostart" arg.
214+
// QuitAppleEventHandler() set m_iWasShutDownBySystem to 1, causing
215+
// CBOINCGUIApp::SaveState to set WasShutDownBySystem in our configuraiton
216+
// file to tell us to treat this as an autostart and launch hidden.
217+
if (m_iWasShutDownBySystem) {
218+
m_iWasShutDownBySystem = 0;
219+
m_bBOINCMGRAutoStarted = true;
220+
m_bGUIVisible = false;
221+
}
235222
#endif
236223
m_pConfig->Read(wxT("DisableAutoStart"), &m_iBOINCMGRDisableAutoStart, 0L);
237224
m_pConfig->Read(wxT("LanguageISO"), &m_strISOLanguageCode, wxT(""));
@@ -490,6 +477,10 @@ bool CBOINCGUIApp::OnInit() {
490477
// Detect if BOINC Manager is already running, if so, bring it into the
491478
// foreground and then exit.
492479
if (DetectDuplicateInstance()) {
480+
#ifdef __WXMAC__
481+
// Hack to work around an issue with the Mac Installer
482+
if (m_bBOINCMGRAutoStarted) return false;
483+
#endif
493484
if (GetBOINCMGRDisplayAnotherInstanceRunningMessage()) {
494485
wxString appName = m_pSkinManager->GetAdvanced()->GetApplicationName();
495486
wxString message;
@@ -686,6 +677,7 @@ void CBOINCGUIApp::SaveState() {
686677
m_pConfig->Write(wxT("DisplayAnotherInstanceRunningDialog"), m_iDisplayAnotherInstanceRunningDialog);
687678
#ifdef __WXMAC__
688679
m_pConfig->Write(wxT("HideMenuBarIcon"), m_iHideMenuBarIcon);
680+
m_pConfig->Write(wxT("WasShutDownBySystem"), m_iWasShutDownBySystem);
689681
#endif
690682
m_pConfig->Write(wxT("DisableAutoStart"), m_iBOINCMGRDisableAutoStart);
691683
m_pConfig->Write(wxT("RunDaemon"), m_bRunDaemon);
@@ -1105,19 +1097,17 @@ int CBOINCGUIApp::IdleTrackerDetach() {
11051097
void CBOINCGUIApp::OnActivateApp(wxActivateEvent& event) {
11061098
m_bProcessingActivateAppEvent = true;
11071099

1108-
1109-
#ifndef __WXMSW__ // On Win, the following raises the wrong window
1110-
if (event.GetActive())
1111-
#endif
1112-
{
1100+
if (event.GetActive()) {
11131101
#ifdef __WXMAC__
11141102
ShowInterface();
1115-
#elif defined(__WXGTK__)
1103+
#else
1104+
#ifdef __WXGTK__
11161105
// Linux allows the Event Log to be brought forward and made active
11171106
// even if we have a modal dialog displayed (associated with our
11181107
// main frame.) This test is needed to allow bringing the modal
11191108
// dialog forward again by clicking on its title bar.
11201109
if (!IsModalDialogDisplayed())
1110+
#endif
11211111
{
11221112
bool keepEventLogInFront = m_bEventLogWasActive;
11231113

clientgui/BOINCGUIApp.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is part of BOINC.
22
// http://boinc.berkeley.edu
3-
// Copyright (C) 2024 University of California
3+
// Copyright (C) 2025 University of California
44
//
55
// BOINC is free software; you can redistribute it and/or modify it
66
// under the terms of the GNU Lesser General Public License
@@ -123,6 +123,7 @@ class CBOINCGUIApp : public wxApp {
123123
int m_iDisplayAnotherInstanceRunningDialog;
124124
#ifdef __WXMAC__
125125
int m_iHideMenuBarIcon;
126+
int m_iWasShutDownBySystem;
126127
#endif
127128

128129
bool m_bGUIVisible;
@@ -202,6 +203,8 @@ class CBOINCGUIApp : public wxApp {
202203
{ return m_iHideMenuBarIcon; }
203204
void SetBOINCMGRHideMenuBarIcon(int iHideMenuBarIcon)
204205
{ m_iHideMenuBarIcon = iHideMenuBarIcon; }
206+
void SetBOINCMGRWasShutDownBySystem(int val)
207+
{ m_iWasShutDownBySystem = val; }
205208
#endif
206209

207210
bool GetRunDaemon()

clientgui/mac/BOINCGUIApp.mm

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is part of BOINC.
22
// http://boinc.berkeley.edu
3-
// Copyright (C) 2016 University of California
3+
// Copyright (C) 2025 University of California
44
//
55
// BOINC is free software; you can redistribute it and/or modify it
66
// under the terms of the GNU Lesser General Public License
@@ -218,6 +218,14 @@ OSErr QuitAppleEventHandler( const AppleEvent *appleEvt, AppleEvent* reply, UInt
218218
if (([bundleID compare:@"com.apple.dock"] != NSOrderedSame)
219219
&& ([bundleID compare:@"edu.berkeley.boinc"] != NSOrderedSame)) {
220220
s_bSkipExitConfirmation = true; // Not from our app, our dock icon or our taskbar icon
221+
if ([ NSApp isHidden ]) {
222+
// If Manager was hidden and was shut down by system when user last logged
223+
// out, MacOS's "Reopen windows when logging in" functionality may relaunch
224+
// us visible before our LaunchAgent launches us with the "autostart" arg.
225+
// Set the WasShutDownBySystem in our configuraiton file to tell us to
226+
// treat this as an autostart and launch hidden.
227+
wxGetApp().SetBOINCMGRWasShutDownBySystem(1);
228+
}
221229
// The following may no longer be needed under wxCocoa-3.0.0
222230
wxGetApp().ExitMainLoop(); // Prevents wxMac from issuing events to closed frames
223231
}

mac_installer/PostInstall.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is part of BOINC.
22
// http://boinc.berkeley.edu
3-
// Copyright (C) 2024 University of California
3+
// Copyright (C) 2025 University of California
44
//
55
// BOINC is free software; you can redistribute it and/or modify it
66
// under the terms of the GNU Lesser General Public License
@@ -61,7 +61,7 @@
6161
#if VERBOSE_TEST
6262
#define CREATE_LOG 1 /* for debugging */
6363
#else
64-
#define CREATE_LOG 0 /* for debugging */
64+
#define CREATE_LOG 1 /* for debugging */
6565
#endif
6666

6767
#define USE_OSASCRIPT_FOR_ALL_LOGGED_IN_USERS false
@@ -693,12 +693,14 @@ int DeleteReceipt()
693693
// Launch Manager hidden (in background, without opening windows)
694694
sprintf(s, "su -l \"%s\" -c 'open -jg \"%s\" --args -s'", pw->pw_name, appPath[brandID]);
695695
err = callPosixSpawn(s);
696-
printf("command: %s returned error %d\n", s, err);
697-
fflush(stdout);
696+
if (err) {
697+
REPORT_ERROR(true);
698+
printf("command: %s returned error %d\n", s, err);
699+
fflush(stdout);
700+
}
698701
}
699702
}
700703
}
701-
702704
return 0;
703705
}
704706

@@ -1833,7 +1835,11 @@ OSErr UpdateAllVisibleUsers(long brandID, long oldBrandID)
18331835

18341836
if (compareOSVersionTo(13, 0) >= 0) {
18351837
deleteLoginItem = true; // Use LaunchAgent to autostart BOINC Manager
1836-
snprintf(s, sizeof(s), "open \"/Library/Application Support/BOINC Data/%s_Finish_Install.app\"", brandName[brandID]);
1838+
// The -i argument tells BOINC_Finish_Install not to "Launchctl load" our
1839+
// LaunchAgent, because doing that launches the Mamager immediately (before
1840+
// we can finish setting things up) and the Mamager starts incorrectly,
1841+
// especially causing problems if starting in SimpleView.
1842+
snprintf(s, sizeof(s), "open \"/Library/Application Support/BOINC Data/%s_Finish_Install.app\" --args -i", brandName[brandID]);
18371843
err = callPosixSpawn(s);
18381844
REPORT_ERROR(err);
18391845
if (err) {

mac_installer/finish_install.cpp

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is part of BOINC.
22
// http://boinc.berkeley.edu
3-
// Copyright (C) 2023 University of California
3+
// Copyright (C) 2025 University of California
44
//
55
// BOINC is free software; you can redistribute it and/or modify it
66
// under the terms of the GNU Lesser General Public License
@@ -31,12 +31,10 @@
3131

3232
#define VERBOSE_TEST 0 /* for debugging callPosixSpawn */
3333
#if VERBOSE_TEST
34-
#define CREATE_LOG 0 /* for debugging */
34+
#define CREATE_LOG 1 /* for debugging */
3535
#else
3636
#define CREATE_LOG 0 /* for debugging */
3737
#endif
38-
#define USE_SPECIAL_LOG_FILE 1
39-
4038

4139
#include <Carbon/Carbon.h>
4240

@@ -72,6 +70,7 @@ int main(int argc, const char * argv[]) {
7270
passwd *pw;
7371
bool isUninstall = false;
7472
int iBrandId = 0;
73+
bool calledFromInstaller = false;
7574

7675
// Wait until we are the active login (in case of fast user switching)
7776
userName = getenv("USER");
@@ -92,10 +91,13 @@ int main(int argc, const char * argv[]) {
9291
}
9392

9493
for (i=1; i<argc; i++) {
94+
print_to_log_file("argv[%d] = '%s'", i, argv[i]);
9595
if (strcmp(argv[i], "-d") == 0) {
9696
isUninstall = true;
97-
} else if (strcmp(argv[i], "-a") != 0) {
97+
} else if (strcmp(argv[i], "-a") == 0) {
9898
iBrandId = atoi(argv[i]);
99+
} else if (strcmp(argv[i], "-i") == 0) {
100+
calledFromInstaller = true;
99101
}
100102
} // end for (i=i; i<argc; i+=2)
101103

@@ -150,12 +152,15 @@ int main(int argc, const char * argv[]) {
150152
print_to_log_file("returned error %d\n", err);
151153
}
152154

153-
snprintf(cmd, sizeof(cmd), "launchctl load \"/Users/%s/Library/LaunchAgents/edu.berkeley.launchboincmanager.plist\"", pw->pw_name);
154-
err = callPosixSpawn(cmd);
155-
if (err) {
156-
print_to_log_file("Command: %s\n", cmd);
157-
print_to_log_file("returned error %d\n", err);
155+
if (! calledFromInstaller) {
156+
snprintf(cmd, sizeof(cmd), "launchctl load \"/Users/%s/Library/LaunchAgents/edu.berkeley.launchboincmanager.plist\"", pw->pw_name);
157+
err = callPosixSpawn(cmd);
158+
if (err) {
159+
print_to_log_file("Command: %s\n", cmd);
160+
print_to_log_file("returned error %d\n", err);
161+
}
158162
}
163+
159164
} else {
160165
snprintf(cmd, sizeof(cmd), "open -jg \"%s\"", appPath[iBrandId]);
161166
err = callPosixSpawn(cmd);
@@ -527,18 +532,14 @@ static void print_to_log_file(const char *format, ...) {
527532
va_list args;
528533
char buf[256];
529534
time_t t;
530-
#if USE_SPECIAL_LOG_FILE
531-
strlcpy(buf, getenv("HOME"), sizeof(buf));
532-
strlcat(buf, "/Documents/test_log.txt", sizeof(buf));
535+
sprintf(buf, "/Users/Shared/test_log_finish_install.txt");
533536
FILE *f;
534537
f = fopen(buf, "a");
535538
if (!f) return;
536539

537-
// freopen(buf, "a", stdout);
538-
// freopen(buf, "a", stderr);
539-
#else
540-
#define f stderr
541-
#endif
540+
// File may be owned by various users, so make it world readable & writable
541+
chmod(buf, 0666);
542+
542543
time(&t);
543544
strlcpy(buf, asctime(localtime(&t)), sizeof(buf));
544545

@@ -552,9 +553,7 @@ static void print_to_log_file(const char *format, ...) {
552553
va_end(args);
553554

554555
fputs("\n", f);
555-
#if USE_SPECIAL_LOG_FILE
556556
fflush(f);
557557
fclose(f);
558558
#endif
559-
#endif
560559
}

0 commit comments

Comments
 (0)