Commit aac68008 authored by Aral Balkan's avatar Aral Balkan
Browse files

Implemented download links in messages.

parent 86442372
......@@ -129,6 +129,10 @@ class MessageSplitViewController: NSSplitViewController
// Remove redundant empty lines.
indexHTML = indexHTML.stringByReplacingOccurrencesOfString("<p><br></p>", withString: "")
// Change objects to links
indexHTML = indexHTML.stringByReplacingOccurrencesOfString("<object data=\"", withString: "<a href=\"download://\(SetupData.accountHandle!)")
indexHTML = indexHTML.stringByReplacingOccurrencesOfString("</object>", withString: "</a>")
//
// If this is a new person notification, add the correct class wrapper for styling.
//
......
import Cocoa
var a:String = "Hello"
//let urlString = "download://aral/all-friends/from/aral/000000027-2015-06-02T19_03_59.365Z/Photo%20on%2031-05-2015%20at%2013.49%20%234.jpg.zip"
var b = a
b = "Goodbye"
let urlString = "download://aral/all-friends/to/000000027-2015-06-02T19_03_59.365Z/Photo%20on%2031-05-2015%20at%2013.49%20%234.jpg.zip"
let url = NSURL(string: urlString)
if let url = url, theProtocol = url.scheme, theCommand = url.host
{
println("here")
let theArguments = url.pathComponents
if theProtocol == "download"
{
println("ℹ️ Download requested for \(theCommand) with arguments: \(theArguments)")
if let theArguments = theArguments, downloadTimeline = theArguments[1] as? String, linkType = theArguments[2] as? String
{
var downloadFolderIndex = 3
var downloadFileNameIndex = 4
if linkType == "from"
{
downloadFolderIndex == 4
downloadFileNameIndex == 5
}
if let downloadFolder = theArguments[downloadFolderIndex] as? String, downloadFileName = theArguments[downloadFileNameIndex] as? String
{
//
// Currently only supporting All Friends.
//
if downloadTimeline != "all-friends"
{
println("Not all friends!")
}
if theCommand == "xxx"
{
// It’s us:
println("It’s us!")
let rootPath = NSHomeDirectory().stringByAppendingPathComponent("/Pulse/Sync/3. All your friends/to/")
let filePath = (rootPath as NSString).stringByAppendingPathComponent("\(downloadFolder)/\(downloadFileName)")
//NSWorkspace.sharedWorkspace().selectFile(filePath, inFileViewerRootedAtPath: rootPath)
println("filePath: \(filePath)")
}
else
{
// It’s a different person
println("It’s a different person!")
let rootPath = NSHomeDirectory().stringByAppendingPathComponent("/Pulse/Sync/3. All your friends/from/")
let filePath = (rootPath as NSString).stringByAppendingPathComponent("\(theCommand)/\(downloadFolder)/\(downloadFileName)")
//NSWorkspace.sharedWorkspace().selectFile(filePath, inFileViewerRootedAtPath: rootPath)
println("filePath: \(filePath)")
}
}
}
}
}
b
a
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='osx'/>
\ No newline at end of file
<playground version='5.0' target-platform='osx'>
<timeline fileName='timeline.xctimeline'/>
</playground>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<Timeline
version = "3.0">
<TimelineItems>
</TimelineItems>
</Timeline>
......@@ -526,6 +526,9 @@ class TimelineViewController: NSViewController, WKNavigationDelegate
// MARK: - WKWebViewNavigationDelegate methods
//
//
// MARK: Handle links from web content.
//
func webView(webView: WKWebView, decidePolicyForNavigationAction navigationAction: WKNavigationAction, decisionHandler: (WKNavigationActionPolicy) -> Void)
{
let url = navigationAction.request.URL
......@@ -576,6 +579,56 @@ class TimelineViewController: NSViewController, WKNavigationDelegate
decisionHandler(WKNavigationActionPolicy.Cancel)
}
else if theProtocol == "download"
{
println("ℹ️ Download requested for \(theCommand) with arguments: \(theArguments)")
if let theArguments = theArguments, downloadTimeline = theArguments[1] as? String, linkType = theArguments[2] as? String
{
var downloadFolderIndex = 3
var downloadFileNameIndex = 4
if linkType == "from"
{
downloadFolderIndex == 4
downloadFileNameIndex == 5
}
if let downloadFolder = theArguments[downloadFolderIndex] as? String, downloadFileName = theArguments[downloadFileNameIndex] as? String
{
//
// Currently only supporting All Friends.
//
if downloadTimeline != "all-friends"
{
decisionHandler(WKNavigationActionPolicy.Cancel)
return
}
if theCommand == SetupData.accountHandle
{
// It’s us:
println("It’s us!")
let rootPath = NSHomeDirectory().stringByAppendingPathComponent("/Pulse/Sync/3. All your friends/to/")
let filePath = (rootPath as NSString).stringByAppendingPathComponent("\(downloadFolder)/\(downloadFileName)")
NSWorkspace.sharedWorkspace().selectFile(filePath, inFileViewerRootedAtPath: rootPath)
}
else
{
// It’s a different person
println("It’s a different person!")
let rootPath = NSHomeDirectory().stringByAppendingPathComponent("/Pulse/Sync/3. All your friends/from/")
let filePath = (rootPath as NSString).stringByAppendingPathComponent("\(theCommand)/\(downloadFolder)/\(downloadFileName)")
NSWorkspace.sharedWorkspace().selectFile(filePath, inFileViewerRootedAtPath: rootPath)
}
}
}
decisionHandler(WKNavigationActionPolicy.Cancel)
}
else
{
// Not indie protocol: allow.
......
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