1+ /**
2+ * Copyright (c) 2024 Nightwind. All rights reserved.
3+ */
4+
5+ import Orion
6+ import VisionSearchPillC
7+
8+ class PillHook : ClassHook < SBHSearchPillView > {
9+ func didMoveToWindow( ) {
10+ orig. didMoveToWindow ( )
11+
12+ // Apply changes without respring
13+ DistributedNotificationCenter . default ( ) . addObserver ( forName: Notification . Name ( " VisionSearchPillPreferenceSet " ) , object: nil , queue: . main) { _ in
14+ self . target. applyVisionStyle ( )
15+ }
16+ }
17+
18+ func layoutSubviews( ) {
19+ orig. layoutSubviews ( )
20+ target. applyVisionStyle ( )
21+ }
22+
23+ /**
24+ * Apply the VisionOS style to the search pill.
25+ */
26+ // orion:new
27+ @objc func applyVisionStyle( ) {
28+ // Load the settings of the tweak
29+ do {
30+ try TweakPreferences . shared. loadSettings ( )
31+ } catch {
32+ remLog ( " error: \( error. localizedDescription) " )
33+ return
34+ }
35+
36+ // Store the settings
37+ let tweakEnabled : Bool = TweakPreferences . shared. settings. tweakEnabled
38+ let borderWidth : CGFloat = TweakPreferences . shared. settings. borderWidth
39+
40+ let backgroundColor : UIColor = TweakPreferences . shared. colorFor ( key: " backgroundColor " , fallback: " #ffffffff " )
41+ let borderColor : UIColor = TweakPreferences . shared. colorFor ( key: " borderColor " , fallback: " #ffffffff " )
42+
43+ // Apply the style
44+ guard let backgroundView = target. backgroundView else { return }
45+ backgroundView. layer. borderWidth = tweakEnabled ? borderWidth : 0
46+ backgroundView. layer. borderColor = tweakEnabled ? borderColor. cgColor : UIColor . clear. cgColor
47+ backgroundView. alpha = tweakEnabled ? 0.1 : 1
48+
49+ target. alpha = tweakEnabled ? 0.1 : 1
50+ target. backgroundColor = tweakEnabled ? backgroundColor : . clear
51+ target. layer. cornerRadius = tweakEnabled ? backgroundView. layer. cornerRadius : 0
52+ target. clipsToBounds = tweakEnabled ? true : false
53+ }
54+ }
55+
56+ class BackgroundPillHook : ClassHook < SBFolderScrollAccessoryView > {
57+ func didMoveToWindow( ) {
58+ orig. didMoveToWindow ( )
59+ target. applyVisionStyle ( )
60+
61+ // Apply changes without respring
62+ DistributedNotificationCenter . default ( ) . addObserver ( forName: Notification . Name ( " VisionSearchPillPreferenceSet " ) , object: nil , queue: . main) { _ in
63+ self . target. applyVisionStyle ( )
64+ }
65+ }
66+
67+ /**
68+ * Apply the VisionOS style to the search pill
69+ */
70+ // orion:new
71+ @objc func applyVisionStyle( ) {
72+ // Load the settings of the tweak
73+ do {
74+ try TweakPreferences . shared. loadSettings ( )
75+ } catch {
76+ remLog ( " error: \( error. localizedDescription) " )
77+ return
78+ }
79+
80+ // Store the settings
81+ let tweakEnabled : Bool = TweakPreferences . shared. settings. tweakEnabled
82+ let borderWidth : CGFloat = TweakPreferences . shared. settings. borderWidth
83+
84+ let backgroundColor : UIColor = TweakPreferences . shared. colorFor ( key: " backgroundColor " , fallback: " #ffffffff " )
85+ let borderColor : UIColor = TweakPreferences . shared. colorFor ( key: " borderColor " , fallback: " #ffffffff " )
86+
87+ // Apply the style
88+ guard let backgroundView = target. backgroundView else { return }
89+ backgroundView. layer. borderWidth = tweakEnabled ? borderWidth : 0
90+ backgroundView. layer. borderColor = tweakEnabled ? borderColor. cgColor : UIColor . clear. cgColor
91+ backgroundView. alpha = tweakEnabled ? 0.1 : 1
92+ backgroundView. backgroundColor = tweakEnabled ? backgroundColor : . clear
93+ }
94+ }
95+
96+ class VisionSearchPill : Tweak {
97+ required init ( ) {
98+ remLog ( " VisionSearchPill starting " )
99+ do {
100+ try TweakPreferences . shared. loadSettings ( )
101+ } catch {
102+ remLog ( " Unexpected error: \( error. localizedDescription) " )
103+ }
104+ }
105+
106+ static func handleError( _ error: OrionHookError ) {
107+ remLog ( error)
108+ DefaultTweak . handleError ( error)
109+ }
110+ }
0 commit comments