Skip to content

Commit

Permalink
Merge pull request #178 from google/issue_171
Browse files Browse the repository at this point in the history
fix issue 171 make app usage logging more robust
  • Loading branch information
rundong08 authored Sep 11, 2023
2 parents a24845e + dc04fed commit db35128
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions pal_event_server/lib/src/loggers/app_usage/macos/macos_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,33 @@ String _prevAppAndWindowName;
// Run Apple Script for the active window
void macOSAppLoggerIsolate(SendPort sendPort) {
Timer.periodic(queryInterval, (Timer _) {
Process.run(apple_script.command, apple_script.scriptArgs).then((result) {
final currWindow = result.stdout.trim();
if (currWindow != '') {
final resultMap = apple_script.buildResultMap(currWindow);
final currAppAndWindowName =
resultMap[appNameField] + resultMap[windowNameField];

if (currAppAndWindowName != _prevAppAndWindowName) {
// Send APP_CLOSED
if (_prevAppAndWindowName != null &&
_prevAppAndWindowName.isNotEmpty) {
sendPort.send(_prevAppAndWindowName);
}

_prevAppAndWindowName = currAppAndWindowName;

// Send PacoEvent && APP_USAGE
if (resultMap != null) {
sendPort.send(resultMap);
try {
Process.run(apple_script.command, apple_script.scriptArgs).then((result) {
final currWindow = result.stdout.trim();
if (currWindow != '') {
final resultMap = apple_script.buildResultMap(currWindow);
final currAppAndWindowName =
resultMap[appNameField] + resultMap[windowNameField];

if (currAppAndWindowName != _prevAppAndWindowName) {
// Send APP_CLOSED
if (_prevAppAndWindowName != null &&
_prevAppAndWindowName.isNotEmpty) {
sendPort.send(_prevAppAndWindowName);
}

_prevAppAndWindowName = currAppAndWindowName;

// Send PacoEvent && APP_USAGE
if (resultMap != null) {
sendPort.send(resultMap);
}
}
}
}
});
});
} catch (e, s) {
print('Exception details:\n $e');
print('Stack trace:\n $s');
}
});
}

0 comments on commit db35128

Please sign in to comment.