Skip to content

Commit a2e9837

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

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed

LanguageFlag/Helpers/LayoutImageContainer.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ final class LayoutImageContainer {
1212

1313
// MARK: Variables
1414
static let shared = LayoutImageContainer()
15+
1516
private lazy var layoutDictionary: Dictionary<String, String> = {
1617
createLayoutDictionary()
1718
}()
1819
private var cachedIcons = NSCache<NSString, NSImage>()
1920

20-
// MARK: Public
21+
// MARK: Internal
2122
func getImage(for keyboardLayout: String) -> NSImage? {
2223
guard
2324
let imageName = layoutDictionary[keyboardLayout],

LanguageFlag/Stories/LanguageViewController.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class LanguageViewController: NSViewController {
2727
addObserver()
2828
}
2929

30+
// MARK: - Deinit
3031
deinit {
3132
NotificationCenter.default.removeObserver(self)
3233
}
@@ -38,7 +39,10 @@ extension LanguageViewController {
3839
@objc
3940
private func keyboardLayoutChanged(notification: NSNotification) {
4041
guard let model = notification.object as? KeyboardLayoutNotification else { return }
41-
changeFlagImage(keyboardLayout: model.keyboardLayout, isCapsLockEnabled: model.isCapsLockEnabled, iconRef: model.iconRef)
42+
43+
changeFlagImage(keyboardLayout: model.keyboardLayout,
44+
isCapsLockEnabled: model.isCapsLockEnabled,
45+
iconRef: model.iconRef)
4246
}
4347
}
4448

LanguageFlag/Stories/LanguageWindow.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
//
2-
// LanguageWindow.swift
3-
// LanguageFlag
4-
//
5-
// Created by Bohdan Bochkovskyi on 26.02.2023.
6-
// Copyright © 2023 Bohdan. All rights reserved.
7-
//
8-
91
import Cocoa
102

113
final class LanguageWindow: NSWindow {
124

5+
// MARK: - Init
136
init(contentRect: NSRect) {
147
super.init(contentRect: contentRect, styleMask: .borderless, backing: .buffered, defer: false)
8+
configureAppearance()
9+
}
10+
11+
// MARK: - Private
12+
private func configureAppearance() {
1513
isOpaque = false
1614
backgroundColor = .clear
1715
level = .floating

LanguageFlag/Stories/LanguageWindowController.swift

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ final class LanguageWindowController: NSWindowController {
3535
configureContentViewController()
3636
addObserver()
3737
}
38+
39+
// MARK: - Deinit
40+
deinit {
41+
NotificationCenter.default.removeObserver(self)
42+
}
3843
}
3944

4045
// MARK: - Actions
@@ -58,8 +63,8 @@ extension LanguageWindowController {
5863
extension LanguageWindowController {
5964

6065
private func configureWindow() {
61-
let screenRect = screenRect ?? NSScreen.main?.visibleFrame
62-
guard let screenRect else { return }
66+
guard let screenRect = screenRect ?? NSScreen.main?.visibleFrame else { return }
67+
6368
let rect = createRect(in: screenRect)
6469
window = LanguageWindow(contentRect: rect)
6570
window?.setFrame(rect, display: true)
@@ -69,20 +74,23 @@ extension LanguageWindowController {
6974
let posX: CGFloat = screen.minX + (screen.width - LanguageViewController.width) / 2
7075
let posY: CGFloat = screen.minY + screen.height * 0.16
7176
let rect = NSRect(x: posX, y: posY, width: LanguageViewController.width, height: LanguageViewController.height)
77+
7278
return rect
7379
}
7480

7581
private func configureContentViewController() {
7682
let mainStoryboard = NSStoryboard.init(name: "Main", bundle: nil)
83+
7784
guard let flagVC = mainStoryboard.instantiateController(withIdentifier: "flagController") as? LanguageViewController else {
7885
return
7986
}
87+
8088
window?.contentViewController = flagVC
8189
let cornerRadius: CGFloat = 16
82-
window?.contentView?.wantsLayer = true
83-
window?.contentView?.layer?.cornerRadius = cornerRadius
84-
window?.contentView?.superview?.wantsLayer = true
85-
window?.contentView?.superview?.layer?.cornerRadius = cornerRadius
90+
[window?.contentView, window?.contentView?.superview].forEach {
91+
$0?.wantsLayer = true
92+
$0?.layer?.cornerRadius = cornerRadius
93+
}
8694
}
8795

8896
private func addObserver() {

0 commit comments

Comments
 (0)