Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
nullxx committed Apr 30, 2020
1 parent 4246941 commit d0b796f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 8 deletions.
16 changes: 8 additions & 8 deletions windowDetector/main.m → windowDetector/windowDetector.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// main.m
// windowDetector.h
// windowDetector
//
// Created by Jon Lara Trigo on 28/04/2020.
Expand All @@ -8,10 +8,10 @@

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
@autoreleasepool {
// insert code here...
NSLog(@"Hello, World!");
}
return 0;
}
NS_ASSUME_NONNULL_BEGIN

@interface windowDetector : NSObject

@end

NS_ASSUME_NONNULL_END
58 changes: 58 additions & 0 deletions windowDetector/windowDetector.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// windowDetector.m
// windowDetector
//
// Created by Jon Lara Trigo on 28/04/2020.
// Copyright © 2020 Jon Lara Trigo. All rights reserved.
//

#import "windowDetector.h"
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>

#define NSLog(FORMAT, ...) fprintf(stderr, "%s\n", [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);

@implementation windowDetector

- (id) init
{
self = [super init];
if (!self)
return self;
[[[NSWorkspace sharedWorkspace] notificationCenter]
addObserver:self
selector:@selector(getInfo:)
name:NSWorkspaceDidActivateApplicationNotification
object:nil];

[[[NSWorkspace sharedWorkspace] notificationCenter]
addObserver:self
selector:@selector(getInfo:)
name:NSWorkspaceDidTerminateApplicationNotification object:nil];

return self;
}

- (void) getInfo:(NSNotification *)d
{
NSRunningApplication *app = d.userInfo[NSWorkspaceApplicationKey];

NSDate * now = [NSDate date];
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
[outputFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString *dateString = [outputFormatter stringFromDate:now];

NSLog(@"{\"name\": \"%@\", \"time\": \"%@\", \"bundleIdentifier\": \"%@\",\"launchDate\": \"%@\",\"PID\": \"%d\", \"isTerminated\": %hhd}", [app localizedName], dateString, [app bundleIdentifier], [app launchDate],[app processIdentifier], [app isTerminated]);
}

int main(int argc, const char * argv[]) {
@autoreleasepool
{
NSRunLoop *runLoop = NSRunLoop.currentRunLoop;
windowDetector *w = [[windowDetector alloc] init];
while ([runLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:5]]);
};
return 0;

}
@end

0 comments on commit d0b796f

Please sign in to comment.