Ind.ie is now Small Technology Foundation.
Commit 75c615c7 authored by Aral Balkan's avatar Aral Balkan

Now handling the indie:// URL scheme and responding to friend requests...

Now handling the indie:// URL scheme and responding to friend requests activated from the web. Closes #156.
parent 7f79e789
......@@ -16,6 +16,7 @@
A70634B81A63112600A75BC0 /* SetupStepViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A70634B71A63112600A75BC0 /* SetupStepViewController.swift */; };
A70634BB1A63114200A75BC0 /* SetupStepOneViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A70634B91A63114200A75BC0 /* SetupStepOneViewController.swift */; };
A70634BC1A63114200A75BC0 /* SetupStepTwoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A70634BA1A63114200A75BC0 /* SetupStepTwoViewController.swift */; };
A70BDFAA1B7F6199000F47CC /* IndieURLSchemeHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = A70BDFA91B7F6199000F47CC /* IndieURLSchemeHandler.swift */; };
A70DA5E61B24DCAB00C9CB35 /* NativeNotification.swift in Sources */ = {isa = PBXBuildFile; fileRef = A70DA5E51B24DCAB00C9CB35 /* NativeNotification.swift */; };
A7296C031AA337EF00D64CDA /* Vertical tab bar component.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7296C021AA337EF00D64CDA /* Vertical tab bar component.swift */; };
A7296C101AA337F900D64CDA /* Active-Section-Indicator-Template.png in Resources */ = {isa = PBXBuildFile; fileRef = A7296C041AA337F900D64CDA /* Active-Section-Indicator-Template.png */; };
......@@ -165,6 +166,7 @@
A70634B71A63112600A75BC0 /* SetupStepViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SetupStepViewController.swift; sourceTree = "<group>"; };
A70634B91A63114200A75BC0 /* SetupStepOneViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SetupStepOneViewController.swift; sourceTree = "<group>"; };
A70634BA1A63114200A75BC0 /* SetupStepTwoViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SetupStepTwoViewController.swift; sourceTree = "<group>"; };
A70BDFA91B7F6199000F47CC /* IndieURLSchemeHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IndieURLSchemeHandler.swift; sourceTree = "<group>"; };
A70DA5E51B24DCAB00C9CB35 /* NativeNotification.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NativeNotification.swift; sourceTree = "<group>"; };
A7296C021AA337EF00D64CDA /* Vertical tab bar component.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = "Vertical tab bar component.swift"; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
A7296C041AA337F900D64CDA /* Active-Section-Indicator-Template.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Active-Section-Indicator-Template.png"; sourceTree = "<group>"; };
......@@ -377,6 +379,7 @@
A7296BFF1AA337C200D64CDA /* Components */ = {
isa = PBXGroup;
children = (
A70BDFA91B7F6199000F47CC /* IndieURLSchemeHandler.swift */,
A75AABC91A5ECFB000B105BA /* AppDelegate.swift */,
A74CC6601A668A7B0083B288 /* Helpers.swift */,
A74C9EEB1A66889D0083B288 /* Node.swift */,
......@@ -1011,6 +1014,7 @@
A7A14C791A83FBBF00586EAD /* NSString+Matcher.m in Sources */,
A7C597B71AEDEDAB008CF983 /* TimelineModel.swift in Sources */,
A7E7D7B61A616B0B003501C1 /* MainInterfaceSplitViewController.swift in Sources */,
A70BDFAA1B7F6199000F47CC /* IndieURLSchemeHandler.swift in Sources */,
A74234171A86477C00493C05 /* MainWindowController.swift in Sources */,
A7E7D7B41A616B0B003501C1 /* IndieWindow.swift in Sources */,
A70634B61A6310E900A75BC0 /* SetupViewController.swift in Sources */,
......
......@@ -68,6 +68,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, NodeDelegate
// MARK: - Application lifecycle
//
func applicationWillFinishLaunching(notification: NSNotification) {
println("✅ Application will finish launching… going to register indie:// URL scheme.")
NSAppleEventManager.sharedAppleEventManager().setEventHandler(self, andSelector: "handleGetURLEvent:replyEvent:", forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL))
}
func applicationDidFinishLaunching(aNotification: NSNotification)
{
......@@ -155,6 +161,24 @@ class AppDelegate: NSObject, NSApplicationDelegate, NodeDelegate
self.node.stop()
}
//
// MARK: indie:// scheme handler
//
func handleGetURLEvent(event: NSAppleEventDescriptor?, replyEvent: NSAppleEventDescriptor?)
{
if let event = event, paramDescriptor = event.paramDescriptorForKeyword(AEKeyword(keyDirectObject)), urlString = paramDescriptor.stringValue, url = NSURL(string: urlString)
{
println("Indie URL scheme is handling \(urlString)")
IndieURLSchemeHandler.sharedInstance.respondToURLRequest(url)
}
else
{
println("Warning: could not unwrap optionals in handleGetURLEvent(). Event: \(event).")
}
}
//
// MARK: NodeSocketDelegate methods
//
......
//
// IndieURLSchemeHandler.swift
// Heartbeat
//
// Created by Aral Balkan on 15/08/2015.
// Copyright (c) 2015 Ind.ie. All rights reserved.
//
import Cocoa
class IndieURLSchemeHandler:NSObject
{
//
// MARK: - Singleton access: sharedInstance
//
class var sharedInstance:IndieURLSchemeHandler
{
struct Static
{
static let instance:IndieURLSchemeHandler = IndieURLSchemeHandler()
}
return Static.instance
}
func respondToURLRequest(url: NSURL)
{
if let theProtocol = url.scheme, theCommand = url.host
{
let theArguments = url.pathComponents
// Sanity check
if theProtocol != "indie"
{
fatalError("Indie URL Scheme Handler called with non-indie:// protocol: \(theProtocol)")
}
switch theCommand
{
case "friend":
if let personToFriend = theArguments?[1] as? String
{
println("Received command to friend \(personToFriend)…")
// TODO: this so that the Send Friendship link is not displayed for the person themselves and then remove this.
if personToFriend == SetupData.accountHandle
{
let confirmationSheet = NSAlert()
confirmationSheet.messageText = "You cannot friend yourself."
confirmationSheet.informativeText = "Love yourself. Be your own best friend. But don’t friend youself on Heartbeat… that’s just weird. 😜"
confirmationSheet.alertStyle = NSAlertStyle.WarningAlertStyle
confirmationSheet.addButtonWithTitle("OK")
confirmationSheet.beginSheetModalForWindow(NSApplication.sharedApplication().mainWindow!) { response in }
break
}
let confirmationSheet = NSAlert()
confirmationSheet.messageText = "Send a friend request to \(personToFriend)?"
// confirmationSheet.informativeText = ""
confirmationSheet.alertStyle = NSAlertStyle.InformationalAlertStyle
confirmationSheet.addButtonWithTitle("Yes")
confirmationSheet.addButtonWithTitle("No")
confirmationSheet.beginSheetModalForWindow(NSApplication.sharedApplication().mainWindow!)
{
/* and handle */ response in
if response == 1000
{
println("ℹ️ Sending friend request to \(personToFriend).\n")
TeleportationAPI.sharedInstance.friendshipRequest(personToFriend, optionalMessage: "⚠️ Unimplemented")
}
else
{
println("ℹ️ Cancelled: Not sending friend request to \(personToFriend).\n")
}
}
}
else
{
println("⚠️ Malformed friend request received with argument: \(theArguments?[1]).")
}
default:
println("⚠️ Unknown command received: \(theCommand)")
}
}
}
}
\ No newline at end of file
......@@ -34,5 +34,16 @@
<string>alert</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>Indie</string>
<key>CFBundleURLSchemes</key>
<array>
<string>indie</string>
</array>
</dict>
</array>
</dict>
</plist>
......@@ -675,54 +675,10 @@ class TimelineViewController: NSViewController, WKNavigationDelegate
}
else if theProtocol == "indie"
{
switch theCommand
{
case "friend":
if let personToFriend = theArguments?[1] as? String
{
println("Received command to friend \(personToFriend)…")
// TODO: this so that the Send Friendship link is not displayed for the person themselves and then remove this.
if personToFriend == SetupData.accountHandle
{
let confirmationSheet = NSAlert()
confirmationSheet.messageText = "You cannot friend yourself."
confirmationSheet.informativeText = "Sorry, it’s not ideal — we won’t even give you the option to try in a future build."
confirmationSheet.alertStyle = NSAlertStyle.WarningAlertStyle
confirmationSheet.addButtonWithTitle("OK")
confirmationSheet.beginSheetModalForWindow(self.view.window!) { response in }
break
}
let confirmationSheet = NSAlert()
confirmationSheet.messageText = "Send a friend request to \(personToFriend)?"
// confirmationSheet.informativeText = ""
confirmationSheet.alertStyle = NSAlertStyle.InformationalAlertStyle
confirmationSheet.addButtonWithTitle("Yes")
confirmationSheet.addButtonWithTitle("No")
confirmationSheet.beginSheetModalForWindow(self.view.window!)
{
/* and handle */ response in
if response == 1000
{
println("ℹ️ Sending friend request to \(personToFriend).\n")
TeleportationAPI.sharedInstance.friendshipRequest(personToFriend, optionalMessage: "⚠️ Unimplemented")
}
else
{
println("ℹ️ Cancelled: Not sending friend request to \(personToFriend).\n")
}
}
}
else
{
println("⚠️ Malformed friend request received with argument: \(theArguments?[1]).")
}
default:
println("⚠️ Unknown command received: \(theCommand)")
}
//
// Indie URL scheme. Let the handler handle it :)
//
IndieURLSchemeHandler.sharedInstance.respondToURLRequest(url)
decisionHandler(WKNavigationActionPolicy.Cancel)
}
......
true
\ No newline at end of file
false
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment