-
Notifications
You must be signed in to change notification settings - Fork 14
/
douban_fmAppDelegate.m
130 lines (86 loc) · 2.65 KB
/
douban_fmAppDelegate.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//
// douban_fmAppDelegate.m
// douban.fm
//
// Created by xhan on 10-7-6.
// Copyright 2010 Baidu.com. All rights reserved.
//
#import "douban_fmAppDelegate.h"
@implementation douban_fmAppDelegate
@synthesize notifyFieldCell;
@synthesize activityIndicator;
@synthesize splashView;
@synthesize webView;
@synthesize window;
#pragma mark -
#pragma mark life cycle
- (id)init{
if (self = [super init]) {
// [[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObject:@"zh_CN"] forKey:@"AppleLanguages"];
}
return self;
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[webView setFrameLoadDelegate:self];
[webView setShouldUpdateWhileOffscreen:NO];
[webView setMainFrameURL:@"http://douban.fm/radio"];
[activityIndicator startAnimation:nil];
self.window.delegate = self;
}
- (void)dealloc {
[notifyFieldCell release], notifyFieldCell = nil;
[activityIndicator release], activityIndicator = nil;
[splashView release], splashView = nil;
[webView release], webView = nil;
[super dealloc];
}
#pragma mark -
#pragma mark Delegates
- (void)webView:(WebView *)sender didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame
{
[window setTitle:title];
return;
// some great posts about communicate between cocoa and javascript(html)
// http://zonble.net/archives/2010_09/1369.php
// http://zonble.net/archives/2010_09/1385.php
// http://zonble.net/archives/2010_09/1403.php
WebScriptObject* logs = [[webView windowScriptObject] valueForKeyPath:@"logs"];
NSUInteger count = [[logs valueForKey:@"length"] integerValue];
// NSMutableArray *a = [NSMutableArray array];
for (NSUInteger i = 0; i < count; i++) {
NSString *item = [logs webScriptValueAtIndex:i];
NSLog(@"item:%@", item);
}
}
- (void)webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame
{
// NSLog(@"start loading");
}
- (void)webView:(WebView *)sender didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame
{
// NSLog(@"opps, load failed");
[notifyFieldCell setStringValue:@"Douban is sleeping, call me later!"];
}
- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
{
//NSLog(@"finished loading");
[self performSelector:@selector(removeSplashView) withObject:nil afterDelay:1];
}
- (void)removeSplashView
{
[activityIndicator stopAnimation:nil];
[splashView removeFromSuperview];
}
- (void)windowWillMiniaturize:(NSNotification *)notification
{
}
- (void)windowDidDeminiaturize:(NSNotification *)notification
{
//refrest webView
[self.webView setHidden:YES];
[self.webView setHidden:NO];
}
- (void)windowDidMiniaturize:(NSNotification *)notification
{
}
@end