Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

T3NativeControlsModule.swift

57 lines1.8 KB

1import ExpoModulesCore
2import Security
3​
4public final class T3NativeControlsModule: Module {
5 public func definition() -> ModuleDefinition {
6 Name("T3NativeControls")
7​
8 Function("getShowcasePairingUrl") {
9 let arguments = ProcessInfo.processInfo.arguments
10 guard
11 let flagIndex = arguments.firstIndex(of: "--showcasePairingUrl"),
12 arguments.indices.contains(flagIndex + 1)
13 else {
14 return nil as String?
15 }
16 return arguments[flagIndex + 1]
17 }
18​
19 Function("getShowcaseScene") { () -> String? in
20 let scenePath = NSHomeDirectory() + "/Library/Caches/T3ShowcaseScene"
21 if let storedScene = try? String(contentsOfFile: scenePath, encoding: .utf8)
22 .trimmingCharacters(in: .whitespacesAndNewlines), !storedScene.isEmpty {
23 return storedScene
24 }
25 let arguments = ProcessInfo.processInfo.arguments
26 guard
27 let flagIndex = arguments.firstIndex(of: "--showcaseScene"),
28 arguments.indices.contains(flagIndex + 1)
29 else {
30 return nil as String?
31 }
32 return arguments[flagIndex + 1]
33 }
34​
35 Function("prepareShowcaseCapture") {
36 for itemClass in [kSecClassGenericPassword, kSecClassInternetPassword] {
37 SecItemDelete([kSecClass as String: itemClass] as CFDictionary)
38 }
39 }
40​
41 Function("markShowcaseReady") { (scene: String) in
42 let readyPath = NSHomeDirectory() + "/Library/Caches/T3ShowcaseReadyScene"
43 try? scene.write(toFile: readyPath, atomically: true, encoding: .utf8)
44 }
45​
46 View(T3HeaderButtonView.self) {
47 Prop("label") { (view: T3HeaderButtonView, label: String) in
48 view.setLabel(label)
49 }
50 Prop("systemImage") { (view: T3HeaderButtonView, systemImage: String) in
51 view.setSystemImage(systemImage)
52 }
53​
54 Events("onTriggered")
55 }
56 }