code refactoring
This commit is contained in:
parent
1bea90c9c3
commit
ec576223be
8 changed files with 350 additions and 185 deletions
|
@ -19,6 +19,8 @@
|
|||
IBOutlet NSWindow *timelineViewWindow;
|
||||
IBOutlet WebView *mentionsView;
|
||||
IBOutlet NSWindow *mentionsViewWindow;
|
||||
NSWindow *loginViewWindow;
|
||||
NSProgressIndicator *loginActivityIndicator;
|
||||
IBOutlet NSMenuItem *globalHotkeyMenuItem;
|
||||
IBOutlet NSImageView *logoLayer;
|
||||
ViewDelegate *viewDelegate;
|
||||
|
@ -30,6 +32,8 @@
|
|||
@property (retain, nonatomic) IBOutlet NSWindow *timelineViewWindow;
|
||||
@property (retain, nonatomic) IBOutlet WebView *mentionsView;
|
||||
@property (retain, nonatomic) IBOutlet NSWindow *mentionsViewWindow;
|
||||
@property (assign) IBOutlet NSWindow *loginViewWindow;
|
||||
@property (assign) IBOutlet NSProgressIndicator *loginActivityIndicator;
|
||||
@property (retain, nonatomic) IBOutlet NSMenuItem *globalHotkeyMenuItem;
|
||||
@property (retain, nonatomic) IBOutlet NSImageView *logoLayer;
|
||||
@property (retain, nonatomic) IBOutlet ViewDelegate *viewDelegate;
|
||||
|
@ -51,6 +55,10 @@
|
|||
- (void)storeAccessToken:(NSString *)accessToken secret:(NSString *)secret userId:(NSString *)userId andScreenName:(NSString *)screenName;
|
||||
- (void)loggedIn;
|
||||
|
||||
- (IBAction)login:(id)sender;
|
||||
- (IBAction)logout:(id)sender;
|
||||
|
||||
|
||||
OSStatus handler(EventHandlerCallRef nextHandler, EventRef theEvent, void* userData);
|
||||
|
||||
@end
|
||||
|
|
67
Controller.m
67
Controller.m
|
@ -12,6 +12,8 @@
|
|||
|
||||
|
||||
@implementation Controller
|
||||
@synthesize loginViewWindow;
|
||||
@synthesize loginActivityIndicator;
|
||||
|
||||
@synthesize timelineView, timelineViewWindow, mentionsView, mentionsViewWindow, globalHotkeyMenuItem, viewDelegate;
|
||||
@synthesize logoLayer;
|
||||
|
@ -50,26 +52,35 @@
|
|||
|
||||
accessToken = [[AccessToken alloc] init];
|
||||
|
||||
//[accessToken setString:nil forKey:@"user_access_token"];
|
||||
|
||||
if (![accessToken stringForKey:@"user_access_token"]) {
|
||||
[self initOauth];
|
||||
[timelineViewWindow performClose:self];
|
||||
[mentionsViewWindow performClose:self];
|
||||
[self.loginViewWindow makeKeyAndOrderFront:self];
|
||||
} else {
|
||||
[timelineViewWindow makeKeyAndOrderFront:self];
|
||||
[self initWebViews];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)initOauth {
|
||||
NSString *path = [[NSBundle mainBundle] resourcePath];
|
||||
NSURL *url = [NSURL fileURLWithPath:path];
|
||||
NSString *index_string = [NSString stringWithContentsOfFile:[NSString stringWithFormat:@"%@/index_oauth.html", path] encoding:NSUTF8StringEncoding error:nil];
|
||||
|
||||
|
||||
oauthView = [[WebView alloc] init];
|
||||
viewDelegate.oauthView = oauthView;
|
||||
[[oauthView mainFrame] loadHTMLString:index_string baseURL:url];
|
||||
[oauthView setFrameLoadDelegate:viewDelegate];
|
||||
[oauthView setPolicyDelegate:viewDelegate];
|
||||
[oauthView setUIDelegate:viewDelegate];
|
||||
[[oauthView windowScriptObject] setValue:self forKey:@"controller"];
|
||||
if (!oauthView) {
|
||||
NSString *path = [[NSBundle mainBundle] resourcePath];
|
||||
NSURL *url = [NSURL fileURLWithPath:path];
|
||||
NSString *index_string = [NSString stringWithContentsOfFile:[NSString stringWithFormat:@"%@/index_oauth.html", path] encoding:NSUTF8StringEncoding error:nil];
|
||||
|
||||
|
||||
oauthView = [[WebView alloc] init];
|
||||
viewDelegate.oauthView = oauthView;
|
||||
[[oauthView mainFrame] loadHTMLString:index_string baseURL:url];
|
||||
[oauthView setFrameLoadDelegate:viewDelegate];
|
||||
[oauthView setPolicyDelegate:viewDelegate];
|
||||
[oauthView setUIDelegate:viewDelegate];
|
||||
[[oauthView windowScriptObject] setValue:self forKey:@"controller"];
|
||||
} else {
|
||||
[oauthView stringByEvaluatingJavaScriptFromString:@"tentia_oauth.authenticate()"];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)initHotKeys {
|
||||
|
@ -123,7 +134,9 @@
|
|||
}
|
||||
|
||||
- (void)authentificationSucceded:(id)sender {
|
||||
[loginActivityIndicator stopAnimation:self];
|
||||
[self initWebViews];
|
||||
[loginViewWindow performClose:self];
|
||||
}
|
||||
|
||||
- (void)initWebViews {
|
||||
|
@ -245,12 +258,36 @@
|
|||
[[NSNotificationCenter defaultCenter] postNotificationName:@"authentificationSucceded" object:nil];
|
||||
}
|
||||
|
||||
- (void)loggedIn
|
||||
{
|
||||
- (void)loggedIn {
|
||||
[timelineViewWindow makeKeyAndOrderFront:self];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:@"authentificationSucceded" object:nil];
|
||||
}
|
||||
|
||||
- (IBAction)login:(id)sender {
|
||||
[loginActivityIndicator startAnimation:self];
|
||||
[self initOauth];
|
||||
}
|
||||
|
||||
- (IBAction)logout:(id)sender {
|
||||
[timelineViewWindow performClose:self];
|
||||
[mentionsViewWindow performClose:self];
|
||||
[self.loginViewWindow makeKeyAndOrderFront:self];
|
||||
|
||||
[timelineView stringByEvaluatingJavaScriptFromString:@"tentia_instance.logout();"];
|
||||
[mentionsView stringByEvaluatingJavaScriptFromString:@"tentia_instance.logout();"];
|
||||
|
||||
[accessToken setString:nil forKey:@"app_mac_key"];
|
||||
[accessToken setString:nil forKey:@"app_mac_key_id"];
|
||||
[accessToken setString:nil forKey:@"app_id"];
|
||||
[accessToken setString:nil forKey:@"app_mac_algorithm"];
|
||||
[accessToken setString:nil forKey:@"user_access_token"];
|
||||
[accessToken setString:nil forKey:@"user_mac_key"];
|
||||
[accessToken setString:nil forKey:@"user_mac_algorithm"];
|
||||
[accessToken setString:nil forKey:@"user_token_type"];
|
||||
[accessToken setString:nil forKey:@"api_root"];
|
||||
[accessToken setString:nil forKey:@"entity"];
|
||||
}
|
||||
|
||||
// Mentions window has been visible
|
||||
- (void)windowDidBecomeKey:(NSNotification *)notification {
|
||||
if ([notification object] == mentionsViewWindow) {
|
||||
|
|
154
Core.js
154
Core.js
|
@ -57,19 +57,15 @@ Core.prototype.newStatus = function(status, supress_new_with_timeout) {
|
|||
this.is_not_init = true;
|
||||
}
|
||||
|
||||
Core.prototype.logout = function() {
|
||||
this.body.innerHTML = "";
|
||||
}
|
||||
|
||||
Core.prototype.getItem = function(status) {
|
||||
|
||||
var _this = this;
|
||||
this.since_id = status.id;
|
||||
this.since_id_entity = status.entity;
|
||||
if (this.since_time < status.published_at) this.since_time = status.published_at;
|
||||
|
||||
var original_status = null;
|
||||
/*
|
||||
if(status.retweeted_status != null) {
|
||||
var original_status = status;
|
||||
var status = status.retweeted_status;
|
||||
}*/
|
||||
|
||||
var template = this.getTemplate();
|
||||
|
||||
|
@ -85,7 +81,6 @@ Core.prototype.getItem = function(status) {
|
|||
}
|
||||
//template.retweet.onclick = function() { template.retweet.className = "hidden"; _this.retweet(status.id_str, template.item); return false; }
|
||||
|
||||
//template.image.src = status.user.profile_image_url;
|
||||
template.username.innerText = status.entity;
|
||||
template.username.href = status.entity; // FIXME open profile
|
||||
|
||||
|
@ -100,30 +95,16 @@ Core.prototype.getItem = function(status) {
|
|||
template.username.title = template.username.innerText;
|
||||
template.username.innerText = basic.name;
|
||||
}
|
||||
if(basic.avatar_url) template.image.src = basic.avatar_url;
|
||||
if(basic.avatar_url) {
|
||||
template.image.onerror = function() { template.image.src = 'default-avatar.png' };
|
||||
template.image.src = basic.avatar_url;
|
||||
}
|
||||
}
|
||||
});
|
||||
}, null, false); // do not send auth-headers
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
if(original_status != null) {
|
||||
var retweeted = document.createElement("span")
|
||||
retweeted.className = "retweeted";
|
||||
var retweeted_icon = document.createElement("span");
|
||||
retweeted_icon.innerText = " ";
|
||||
retweeted.appendChild(retweeted_icon);
|
||||
var retweeted_by = document.createElement("a");
|
||||
retweeted_by.innerText = original_status.user.screen_name + " ";
|
||||
retweeted_by.href = WEBSITE_PATH + original_status.user.screen_name;
|
||||
retweeted.appendChild(document.createTextNode("@"));
|
||||
retweeted.appendChild(retweeted_by);
|
||||
template.in_reply.parentNode.parentNode.insertBefore(retweeted, template.in_reply.parent);
|
||||
}*/
|
||||
|
||||
/*if(status.in_reply_to_status_id_str != null) template.in_reply.innerText = status.in_reply_to_screen_name;
|
||||
else */template.in_reply.parentNode.className = "hidden";
|
||||
//template.in_reply.href = WEBSITE_PATH + status.in_reply_to_screen_name + "/status/" + status.in_reply_to_status_id_str;
|
||||
template.in_reply.parentNode.className = "hidden";
|
||||
|
||||
template.message.innerHTML = replaceUsernamesWithLinks(replaceURLWithHTMLLinks(status.content.text, status.entities, template.message));
|
||||
|
||||
|
@ -133,60 +114,17 @@ Core.prototype.getItem = function(status) {
|
|||
time.className = "timeago";
|
||||
$(time).timeago();
|
||||
template.ago.appendChild(time);
|
||||
//template.ago.href = WEBSITE_PATH + status.user.screen_name + "/status/" + status.id_str;
|
||||
|
||||
// {"type":"Point","coordinates":[57.10803113,12.25854746]}
|
||||
if (status.content && status.content.location && status.content.location.type == "Point") {
|
||||
template.geo.href = "http://maps.google.com/maps?q=" + status.content.location.coordinates[0] + "," + status.content.location.coordinates[1];
|
||||
template.geo.style.display = "";
|
||||
}
|
||||
|
||||
|
||||
template.source.href = status.app.url;
|
||||
template.source.innerHTML = status.app.name;
|
||||
template.source.title = status.app.url;
|
||||
/*
|
||||
if(status.entities.media) {
|
||||
|
||||
for(var i=0; i<status.entities.media.length; i++) {
|
||||
var media = status.entities.media[i];
|
||||
|
||||
if(media.type == "photo") {
|
||||
var a = document.createElement("a");
|
||||
a.href = media.media_url;
|
||||
template.message.innerHTML = template.message.innerHTML.replace(media.url, "");
|
||||
alert(media.url)
|
||||
|
||||
var img = document.createElement("img");
|
||||
img.className = "photo";
|
||||
img.src = media.media_url + ":small";
|
||||
|
||||
a.appendChild(img);
|
||||
template.images.appendChild(a);
|
||||
|
||||
} else if(media.type == "tentia_youtube") {
|
||||
var a = document.createElement("a");
|
||||
a.href = media.url;
|
||||
|
||||
var img = document.createElement("img");
|
||||
img.className = "video";
|
||||
img.src = media.media_url;
|
||||
|
||||
a.appendChild(img);
|
||||
template.images.appendChild(a);
|
||||
} else if(media.type == "tentia_photo") {
|
||||
var a = document.createElement("a");
|
||||
a.href = media.url;
|
||||
|
||||
var img = document.createElement("img");
|
||||
img.className = "photo";
|
||||
img.src = media.media_url;
|
||||
|
||||
a.appendChild(img);
|
||||
template.images.appendChild(a);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
return template.item;
|
||||
}
|
||||
|
||||
|
@ -297,7 +235,7 @@ Core.prototype.getNewData = function(supress_new_with_timeout) {
|
|||
|
||||
var those = this;
|
||||
var url = URI(controller.stringForKey_("api_root"));
|
||||
url.path("posts");
|
||||
url.path(url.directory() + "posts");
|
||||
url.addSearch("post_types", "https://tent.io/types/post/status/v0.1.0");
|
||||
url.addSearch("limit", this.max_length);
|
||||
if(this.since_id) {
|
||||
|
@ -311,7 +249,7 @@ Core.prototype.getNewData = function(supress_new_with_timeout) {
|
|||
|
||||
var http_method = "GET";
|
||||
var callback = function(resp) {
|
||||
|
||||
|
||||
try {
|
||||
var json = JSON.parse(resp.responseText)
|
||||
} catch (e) {
|
||||
|
@ -325,18 +263,9 @@ Core.prototype.getNewData = function(supress_new_with_timeout) {
|
|||
|
||||
var data = null;
|
||||
|
||||
getURL(
|
||||
url.toString(),
|
||||
http_method,
|
||||
callback,
|
||||
data,
|
||||
makeAuthHeader(
|
||||
url.toString(),
|
||||
http_method,
|
||||
controller.stringForKey_("user_mac_key"),
|
||||
controller.stringForKey_("user_access_token")
|
||||
)
|
||||
); // FIXME: error callback
|
||||
if (controller.stringForKey_("user_access_token")) {
|
||||
getURL(url.toString(), http_method, callback, data); // FIXME: error callback
|
||||
}
|
||||
|
||||
/*
|
||||
$.ajax(
|
||||
|
@ -383,54 +312,7 @@ Core.prototype.sendNewMessage = function(content, in_reply_to_status_id, in_repl
|
|||
data["mentions"] = mentions;
|
||||
}
|
||||
|
||||
getURL(
|
||||
url.toString(),
|
||||
http_method,
|
||||
callback,
|
||||
JSON.stringify(data),
|
||||
makeAuthHeader(
|
||||
url.toString(),
|
||||
http_method,
|
||||
controller.stringForKey_("user_mac_key"),
|
||||
controller.stringForKey_("user_access_token")
|
||||
)
|
||||
); // FIXME: error callback
|
||||
|
||||
/*
|
||||
var url = API_PATH + "statuses/update.json";
|
||||
var data = "source=tentia&status=" + OAuth.percentEncode(tweet);
|
||||
if(in_reply_to_status_id != '') data += "&in_reply_to_status_id=" + in_reply_to_status_id
|
||||
|
||||
var parameters = { source: "tentia", status: tweet };
|
||||
if(in_reply_to_status_id != '') parameters.in_reply_to_status_id = in_reply_to_status_id;
|
||||
|
||||
var _this = this;
|
||||
|
||||
var message = { method:"POST" , action:url, parameters:parameters };
|
||||
|
||||
OAuth.completeRequest(message,
|
||||
{ consumerKey : OAUTH_CONSUMER_KEY
|
||||
, consumerSecret: OAUTH_CONSUMER_SECRET
|
||||
, token : controller.accessToken.accessToken()
|
||||
, tokenSecret : controller.accessToken.secret()
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
beforeSend: function(xhr) {
|
||||
xhr.setRequestHeader("Authorization", OAuth.getAuthorizationHeader("", message.parameters));
|
||||
},
|
||||
url: url,
|
||||
type: 'POST',
|
||||
data: data,
|
||||
dataType: 'json',
|
||||
success: function(data) {
|
||||
_this.getNewData(true);
|
||||
},
|
||||
error:function (xhr, ajaxOptions, thrownError) {
|
||||
alert(xhr.status);
|
||||
alert(thrownError);
|
||||
}
|
||||
});*/
|
||||
getURL(url.toString(), http_method, callback, JSON.stringify(data)); // FIXME: error callback
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -28,8 +28,10 @@
|
|||
<string>NSImageView</string>
|
||||
<string>NSMenu</string>
|
||||
<string>NSMenuItem</string>
|
||||
<string>NSProgressIndicator</string>
|
||||
<string>NSTextField</string>
|
||||
<string>NSTextFieldCell</string>
|
||||
<string>NSUserDefaultsController</string>
|
||||
<string>NSView</string>
|
||||
<string>NSWindowTemplate</string>
|
||||
<string>WebView</string>
|
||||
|
@ -93,6 +95,15 @@
|
|||
<reference key="NSOnImage" ref="1033313550"/>
|
||||
<reference key="NSMixedImage" ref="310636482"/>
|
||||
</object>
|
||||
<object class="NSMenuItem" id="670714241">
|
||||
<reference key="NSMenu" ref="110575045"/>
|
||||
<string key="NSTitle">Preferences...</string>
|
||||
<string key="NSKeyEquiv">,</string>
|
||||
<int key="NSKeyEquivModMask">1048576</int>
|
||||
<int key="NSMnemonicLoc">2147483647</int>
|
||||
<reference key="NSOnImage" ref="1033313550"/>
|
||||
<reference key="NSMixedImage" ref="310636482"/>
|
||||
</object>
|
||||
<object class="NSMenuItem" id="304266470">
|
||||
<reference key="NSMenu" ref="110575045"/>
|
||||
<bool key="NSIsDisabled">YES</bool>
|
||||
|
@ -252,6 +263,24 @@
|
|||
<reference key="NSOnImage" ref="1033313550"/>
|
||||
<reference key="NSMixedImage" ref="310636482"/>
|
||||
</object>
|
||||
<object class="NSMenuItem" id="157409543">
|
||||
<reference key="NSMenu" ref="720053764"/>
|
||||
<bool key="NSIsDisabled">YES</bool>
|
||||
<bool key="NSIsSeparator">YES</bool>
|
||||
<string key="NSTitle"/>
|
||||
<string key="NSKeyEquiv"/>
|
||||
<int key="NSMnemonicLoc">2147483647</int>
|
||||
<reference key="NSOnImage" ref="1033313550"/>
|
||||
<reference key="NSMixedImage" ref="310636482"/>
|
||||
</object>
|
||||
<object class="NSMenuItem" id="1007514384">
|
||||
<reference key="NSMenu" ref="720053764"/>
|
||||
<string key="NSTitle">Logout</string>
|
||||
<string key="NSKeyEquiv"/>
|
||||
<int key="NSMnemonicLoc">2147483647</int>
|
||||
<reference key="NSOnImage" ref="1033313550"/>
|
||||
<reference key="NSMixedImage" ref="310636482"/>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
|
@ -910,11 +939,11 @@
|
|||
<bool key="NSWindowIsRestorable">YES</bool>
|
||||
</object>
|
||||
<object class="NSWindowTemplate" id="842998572">
|
||||
<int key="NSWindowStyleMask">15</int>
|
||||
<int key="NSWindowStyleMask">7</int>
|
||||
<int key="NSWindowBacking">2</int>
|
||||
<string key="NSWindowRect">{{641, 502}, {480, 186}}</string>
|
||||
<int key="NSWTFlags">611845120</int>
|
||||
<string key="NSWindowTitle">Login</string>
|
||||
<int key="NSWTFlags">1685586944</int>
|
||||
<string key="NSWindowTitle">Preferences</string>
|
||||
<string key="NSWindowClass">NSWindow</string>
|
||||
<nil key="NSViewClass"/>
|
||||
<nil key="NSUserInterfaceItemIdentifier"/>
|
||||
|
@ -964,7 +993,7 @@
|
|||
<string key="NSFrame">{{194, 82}, {266, 22}}</string>
|
||||
<reference key="NSSuperview" ref="503676418"/>
|
||||
<reference key="NSWindow"/>
|
||||
<reference key="NSNextKeyView" ref="251531186"/>
|
||||
<reference key="NSNextKeyView" ref="1063247419"/>
|
||||
<string key="NSReuseIdentifierKey">_NS:9</string>
|
||||
<bool key="NSEnabled">YES</bool>
|
||||
<object class="NSTextFieldCell" key="NSCell" id="2007231">
|
||||
|
@ -976,7 +1005,7 @@
|
|||
<double key="NSSize">13</double>
|
||||
<int key="NSfFlags">1044</int>
|
||||
</object>
|
||||
<string key="NSPlaceholderString">https://someone.tent.is</string>
|
||||
<string key="NSPlaceholderString">https://example.tent.is</string>
|
||||
<string key="NSCellIdentifier">_NS:9</string>
|
||||
<reference key="NSControlView" ref="643973685"/>
|
||||
<bool key="NSDrawsBackground">YES</bool>
|
||||
|
@ -1060,6 +1089,17 @@
|
|||
</object>
|
||||
<bool key="NSAllowsLogicalLayoutDirection">NO</bool>
|
||||
</object>
|
||||
<object class="NSProgressIndicator" id="1063247419">
|
||||
<reference key="NSNextResponder" ref="503676418"/>
|
||||
<int key="NSvFlags">268</int>
|
||||
<string key="NSFrame">{{373, 55}, {16, 16}}</string>
|
||||
<reference key="NSSuperview" ref="503676418"/>
|
||||
<reference key="NSWindow"/>
|
||||
<reference key="NSNextKeyView" ref="251531186"/>
|
||||
<string key="NSReuseIdentifierKey">_NS:945</string>
|
||||
<int key="NSpiFlags">28938</int>
|
||||
<double key="NSMaxValue">100</double>
|
||||
</object>
|
||||
</object>
|
||||
<string key="NSFrameSize">{480, 186}</string>
|
||||
<reference key="NSSuperview"/>
|
||||
|
@ -1069,8 +1109,12 @@
|
|||
</object>
|
||||
<string key="NSScreenRect">{{0, 0}, {2560, 1418}}</string>
|
||||
<string key="NSMaxSize">{10000000000000, 10000000000000}</string>
|
||||
<string key="NSFrameAutosaveName">preferences</string>
|
||||
<bool key="NSWindowIsRestorable">YES</bool>
|
||||
</object>
|
||||
<object class="NSUserDefaultsController" id="863857937">
|
||||
<bool key="NSSharedInstance">YES</bool>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBObjectContainer" key="IBDocument.Objects">
|
||||
<object class="NSMutableArray" key="connectionRecords">
|
||||
|
@ -1467,6 +1511,54 @@
|
|||
</object>
|
||||
<int key="connectionID">570</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBOutletConnection" key="connection">
|
||||
<string key="label">loginEntityTextField</string>
|
||||
<reference key="source" ref="408500656"/>
|
||||
<reference key="destination" ref="643973685"/>
|
||||
</object>
|
||||
<int key="connectionID">605</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBActionConnection" key="connection">
|
||||
<string key="label">login:</string>
|
||||
<reference key="source" ref="408500656"/>
|
||||
<reference key="destination" ref="251531186"/>
|
||||
</object>
|
||||
<int key="connectionID">606</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBActionConnection" key="connection">
|
||||
<string key="label">login:</string>
|
||||
<reference key="source" ref="408500656"/>
|
||||
<reference key="destination" ref="643973685"/>
|
||||
</object>
|
||||
<int key="connectionID">609</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBActionConnection" key="connection">
|
||||
<string key="label">logout:</string>
|
||||
<reference key="source" ref="408500656"/>
|
||||
<reference key="destination" ref="1007514384"/>
|
||||
</object>
|
||||
<int key="connectionID">612</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBOutletConnection" key="connection">
|
||||
<string key="label">loginViewWindow</string>
|
||||
<reference key="source" ref="408500656"/>
|
||||
<reference key="destination" ref="842998572"/>
|
||||
</object>
|
||||
<int key="connectionID">616</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBOutletConnection" key="connection">
|
||||
<string key="label">loginActivityIndicator</string>
|
||||
<reference key="source" ref="408500656"/>
|
||||
<reference key="destination" ref="1063247419"/>
|
||||
</object>
|
||||
<int key="connectionID">622</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBActionConnection" key="connection">
|
||||
<string key="label">makeKeyAndOrderFront:</string>
|
||||
|
@ -1499,6 +1591,30 @@
|
|||
</object>
|
||||
<int key="connectionID">569</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBActionConnection" key="connection">
|
||||
<string key="label">makeKeyAndOrderFront:</string>
|
||||
<reference key="source" ref="842998572"/>
|
||||
<reference key="destination" ref="670714241"/>
|
||||
</object>
|
||||
<int key="connectionID">611</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBBindingConnection" key="connection">
|
||||
<string key="label">value: values.entity</string>
|
||||
<reference key="source" ref="643973685"/>
|
||||
<reference key="destination" ref="863857937"/>
|
||||
<object class="NSNibBindingConnector" key="connector">
|
||||
<reference key="NSSource" ref="643973685"/>
|
||||
<reference key="NSDestination" ref="863857937"/>
|
||||
<string key="NSLabel">value: values.entity</string>
|
||||
<string key="NSBinding">value</string>
|
||||
<string key="NSKeyPath">values.entity</string>
|
||||
<int key="NSNibBindingConnectorVersion">2</int>
|
||||
</object>
|
||||
</object>
|
||||
<int key="connectionID">619</int>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBMutableOrderedSet" key="objectRecords">
|
||||
<object class="NSArray" key="orderedObjects">
|
||||
|
@ -1588,6 +1704,8 @@
|
|||
<reference ref="425164168"/>
|
||||
<reference ref="281587867"/>
|
||||
<reference ref="295904906"/>
|
||||
<reference ref="157409543"/>
|
||||
<reference ref="1007514384"/>
|
||||
</object>
|
||||
<reference key="parent" ref="379814623"/>
|
||||
</object>
|
||||
|
@ -1779,6 +1897,7 @@
|
|||
<reference ref="1056857174"/>
|
||||
<reference ref="342932134"/>
|
||||
<reference ref="1073310099"/>
|
||||
<reference ref="670714241"/>
|
||||
</object>
|
||||
<reference key="parent" ref="694149608"/>
|
||||
</object>
|
||||
|
@ -2160,6 +2279,7 @@
|
|||
<reference ref="643973685"/>
|
||||
<reference ref="215157023"/>
|
||||
<reference ref="251531186"/>
|
||||
<reference ref="1063247419"/>
|
||||
</object>
|
||||
<reference key="parent" ref="842998572"/>
|
||||
</object>
|
||||
|
@ -2219,6 +2339,31 @@
|
|||
<reference key="object" ref="54847478"/>
|
||||
<reference key="parent" ref="251531186"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">602</int>
|
||||
<reference key="object" ref="157409543"/>
|
||||
<reference key="parent" ref="720053764"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">603</int>
|
||||
<reference key="object" ref="1007514384"/>
|
||||
<reference key="parent" ref="720053764"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">610</int>
|
||||
<reference key="object" ref="670714241"/>
|
||||
<reference key="parent" ref="110575045"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">613</int>
|
||||
<reference key="object" ref="863857937"/>
|
||||
<reference key="parent" ref="0"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">620</int>
|
||||
<reference key="object" ref="1063247419"/>
|
||||
<reference key="parent" ref="503676418"/>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
<object class="NSMutableDictionary" key="flattenedProperties">
|
||||
|
@ -2325,6 +2470,11 @@
|
|||
<string>599.IBPluginDependency</string>
|
||||
<string>600.IBPluginDependency</string>
|
||||
<string>601.IBPluginDependency</string>
|
||||
<string>602.IBPluginDependency</string>
|
||||
<string>603.IBPluginDependency</string>
|
||||
<string>610.IBPluginDependency</string>
|
||||
<string>613.IBPluginDependency</string>
|
||||
<string>620.IBPluginDependency</string>
|
||||
<string>72.IBPluginDependency</string>
|
||||
<string>73.IBPluginDependency</string>
|
||||
<string>79.IBPluginDependency</string>
|
||||
|
@ -2409,7 +2559,7 @@
|
|||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>{{202, 175}, {397, 581}}</string>
|
||||
<boolean value="YES"/>
|
||||
<boolean value="NO"/>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.WebKitIBPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
|
@ -2425,7 +2575,12 @@
|
|||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<boolean value="YES"/>
|
||||
<boolean value="NO"/>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
|
@ -2456,7 +2611,7 @@
|
|||
<reference key="dict.values" ref="0"/>
|
||||
</object>
|
||||
<nil key="sourceID"/>
|
||||
<int key="maxID">601</int>
|
||||
<int key="maxID">622</int>
|
||||
</object>
|
||||
<object class="IBClassDescriber" key="IBDocument.Classes">
|
||||
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
|
||||
|
@ -2464,11 +2619,59 @@
|
|||
<object class="IBPartialClassDescription">
|
||||
<string key="className">Controller</string>
|
||||
<string key="superclassName">NSObject</string>
|
||||
<object class="NSMutableDictionary" key="actions">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="NSArray" key="dict.sortedKeys">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>login:</string>
|
||||
<string>logout:</string>
|
||||
<string>openNewMessageWindow:</string>
|
||||
<string>sendTweet:</string>
|
||||
</object>
|
||||
<object class="NSArray" key="dict.values">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>id</string>
|
||||
<string>id</string>
|
||||
<string>id</string>
|
||||
<string>id</string>
|
||||
</object>
|
||||
</object>
|
||||
<object class="NSMutableDictionary" key="actionInfosByName">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="NSArray" key="dict.sortedKeys">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>login:</string>
|
||||
<string>logout:</string>
|
||||
<string>openNewMessageWindow:</string>
|
||||
<string>sendTweet:</string>
|
||||
</object>
|
||||
<object class="NSArray" key="dict.values">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="IBActionInfo">
|
||||
<string key="name">login:</string>
|
||||
<string key="candidateClassName">id</string>
|
||||
</object>
|
||||
<object class="IBActionInfo">
|
||||
<string key="name">logout:</string>
|
||||
<string key="candidateClassName">id</string>
|
||||
</object>
|
||||
<object class="IBActionInfo">
|
||||
<string key="name">openNewMessageWindow:</string>
|
||||
<string key="candidateClassName">id</string>
|
||||
</object>
|
||||
<object class="IBActionInfo">
|
||||
<string key="name">sendTweet:</string>
|
||||
<string key="candidateClassName">id</string>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
<object class="NSMutableDictionary" key="outlets">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="NSArray" key="dict.sortedKeys">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>globalHotkeyMenuItem</string>
|
||||
<string>loginActivityIndicator</string>
|
||||
<string>loginViewWindow</string>
|
||||
<string>logoLayer</string>
|
||||
<string>mentionsView</string>
|
||||
<string>mentionsViewWindow</string>
|
||||
|
@ -2479,6 +2682,8 @@
|
|||
<object class="NSArray" key="dict.values">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>NSMenuItem</string>
|
||||
<string>NSProgressIndicator</string>
|
||||
<string>NSWindow</string>
|
||||
<string>NSImageView</string>
|
||||
<string>WebView</string>
|
||||
<string>NSWindow</string>
|
||||
|
@ -2492,6 +2697,8 @@
|
|||
<object class="NSArray" key="dict.sortedKeys">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>globalHotkeyMenuItem</string>
|
||||
<string>loginActivityIndicator</string>
|
||||
<string>loginViewWindow</string>
|
||||
<string>logoLayer</string>
|
||||
<string>mentionsView</string>
|
||||
<string>mentionsViewWindow</string>
|
||||
|
@ -2505,6 +2712,14 @@
|
|||
<string key="name">globalHotkeyMenuItem</string>
|
||||
<string key="candidateClassName">NSMenuItem</string>
|
||||
</object>
|
||||
<object class="IBToOneOutletInfo">
|
||||
<string key="name">loginActivityIndicator</string>
|
||||
<string key="candidateClassName">NSProgressIndicator</string>
|
||||
</object>
|
||||
<object class="IBToOneOutletInfo">
|
||||
<string key="name">loginViewWindow</string>
|
||||
<string key="candidateClassName">NSWindow</string>
|
||||
</object>
|
||||
<object class="IBToOneOutletInfo">
|
||||
<string key="name">logoLayer</string>
|
||||
<string key="candidateClassName">NSImageView</string>
|
||||
|
|
|
@ -34,11 +34,11 @@
|
|||
// If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this method and override -makeWindowControllers instead.
|
||||
return @"NewMessageWindow";
|
||||
}
|
||||
/*
|
||||
|
||||
- (NSString *)displayName {
|
||||
return @"New Tweet";
|
||||
return @"New Post";
|
||||
}
|
||||
*/
|
||||
|
||||
- (void)windowControllerDidLoadNib:(NSWindowController *) aController
|
||||
{
|
||||
[super windowControllerDidLoadNib:aController];
|
||||
|
|
|
@ -19,9 +19,7 @@ function getUrlVars(url) {
|
|||
return vars;
|
||||
}
|
||||
|
||||
function OauthImplementation(entity) {
|
||||
this.entity = entity || "http://jeena.net";
|
||||
controller.setString_forKey_(this.entity, "entity");
|
||||
function OauthImplementation() {
|
||||
this.app_info = {
|
||||
"id": null,
|
||||
"name": "Tentia",
|
||||
|
@ -39,6 +37,12 @@ function OauthImplementation(entity) {
|
|||
this.register_data = null;
|
||||
this.profile = null;
|
||||
this.state = null;
|
||||
|
||||
this.authenticate();
|
||||
}
|
||||
|
||||
OauthImplementation.prototype.authenticate = function() {
|
||||
this.entity = controller.stringForKey_("entity");
|
||||
this.requestProfileURL(this.entity);
|
||||
}
|
||||
|
||||
|
@ -102,12 +106,19 @@ OauthImplementation.prototype.requestAccessToken = function(responseBody) {
|
|||
});
|
||||
|
||||
var those = this;
|
||||
var http_method = "POST";
|
||||
var callback = function(resp) {
|
||||
those.requestAccessTokenTicketFinished(resp.responseText);
|
||||
};
|
||||
|
||||
var auth_header = makeAuthHeader(url, "POST", controller.stringForKey_("app_mac_key"), controller.stringForKey_("app_mac_key_id"));
|
||||
getURL(url, "POST", callback, requestBody, auth_header);
|
||||
var auth_header = makeAuthHeader(
|
||||
url,
|
||||
http_method,
|
||||
controller.stringForKey_("app_mac_key"),
|
||||
controller.stringForKey_("app_mac_key_id")
|
||||
);
|
||||
|
||||
getURL(url, http_method, callback, requestBody, auth_header);
|
||||
|
||||
} else {
|
||||
alert("State is not the same: {" + this.state + "} vs {" + urlVars["state"] + "}")
|
||||
|
@ -116,10 +127,6 @@ OauthImplementation.prototype.requestAccessToken = function(responseBody) {
|
|||
this.state = null; // reset the state
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
OauthImplementation.prototype.requestAccessTokenTicketFinished = function(responseBody) {
|
||||
|
||||
var access = JSON.parse(responseBody);
|
||||
|
|
|
@ -6,7 +6,7 @@ html, body {
|
|||
body {
|
||||
font-family: "Lucida Grande", Tahoma, sans-serif;
|
||||
font-size: 11px;
|
||||
background: #dedede;
|
||||
background: #dedede url(Icon.png) bottom center no-repeat;
|
||||
}
|
||||
|
||||
a {
|
||||
|
|
|
@ -6,7 +6,21 @@ function getURL(url, http_method, callback, data, auth_header) {
|
|||
$.ajax({
|
||||
beforeSend: function(xhr) {
|
||||
if (data) xhr.setRequestHeader("Content-Length", data.length);
|
||||
if (auth_header) xhr.setRequestHeader("Authorization", auth_header);
|
||||
|
||||
if (auth_header) { // if is_set? auth_header
|
||||
xhr.setRequestHeader("Authorization", auth_header);
|
||||
} else {
|
||||
var user_access_token = controller.stringForKey_("user_access_token");
|
||||
if (auth_header !== false && user_access_token) {
|
||||
auth_header = makeAuthHeader(
|
||||
url,
|
||||
http_method,
|
||||
controller.stringForKey_("user_mac_key"),
|
||||
user_access_token
|
||||
)
|
||||
xhr.setRequestHeader("Authorization", auth_header);
|
||||
}
|
||||
}
|
||||
},
|
||||
url: url,
|
||||
accepts: "application/vnd.tent.v0+json",
|
||||
|
@ -16,10 +30,7 @@ function getURL(url, http_method, callback, data, auth_header) {
|
|||
data: data,
|
||||
processData: false,
|
||||
error: function(xhr, ajaxOptions, thrownError) {
|
||||
alert("getURL ERROR (" + url + ") (" + http_method + "):");
|
||||
alert(xhr.statusText);
|
||||
alert(ajaxOptions);
|
||||
alert(thrownError);
|
||||
alert("getURL " + xhr.statusText + " " + http_method + " (" + url + "): '" + xhr.responseText + "'");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -30,13 +41,18 @@ function makeAuthHeader(url, http_method, mac_key, mac_key_id) {
|
|||
var nonce = makeid(8);
|
||||
var time_stamp = parseInt((new Date).getTime() / 1000, 10);
|
||||
|
||||
var port = url.port();
|
||||
if (!port) {
|
||||
port = url.protocol() == "https" ? "443" : "80";
|
||||
}
|
||||
|
||||
var normalizedRequestString = ""
|
||||
+ time_stamp + '\n'
|
||||
+ nonce + '\n'
|
||||
+ http_method + '\n'
|
||||
+ url.path() + url.search() + url.hash() + '\n'
|
||||
+ url.hostname() + '\n'
|
||||
+ url.port() + '\n'
|
||||
+ port + '\n'
|
||||
+ '\n' ;
|
||||
|
||||
var hmac = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, mac_key);
|
||||
|
@ -69,21 +85,21 @@ function findProfileURL(entity, callback) {
|
|||
var headers = resp.getAllResponseHeaders();
|
||||
var regex = /Link: <([^>]*)>; rel="https:\/\/tent.io\/rels\/profile"/; // FIXME: parse it!
|
||||
var ret = headers.match(regex);
|
||||
var profile_url = entity + "/profile";
|
||||
if(ret.length > 1) {
|
||||
var profile_url = null;
|
||||
if(ret && ret.length > 1) {
|
||||
var profile_url = ret[1];
|
||||
if (profile_url == "/profile") {
|
||||
profile_url = entity + "/profile";
|
||||
}
|
||||
}
|
||||
callback(profile_url);
|
||||
|
||||
if (profile_url) {
|
||||
callback(profile_url);
|
||||
}
|
||||
}
|
||||
},
|
||||
error: function(xhr, ajaxOptions, thrownError) {
|
||||
alert("getURL ERROR (" + url + ") (" + http_method + "):");
|
||||
alert(xhr.statusText);
|
||||
alert(ajaxOptions);
|
||||
alert(thrownError);
|
||||
alert("findProfileURL " + xhr.statusText + " (" + entity + "): " + xhr.responseText);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Reference in a new issue