Skip to content

Commit

Permalink
Don't lock up app on close on macos
Browse files Browse the repository at this point in the history
  • Loading branch information
tmolitor-stud-tu committed Jan 4, 2025
1 parent 664d3a0 commit 6aedd4c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
1 change: 1 addition & 0 deletions Monal/Classes/HelperTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ void swizzle(Class c, SEL orig, SEL new);
+(BOOL) isAppSuspended;
+(void) signalSuspension;
+(void) signalResumption;
+(void) activateTerminationLogging;
+(void) __attribute__((noreturn)) MLAssertWithText:(NSString*) text andUserData:(id _Nullable) additionalData andFile:(const char* const) file andLine:(int) line andFunc:(const char* const) func;
+(void) __attribute__((noreturn)) handleRustPanicWithText:(NSString*) text andBacktrace:(NSString*) backtrace;
+(void) __attribute__((noreturn)) throwExceptionWithName:(NSString*) name reason:(NSString*) reason userInfo:(NSDictionary* _Nullable) userInfo;
Expand Down
20 changes: 16 additions & 4 deletions Monal/Classes/HelperTools.m
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ -(void) swizzled_queueLogMessage:(DDLogMessage*) logMessage asynchronously:(BOOL
void exitLogging(void)
{
DDLogInfo(@"exit() was called...");
[HelperTools flushLogsWithTimeout:0.250];
//make sure to unfreeze logging before flushing everything and terminating
[HelperTools activateTerminationLogging];
[HelperTools flushLogsWithTimeout:0.025];
return;
}

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

//log error and flush all logs
[DDLog flushLog];
DDLogError(@"*****************\n%@\n%@", abort_msg, backtrace);
[DDLog flushLog];
[HelperTools flushLogsWithTimeout:0.250];
[HelperTools flushLogsWithTimeout:0.025];

//now abort everything
abort();
Expand Down Expand Up @@ -2212,6 +2212,18 @@ +(void) signalResumption
}
}

+(void) activateTerminationLogging
{
@synchronized(_suspensionHandling_lock) {
if(_suspensionHandling_isSuspended)
{
DDLogVerbose(@"Activating logging for app termination...");
dispatch_resume([DDLog loggingQueue]);
_suspensionHandling_isSuspended = NO;
}
}
}

+(void) configureXcodeLogging
{
//only start console logger
Expand Down
8 changes: 4 additions & 4 deletions Monal/Classes/MonalAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -1244,23 +1244,23 @@ -(void) applicationDidEnterBackground:(UIApplication*) application
#endif
}

-(void) applicationWillTerminate:(UIApplication *)application
-(void) applicationWillTerminate:(UIApplication*) application
{
@synchronized(self) {
[HelperTools activateTerminationLogging]; //activate logging during shutdown
DDLogVerbose(@"Setting _shutdownPending to YES...");
_shutdownPending = YES;
DDLogWarn(@"|~~| T E R M I N A T I N G |~~|");
[HelperTools scheduleBackgroundTask:YES]; //make sure delivery will be attempted, if needed (force as soon as possible)
[HelperTools scheduleBackgroundTask:YES]; //make sure delivery will be attempted, if needed (force as soon as possible)
DDLogInfo(@"|~~| 33%% |~~|");
[[MLXMPPManager sharedInstance] nowBackgrounded];
DDLogInfo(@"|~~| 66%% |~~|");
[HelperTools updateSyncErrorsWithDeleteOnly:NO andWaitForCompletion:YES];
DDLogInfo(@"|~~| 99%% |~~|");
[[MLXMPPManager sharedInstance] disconnectAll];
DDLogInfo(@"|~~| T E R M I N A T E D |~~|");
[DDLog flushLog];
[HelperTools activateTerminationLogging]; //ensure our flush is really successful
[HelperTools flushLogsWithTimeout:0.025];
[DDLog flushLog];
}
}

Expand Down
2 changes: 0 additions & 2 deletions Monal/NotificationService/NotificationService.m
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ -(void) killAppex
[NotificationService setAppexCleanShutdownStatus:YES];

DDLogInfo(@"Now killing appex process, goodbye...");
[HelperTools flushLogsWithTimeout:0.100];
exit(0);
}

Expand Down Expand Up @@ -605,7 +604,6 @@ -(void) serviceExtensionTimeWillExpire
#endif

DDLogInfo(@"Committing suicide...");
[HelperTools flushLogsWithTimeout:0.100];
exit(0);

/*
Expand Down

0 comments on commit 6aedd4c

Please sign in to comment.