-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 17c636d
Showing
14 changed files
with
694 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.DS_Store | ||
*.xcodeproj/*.mode?v? | ||
*.xcodeproj/*.pbxuser | ||
*.xcodeproj/project.xcworkspace/ | ||
*.xcodeproj/xcuserdata/ |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// AppDelegate.swift | ||
// CalltoBouncer | ||
// | ||
// Copyright © 2017 64 Characters | ||
// | ||
|
||
import Cocoa | ||
|
||
@NSApplicationMain | ||
final class AppDelegate: NSObject, NSApplicationDelegate { | ||
private let target = OpenURLEventTarget(manager: NSAppleEventManager.shared(), workspace: NSWorkspace.shared()) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct"> | ||
<dependencies> | ||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11762"/> | ||
</dependencies> | ||
<objects> | ||
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication"> | ||
<connections> | ||
<outlet property="delegate" destination="Voe-Tx-rLC" id="GzC-gU-4Uq"/> | ||
</connections> | ||
</customObject> | ||
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/> | ||
<customObject id="-3" userLabel="Application" customClass="NSObject"/> | ||
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="CalltoAdapter" customModuleProvider="target"/> | ||
</objects> | ||
</document> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>com.apple.security.app-sandbox</key> | ||
<true/> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>en</string> | ||
<key>CFBundleExecutable</key> | ||
<string>$(EXECUTABLE_NAME)</string> | ||
<key>CFBundleIconFile</key> | ||
<string></string> | ||
<key>CFBundleIdentifier</key> | ||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>$(PRODUCT_NAME)</string> | ||
<key>CFBundlePackageType</key> | ||
<string>APPL</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>1.0</string> | ||
<key>CFBundleURLTypes</key> | ||
<array> | ||
<dict> | ||
<key>CFBundleTypeRole</key> | ||
<string>Editor</string> | ||
<key>CFBundleURLName</key> | ||
<string>Callto URL</string> | ||
<key>CFBundleURLSchemes</key> | ||
<array> | ||
<string>callto</string> | ||
</array> | ||
</dict> | ||
</array> | ||
<key>CFBundleVersion</key> | ||
<string>1</string> | ||
<key>LSMinimumSystemVersion</key> | ||
<string>$(MACOSX_DEPLOYMENT_TARGET)</string> | ||
<key>NSHumanReadableCopyright</key> | ||
<string>Copyright © 2017 64 Characters</string> | ||
<key>NSMainNibFile</key> | ||
<string>Main</string> | ||
<key>NSPrincipalClass</key> | ||
<string>NSApplication</string> | ||
<key>LSBackgroundOnly</key> | ||
<true/> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// OpenURLEventTarget.swift | ||
// CalltoBouncer | ||
// | ||
// Copyright © 2017 64 Characters | ||
// | ||
|
||
import Cocoa | ||
|
||
final class OpenURLEventTarget { | ||
private let manager: NSAppleEventManager | ||
private let workspace: NSWorkspace | ||
|
||
init(manager: NSAppleEventManager, workspace: NSWorkspace) { | ||
self.manager = manager | ||
self.workspace = workspace | ||
self.manager.setEventHandler( | ||
self, | ||
andSelector: #selector(handle(_:reply:)), | ||
forEventClass: AEEventClass(kInternetEventClass), | ||
andEventID: AEEventID(kAEGetURL) | ||
) | ||
} | ||
|
||
deinit { | ||
manager.removeEventHandler(forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL)) | ||
} | ||
|
||
@objc private func handle(_ event: NSAppleEventDescriptor, reply: NSAppleEventDescriptor) { | ||
if let calltoURL = event.paramDescriptor(forKeyword: keyDirectObject)?.stringValue { | ||
if let telURL = URL(string: TelURL(phone: PhoneNumber(calltoURL: calltoURL))) { | ||
workspace.open(telURL) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// PhoneNumber.swift | ||
// CalltoBouncer | ||
// | ||
// Copyright © 2017 64 Characters | ||
// | ||
|
||
import Foundation | ||
|
||
typealias PhoneNumber = String | ||
|
||
extension PhoneNumber { | ||
init(calltoURL url: String) { | ||
self = strippingSlashes(from: strippingCallto(from: url)) | ||
} | ||
} | ||
|
||
private func strippingCallto(from string: String) -> String { | ||
if let range = string.range(of: "callto:") { | ||
return string.substring(from: range.upperBound) | ||
} else { | ||
return string | ||
} | ||
} | ||
|
||
private func strippingSlashes(from string: String) -> String { | ||
if let range = string.range(of: "//") { | ||
return string.substring(from: range.upperBound) | ||
} else { | ||
return string | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// TelURL.swift | ||
// CalltoBouncer | ||
// | ||
// Copyright © 2017 64 Characters | ||
// | ||
|
||
typealias TelURL = String | ||
|
||
extension TelURL { | ||
init(phone: PhoneNumber) { | ||
self = "tel:\(phone)" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>en</string> | ||
<key>CFBundleExecutable</key> | ||
<string>$(EXECUTABLE_NAME)</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>$(PRODUCT_NAME)</string> | ||
<key>CFBundlePackageType</key> | ||
<string>BNDL</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>1.0</string> | ||
<key>CFBundleVersion</key> | ||
<string>1</string> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// PhoneNumberTests.swift | ||
// CalltoBouncer | ||
// | ||
// Copyright © 2017 64 Characters | ||
// | ||
|
||
import XCTest | ||
|
||
final class PhoneNumberTests: XCTestCase { | ||
func testStripsCallto() { | ||
let sut = PhoneNumber(calltoURL: "callto:any") | ||
|
||
XCTAssertEqual(sut, "any") | ||
} | ||
|
||
func testStripsTwoSlashes() { | ||
let sut = PhoneNumber(calltoURL: "callto://any") | ||
|
||
XCTAssertEqual(sut, "any") | ||
} | ||
|
||
func testReturnsOriginalStringWhenThereIsNoCallto() { | ||
let sut = PhoneNumber(calltoURL: "any") | ||
|
||
XCTAssertEqual(sut, "any") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// TelURLTests.swift | ||
// CalltoBouncer | ||
// | ||
// Copyright © 2017 64 Characters | ||
// | ||
|
||
import XCTest | ||
|
||
final class TelURLTests: XCTestCase { | ||
func testAddsTelScheme() { | ||
let sut = TelURL(phone: PhoneNumber(calltoURL: "callto:any")) | ||
|
||
XCTAssertEqual(sut, "tel:any") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2017 64 Characters | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
CalltoBouncer is a macOS utility that handles `callto` URL open events | ||
by opening `tel` URLs with the same phone number. | ||
|
||
It might be useful when you make phone calls by clicking the `callto` | ||
links and you want those calls to be made via an application that only | ||
responds to the `tel` URLs. | ||
|
||
If another application that handles the `callto` URLs is already | ||
present in the system and being opened, CalltoBouncer needs to be set | ||
as a handler for this URL scheme. This can be done via the | ||
[RCDefaultApp] perference pane. | ||
|
||
CalltoBouncer works in background and doesn't have any UI. Once | ||
registered as a handler, it doesn't even need to be automatically | ||
started with the system strart, because the system launches it when | ||
needed. | ||
|
||
[RCDefaultApp]: http://www.rubicode.com/Software/RCDefaultApp/ |