Skip to content

Commit 6aedd4c

Browse files
Don't lock up app on close on macos
1 parent 664d3a0 commit 6aedd4c

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

Monal/Classes/HelperTools.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ void swizzle(Class c, SEL orig, SEL new);
101101
+(BOOL) isAppSuspended;
102102
+(void) signalSuspension;
103103
+(void) signalResumption;
104+
+(void) activateTerminationLogging;
104105
+(void) __attribute__((noreturn)) MLAssertWithText:(NSString*) text andUserData:(id _Nullable) additionalData andFile:(const char* const) file andLine:(int) line andFunc:(const char* const) func;
105106
+(void) __attribute__((noreturn)) handleRustPanicWithText:(NSString*) text andBacktrace:(NSString*) backtrace;
106107
+(void) __attribute__((noreturn)) throwExceptionWithName:(NSString*) name reason:(NSString*) reason userInfo:(NSDictionary* _Nullable) userInfo;

Monal/Classes/HelperTools.m

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ -(void) swizzled_queueLogMessage:(DDLogMessage*) logMessage asynchronously:(BOOL
136136
void exitLogging(void)
137137
{
138138
DDLogInfo(@"exit() was called...");
139-
[HelperTools flushLogsWithTimeout:0.250];
139+
//make sure to unfreeze logging before flushing everything and terminating
140+
[HelperTools activateTerminationLogging];
141+
[HelperTools flushLogsWithTimeout:0.025];
140142
return;
141143
}
142144

@@ -511,10 +513,8 @@ +(void) __attribute__((noreturn)) handleRustPanicWithText:(NSString*) text andBa
511513
_crash_info.backtrace = backtrace.UTF8String;
512514

513515
//log error and flush all logs
514-
[DDLog flushLog];
515516
DDLogError(@"*****************\n%@\n%@", abort_msg, backtrace);
516-
[DDLog flushLog];
517-
[HelperTools flushLogsWithTimeout:0.250];
517+
[HelperTools flushLogsWithTimeout:0.025];
518518

519519
//now abort everything
520520
abort();
@@ -2212,6 +2212,18 @@ +(void) signalResumption
22122212
}
22132213
}
22142214

2215+
+(void) activateTerminationLogging
2216+
{
2217+
@synchronized(_suspensionHandling_lock) {
2218+
if(_suspensionHandling_isSuspended)
2219+
{
2220+
DDLogVerbose(@"Activating logging for app termination...");
2221+
dispatch_resume([DDLog loggingQueue]);
2222+
_suspensionHandling_isSuspended = NO;
2223+
}
2224+
}
2225+
}
2226+
22152227
+(void) configureXcodeLogging
22162228
{
22172229
//only start console logger

Monal/Classes/MonalAppDelegate.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,23 +1244,23 @@ -(void) applicationDidEnterBackground:(UIApplication*) application
12441244
#endif
12451245
}
12461246

1247-
-(void) applicationWillTerminate:(UIApplication *)application
1247+
-(void) applicationWillTerminate:(UIApplication*) application
12481248
{
12491249
@synchronized(self) {
1250+
[HelperTools activateTerminationLogging]; //activate logging during shutdown
12501251
DDLogVerbose(@"Setting _shutdownPending to YES...");
12511252
_shutdownPending = YES;
12521253
DDLogWarn(@"|~~| T E R M I N A T I N G |~~|");
1253-
[HelperTools scheduleBackgroundTask:YES]; //make sure delivery will be attempted, if needed (force as soon as possible)
1254+
[HelperTools scheduleBackgroundTask:YES]; //make sure delivery will be attempted, if needed (force as soon as possible)
12541255
DDLogInfo(@"|~~| 33%% |~~|");
12551256
[[MLXMPPManager sharedInstance] nowBackgrounded];
12561257
DDLogInfo(@"|~~| 66%% |~~|");
12571258
[HelperTools updateSyncErrorsWithDeleteOnly:NO andWaitForCompletion:YES];
12581259
DDLogInfo(@"|~~| 99%% |~~|");
12591260
[[MLXMPPManager sharedInstance] disconnectAll];
12601261
DDLogInfo(@"|~~| T E R M I N A T E D |~~|");
1261-
[DDLog flushLog];
1262+
[HelperTools activateTerminationLogging]; //ensure our flush is really successful
12621263
[HelperTools flushLogsWithTimeout:0.025];
1263-
[DDLog flushLog];
12641264
}
12651265
}
12661266

Monal/NotificationService/NotificationService.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ -(void) killAppex
133133
[NotificationService setAppexCleanShutdownStatus:YES];
134134

135135
DDLogInfo(@"Now killing appex process, goodbye...");
136-
[HelperTools flushLogsWithTimeout:0.100];
137136
exit(0);
138137
}
139138

@@ -605,7 +604,6 @@ -(void) serviceExtensionTimeWillExpire
605604
#endif
606605

607606
DDLogInfo(@"Committing suicide...");
608-
[HelperTools flushLogsWithTimeout:0.100];
609607
exit(0);
610608

611609
/*

0 commit comments

Comments
 (0)