Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
eofster committed Feb 17, 2017
0 parents commit 17c636d
Show file tree
Hide file tree
Showing 14 changed files with 694 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
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/
417 changes: 417 additions & 0 deletions CalltoBouncer.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions CalltoBouncer/AppDelegate.swift
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())
}

16 changes: 16 additions & 0 deletions CalltoBouncer/Base.lproj/Main.xib
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>
8 changes: 8 additions & 0 deletions CalltoBouncer/CalltoBouncer.entitlements
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>
47 changes: 47 additions & 0 deletions CalltoBouncer/Info.plist
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>
36 changes: 36 additions & 0 deletions CalltoBouncer/OpenURLEventTarget.swift
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)
}
}
}
}
32 changes: 32 additions & 0 deletions CalltoBouncer/PhoneNumber.swift
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
}
}
14 changes: 14 additions & 0 deletions CalltoBouncer/TelURL.swift
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)"
}
}
22 changes: 22 additions & 0 deletions CalltoBouncerTests/Info.plist
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>
28 changes: 28 additions & 0 deletions CalltoBouncerTests/PhoneNumberTests.swift
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")
}
}
16 changes: 16 additions & 0 deletions CalltoBouncerTests/TelURLTests.swift
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")
}
}
21 changes: 21 additions & 0 deletions LICENSE
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.
18 changes: 18 additions & 0 deletions README.md
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/

0 comments on commit 17c636d

Please sign in to comment.