Skip to content

Commit e19759c

Browse files
BohdanBohdan
authored andcommitted
No-ticket: Small refactor
1 parent a2e9837 commit e19759c

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

LanguageFlag/Helpers/CapsLockManager.swift

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Cocoa
2+
import Carbon
23

34
class CapsLockManager {
45

@@ -27,17 +28,21 @@ extension CapsLockManager {
2728
let capsLockEnabled = event.modifierFlags.contains(.capsLock)
2829
if isCapsLockEnabled != capsLockEnabled {
2930
isCapsLockEnabled = capsLockEnabled
30-
DispatchQueue.main.asyncAfter(deadline: .now() + 0.15) {
31-
self.notifyCapsLockStateChanged()
31+
32+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.10) {
33+
self.notifyCapsLockStateChanged(newCapsLockEnabled: capsLockEnabled)
3234
}
3335
}
3436
}
3537

3638
/// Notifies observers about the Caps Lock state change.
37-
private func notifyCapsLockStateChanged() {
38-
NotificationCenter.default.post(
39-
name: .keyboardLayoutChanged,
40-
object: nil // Pass data if needed
41-
)
39+
private func notifyCapsLockStateChanged(newCapsLockEnabled: Bool) {
40+
let currentLayout = TISCopyCurrentKeyboardInputSource().takeUnretainedValue()
41+
let model = KeyboardLayoutNotification(keyboardLayout: currentLayout.name,
42+
isCapsLockEnabled: newCapsLockEnabled,
43+
iconRef: currentLayout.iconRef)
44+
45+
NotificationCenter.default.post(name: .keyboardLayoutChanged,
46+
object: model)
4247
}
4348
}

LanguageFlag/Helpers/NotificationManager.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Foundation
22
import Carbon
3+
import Combine
34

45
class NotificationManager {
56

@@ -33,6 +34,7 @@ extension NotificationManager {
3334
let model = KeyboardLayoutNotification(keyboardLayout: currentLayout.name,
3435
isCapsLockEnabled: capsLockManager.isCapsLockEnabled,
3536
iconRef: currentLayout.iconRef)
37+
3638
NotificationCenter.default.post(name: .keyboardLayoutChanged, object: model)
3739
}
3840
}

LanguageFlag/Stories/Base.lproj/Main.storyboard

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="21507" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
2+
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="23503" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
33
<dependencies>
44
<deployment identifier="macosx"/>
5-
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21507"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="23503"/>
66
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
77
</dependencies>
88
<scenes>
@@ -105,7 +105,7 @@
105105
<visualEffectView blendingMode="behindWindow" material="toolTip" state="active" translatesAutoresizingMaskIntoConstraints="NO" id="pBq-xi-oWC">
106106
<rect key="frame" x="0.0" y="0.0" width="250" height="155"/>
107107
<subviews>
108-
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="fuB-UH-0Lr" userLabel="Big Label">
108+
<textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="fuB-UH-0Lr" userLabel="Big Label">
109109
<rect key="frame" x="14" y="66" width="222" height="24"/>
110110
<textFieldCell key="cell" lineBreakMode="clipping" truncatesLastVisibleLine="YES" allowsUndo="NO" alignment="center" id="9NG-8A-OgX">
111111
<font key="font" metaFont="system" size="21"/>
@@ -121,7 +121,7 @@
121121
</constraints>
122122
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="hpf-7H-XHV"/>
123123
</imageView>
124-
<textField wantsLayer="YES" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="A3c-Wz-P9g">
124+
<textField wantsLayer="YES" focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="A3c-Wz-P9g">
125125
<rect key="frame" x="101" y="13" width="48" height="19"/>
126126
<textFieldCell key="cell" lineBreakMode="clipping" alignment="center" title="Label" id="sfL-RG-8GF">
127127
<font key="font" metaFont="system" size="16"/>

0 commit comments

Comments
 (0)