diff --git a/Application/Dopamine/UI/DOUIManager.h b/Application/Dopamine/UI/DOUIManager.h index 907c966a2..0ee67e8e9 100644 --- a/Application/Dopamine/UI/DOUIManager.h +++ b/Application/Dopamine/UI/DOUIManager.h @@ -16,6 +16,7 @@ NS_ASSUME_NONNULL_BEGIN { DOPreferenceManager *_preferenceManager; NSDictionary *_fallbackLocalizations; + NSLock *_logLock; } @property (nonatomic, retain) NSObject *logView; diff --git a/Application/Dopamine/UI/DOUIManager.m b/Application/Dopamine/UI/DOUIManager.m index 318a268fc..7c70189c4 100644 --- a/Application/Dopamine/UI/DOUIManager.m +++ b/Application/Dopamine/UI/DOUIManager.m @@ -26,6 +26,7 @@ - (id)init if (self = [super init]){ _preferenceManager = [DOPreferenceManager sharedManager]; _logRecord = [NSMutableArray new]; + _logLock = [NSLock new]; } return self; } @@ -209,12 +210,17 @@ - (void)sendLog:(NSString*)log debug:(BOOL)debug update:(BOOL)update { if (!self.logView || !log) return; - + + [_logLock lock]; + [self.logRecord addObject:log]; BOOL isDebug = self.logView.class == DODebugLogView.class; - if (debug && !isDebug) + if (debug && !isDebug) { + [_logLock unlock]; return; + } + if (update) { if ([self.logView respondsToSelector:@selector(updateLog:)]) { @@ -224,6 +230,7 @@ - (void)sendLog:(NSString*)log debug:(BOOL)debug update:(BOOL)update else { [self.logView showLog:log]; } + [_logLock unlock]; } - (void)sendLog:(NSString*)log debug:(BOOL)debug @@ -273,6 +280,9 @@ - (void)startLogCapture while ((bytes_read = read(stdout_pipe[0], buffer, sizeof(buffer) - 1)) > 0) { @autoreleasepool { + // Tee: Write back to the original standard output + write(stdout_orig[1], buffer, bytes_read); + buffer[bytes_read] = '\0'; // Null terminate to handle as string for (int i = 0; i < bytes_read; ++i) { if (buffer[i] == '\n') { @@ -286,8 +296,6 @@ - (void)startLogCapture } } } - // Tee: Write back to the original standard output - write(stdout_orig[1], buffer, bytes_read); } } close(stdout_pipe[0]);