Skip to content

Commit 17c636d

Browse files
committed
Initial commit
0 parents  commit 17c636d

File tree

14 files changed

+694
-0
lines changed

14 files changed

+694
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.DS_Store
2+
*.xcodeproj/*.mode?v?
3+
*.xcodeproj/*.pbxuser
4+
*.xcodeproj/project.xcworkspace/
5+
*.xcodeproj/xcuserdata/

CalltoBouncer.xcodeproj/project.pbxproj

Lines changed: 417 additions & 0 deletions
Large diffs are not rendered by default.

CalltoBouncer/AppDelegate.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// AppDelegate.swift
3+
// CalltoBouncer
4+
//
5+
// Copyright © 2017 64 Characters
6+
//
7+
8+
import Cocoa
9+
10+
@NSApplicationMain
11+
final class AppDelegate: NSObject, NSApplicationDelegate {
12+
private let target = OpenURLEventTarget(manager: NSAppleEventManager.shared(), workspace: NSWorkspace.shared())
13+
}
14+

CalltoBouncer/Base.lproj/Main.xib

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
3+
<dependencies>
4+
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11762"/>
5+
</dependencies>
6+
<objects>
7+
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
8+
<connections>
9+
<outlet property="delegate" destination="Voe-Tx-rLC" id="GzC-gU-4Uq"/>
10+
</connections>
11+
</customObject>
12+
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
13+
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
14+
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="CalltoAdapter" customModuleProvider="target"/>
15+
</objects>
16+
</document>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>com.apple.security.app-sandbox</key>
6+
<true/>
7+
</dict>
8+
</plist>

CalltoBouncer/Info.plist

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>en</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIconFile</key>
10+
<string></string>
11+
<key>CFBundleIdentifier</key>
12+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
13+
<key>CFBundleInfoDictionaryVersion</key>
14+
<string>6.0</string>
15+
<key>CFBundleName</key>
16+
<string>$(PRODUCT_NAME)</string>
17+
<key>CFBundlePackageType</key>
18+
<string>APPL</string>
19+
<key>CFBundleShortVersionString</key>
20+
<string>1.0</string>
21+
<key>CFBundleURLTypes</key>
22+
<array>
23+
<dict>
24+
<key>CFBundleTypeRole</key>
25+
<string>Editor</string>
26+
<key>CFBundleURLName</key>
27+
<string>Callto URL</string>
28+
<key>CFBundleURLSchemes</key>
29+
<array>
30+
<string>callto</string>
31+
</array>
32+
</dict>
33+
</array>
34+
<key>CFBundleVersion</key>
35+
<string>1</string>
36+
<key>LSMinimumSystemVersion</key>
37+
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
38+
<key>NSHumanReadableCopyright</key>
39+
<string>Copyright © 2017 64 Characters</string>
40+
<key>NSMainNibFile</key>
41+
<string>Main</string>
42+
<key>NSPrincipalClass</key>
43+
<string>NSApplication</string>
44+
<key>LSBackgroundOnly</key>
45+
<true/>
46+
</dict>
47+
</plist>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//
2+
// OpenURLEventTarget.swift
3+
// CalltoBouncer
4+
//
5+
// Copyright © 2017 64 Characters
6+
//
7+
8+
import Cocoa
9+
10+
final class OpenURLEventTarget {
11+
private let manager: NSAppleEventManager
12+
private let workspace: NSWorkspace
13+
14+
init(manager: NSAppleEventManager, workspace: NSWorkspace) {
15+
self.manager = manager
16+
self.workspace = workspace
17+
self.manager.setEventHandler(
18+
self,
19+
andSelector: #selector(handle(_:reply:)),
20+
forEventClass: AEEventClass(kInternetEventClass),
21+
andEventID: AEEventID(kAEGetURL)
22+
)
23+
}
24+
25+
deinit {
26+
manager.removeEventHandler(forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL))
27+
}
28+
29+
@objc private func handle(_ event: NSAppleEventDescriptor, reply: NSAppleEventDescriptor) {
30+
if let calltoURL = event.paramDescriptor(forKeyword: keyDirectObject)?.stringValue {
31+
if let telURL = URL(string: TelURL(phone: PhoneNumber(calltoURL: calltoURL))) {
32+
workspace.open(telURL)
33+
}
34+
}
35+
}
36+
}

CalltoBouncer/PhoneNumber.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// PhoneNumber.swift
3+
// CalltoBouncer
4+
//
5+
// Copyright © 2017 64 Characters
6+
//
7+
8+
import Foundation
9+
10+
typealias PhoneNumber = String
11+
12+
extension PhoneNumber {
13+
init(calltoURL url: String) {
14+
self = strippingSlashes(from: strippingCallto(from: url))
15+
}
16+
}
17+
18+
private func strippingCallto(from string: String) -> String {
19+
if let range = string.range(of: "callto:") {
20+
return string.substring(from: range.upperBound)
21+
} else {
22+
return string
23+
}
24+
}
25+
26+
private func strippingSlashes(from string: String) -> String {
27+
if let range = string.range(of: "//") {
28+
return string.substring(from: range.upperBound)
29+
} else {
30+
return string
31+
}
32+
}

CalltoBouncer/TelURL.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// TelURL.swift
3+
// CalltoBouncer
4+
//
5+
// Copyright © 2017 64 Characters
6+
//
7+
8+
typealias TelURL = String
9+
10+
extension TelURL {
11+
init(phone: PhoneNumber) {
12+
self = "tel:\(phone)"
13+
}
14+
}

CalltoBouncerTests/Info.plist

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>en</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundleName</key>
14+
<string>$(PRODUCT_NAME)</string>
15+
<key>CFBundlePackageType</key>
16+
<string>BNDL</string>
17+
<key>CFBundleShortVersionString</key>
18+
<string>1.0</string>
19+
<key>CFBundleVersion</key>
20+
<string>1</string>
21+
</dict>
22+
</plist>

0 commit comments

Comments
 (0)