This repository has been archived by the owner on Jan 17, 2018. It is now read-only.
/
ApplicationController.m
103 lines (82 loc) · 3.29 KB
/
ApplicationController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//
// AppDelegate.m
// Perpetual
//
// Created by Kalle Persson on 2/14/12.
// Copyright (c) 2012 Revyver, Inc. All rights reserved.
//
#import "ApplicationController.h"
#import "INAppStoreWindow.h"
#import "PlaybackController.h"
#import "Track.h"
#import "WindowController.h"
// All builds should expire in 4 weeks time.
#define EXPIREAFTERDAYS 28
@interface ApplicationController ()
@property (nonatomic, strong) WindowController *windowController;
@property (nonatomic, strong) PlaybackController *playbackController;
- (void)checkFreshness;
@end
@implementation ApplicationController
@synthesize windowController = _windowController;
@synthesize playbackController = _playbackController;
+ (ApplicationController *)sharedInstance
{
return [NSApp delegate];
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Kill the application if it's over EXPIREAFTERDAYS days old.
[self checkFreshness];
WindowController *windowController = [[WindowController alloc] init];
[self setWindowController:windowController];
[self.windowController showWindow:self];
// Basic implementation of the default loop count.
// Infinity = 31 until further notice.
PlaybackController *playbackController = [[PlaybackController alloc] init];
[self setPlaybackController:playbackController];
[self.playbackController setLoopInfiniteCount:31];
[self.playbackController updateLoopCount:31];
// Set the max value of the loop counter.
[[self.windowController loopCountStepper] setMaxValue:(double)[self.playbackController loopInfiniteCount]];
}
- (void)checkFreshness
{
#if EXPIREAFTERDAYS
NSString* compileDateString = [NSString stringWithUTF8String:__DATE__];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setFormatterBehavior:NSDateFormatterBehavior10_4];
[formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
[formatter setDateFormat:@"MMM dd yyyy"];
NSDate *compileDate = [formatter dateFromString:compileDateString];
NSDate *expireDate = [compileDate dateByAddingTimeInterval:(60*60*24*EXPIREAFTERDAYS)];
if ([expireDate earlierDate:[NSDate date]] == expireDate) {
// TODO: Run an alert or whatever.
[NSApp terminate:self];
}
#endif
}
- (IBAction)openFile:(id)sender
{
void(^handler)(NSInteger);
NSOpenPanel *panel = [NSOpenPanel openPanel];
[panel setAllowedFileTypes:[NSArray arrayWithObject:@"public.audio"]];
handler = ^(NSInteger result) {
if (result == NSFileHandlingPanelOKButton) {
NSURL *filePath = [[panel URLs] objectAtIndex:0];
if (![[ApplicationController sharedInstance].playbackController openURL:filePath]) {
NSLog(@"Could not load track.");
return;
}
[[ApplicationController sharedInstance].windowController showPlayerView];
[[ApplicationController sharedInstance].playbackController openURL:filePath];
}
};
[panel beginSheetModalForWindow:[[ApplicationController sharedInstance].windowController window] completionHandler:handler];
}
- (BOOL)application:(NSApplication *)sender openFile:(NSString *)filename
{
[self.windowController showPlayerView];
return [self.playbackController openURL:[NSURL fileURLWithPath:filename]];
}
@end