-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
43fcdad
commit c5e2264
Showing
71 changed files
with
819 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
HeliPort/Appearance/StatusBarIcon/StatusBarIconLegacy.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// StatusBarIconLegacy.swift | ||
// HeliPort | ||
// | ||
// Created by Bat.bat on 25/6/2024. | ||
// Copyright © 2020 OpenIntelWireless. All rights reserved. | ||
// | ||
|
||
/* | ||
* This program and the accompanying materials are licensed and made available | ||
* under the terms and conditions of the The 3-Clause BSD License | ||
* which accompanies this distribution. The full text of the license may be found at | ||
* https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import Cocoa | ||
|
||
class StatusBarIconLegacy: StatusBarIconProvider { | ||
var transition: CATransition? { return nil } | ||
var off: NSImage { return #imageLiteral(resourceName: "LegacyStateOff") } | ||
var connected: NSImage { return #imageLiteral(resourceName: "LegacyStateOn") } | ||
var disconnected: NSImage { return #imageLiteral(resourceName: "LegacyStateDisconnected") } | ||
var warning: NSImage { return #imageLiteral(resourceName: "LegacyStateWarning") } | ||
var scanning: [NSImage] { | ||
return [ | ||
#imageLiteral(resourceName: "LegacyStateScanning1"), | ||
#imageLiteral(resourceName: "LegacyStateScanning2"), | ||
#imageLiteral(resourceName: "LegacyStateScanning3"), | ||
#imageLiteral(resourceName: "LegacyStateScanning4") | ||
] | ||
} | ||
|
||
func getRssiImage(_ RSSI: Int16) -> NSImage? { | ||
switch RSSI { | ||
case ..<(-100): return #imageLiteral(resourceName: "LegacySignalStrengthPoor") | ||
case ..<(-80): return #imageLiteral(resourceName: "LegacySignalStrengthFair") | ||
case ..<(-60): return #imageLiteral(resourceName: "LegacySignalStrengthGood") | ||
default: return #imageLiteral(resourceName: "LegacySignalStrengthExcellent") | ||
} | ||
} | ||
} |
128 changes: 128 additions & 0 deletions
128
HeliPort/Appearance/StatusBarIcon/StatusBarIconManager.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
// | ||
// StatusBarIconManager.swift | ||
// HeliPort | ||
// | ||
// Created by 梁怀宇 on 2020/4/7. | ||
// Copyright © 2020 OpenIntelWireless. All rights reserved. | ||
// | ||
|
||
/* | ||
* This program and the accompanying materials are licensed and made available | ||
* under the terms and conditions of the The 3-Clause BSD License | ||
* which accompanies this distribution. The full text of the license may be found at | ||
* https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import Cocoa | ||
|
||
protocol StatusBarIconProvider { | ||
var transition: CATransition? { get } | ||
var off: NSImage { get } | ||
var connected: NSImage { get } | ||
var disconnected: NSImage { get } | ||
var warning: NSImage { get } | ||
var scanning: [NSImage] { get } | ||
func getRssiImage(_ RSSI: Int16) -> NSImage? | ||
} | ||
|
||
class StatusBarIcon { | ||
private static var instance: StatusBarIcon? | ||
|
||
private let statusBar: NSStatusItem | ||
private let icons: StatusBarIconProvider | ||
private var timer: Timer? | ||
private var tickIndex: Int = 0 | ||
private var tickDirection: Int = 1 | ||
|
||
private init(_ statusBar: NSStatusItem, _ icons: StatusBarIconProvider) { | ||
self.statusBar = statusBar | ||
self.icons = icons | ||
} | ||
|
||
static func shared(statusBar: NSStatusItem? = nil, icons: StatusBarIconProvider? = nil) -> StatusBarIcon { | ||
if let instance { | ||
return instance | ||
} | ||
guard let statusBar, let icons else { | ||
fatalError("Must provide statusBar and iconProvider for the first initialization.") | ||
} | ||
instance = StatusBarIcon(statusBar, icons) | ||
return instance! | ||
} | ||
|
||
func on() { | ||
stopTimer() | ||
disconnected() | ||
} | ||
|
||
func off() { | ||
stopTimer() | ||
statusBar.button?.image = icons.off | ||
} | ||
|
||
func connected() { | ||
stopTimer() | ||
statusBar.button?.image = icons.connected | ||
} | ||
|
||
func disconnected() { | ||
stopTimer() | ||
statusBar.button?.image = icons.disconnected | ||
} | ||
|
||
func connecting() { | ||
guard timer == nil else { return } | ||
tickIndex = 0 | ||
tickDirection = 1 | ||
DispatchQueue.global(qos: .default).async { | ||
self.timer = Timer.scheduledTimer( | ||
timeInterval: 0.3, | ||
target: self, | ||
selector: #selector(self.tick), | ||
userInfo: nil, | ||
repeats: true | ||
) | ||
self.timer?.fire() | ||
RunLoop.current.add(self.timer!, forMode: .common) | ||
RunLoop.current.run() | ||
} | ||
} | ||
|
||
func warning() { | ||
stopTimer() | ||
statusBar.button?.image = icons.warning | ||
} | ||
|
||
func error() { | ||
stopTimer() | ||
statusBar.button?.image = #imageLiteral(resourceName: "WiFiStateError") | ||
} | ||
|
||
func signalStrength(rssi: Int16) { | ||
stopTimer() | ||
statusBar.button?.image = icons.getRssiImage(rssi) | ||
} | ||
|
||
func getRssiImage(rssi: Int16) -> NSImage? { | ||
return icons.getRssiImage(rssi) | ||
} | ||
|
||
@objc private func tick() { | ||
DispatchQueue.main.async { | ||
if let transition = self.icons.transition { | ||
self.statusBar.button?.layer?.add(transition, forKey: kCATransition) | ||
} | ||
self.statusBar.button?.image = self.icons.scanning[self.tickIndex] | ||
|
||
self.tickIndex += self.tickDirection | ||
if self.tickIndex == 0 || self.tickIndex == self.icons.scanning.endIndex - 1 { | ||
self.tickDirection *= -1 | ||
} | ||
} | ||
} | ||
|
||
private func stopTimer() { | ||
timer?.invalidate() | ||
timer = nil | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
HeliPort/Appearance/StatusBarIcon/StatusBarIconModern.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// | ||
// StatusBarIconModern.swift | ||
// HeliPort | ||
// | ||
// Created by Bat.bat on 25/6/2024. | ||
// Copyright © 2024 OpenIntelWireless. All rights reserved. | ||
// | ||
|
||
/* | ||
* This program and the accompanying materials are licensed and made available | ||
* under the terms and conditions of the The 3-Clause BSD License | ||
* which accompanies this distribution. The full text of the license may be found at | ||
* https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import Cocoa | ||
|
||
class StatusBarIconModern: StatusBarIconProvider { | ||
var transition: CATransition? { | ||
let transition = CATransition() | ||
transition.type = .fade | ||
transition.duration = 0.2 | ||
return transition | ||
} | ||
var off: NSImage { return #imageLiteral(resourceName: "ModernStateOff") } | ||
var connected: NSImage { return #imageLiteral(resourceName: "ModernStateOn") } | ||
var disconnected: NSImage { return #imageLiteral(resourceName: "ModernStateDisconnected") } | ||
var warning: NSImage { return #imageLiteral(resourceName: "ModernStateWarning") } | ||
var scanning: [NSImage] { | ||
return [ | ||
#imageLiteral(resourceName: "ModernStateScanning1"), | ||
#imageLiteral(resourceName: "ModernStateScanning2"), | ||
#imageLiteral(resourceName: "ModernStateScanning3") | ||
] | ||
} | ||
|
||
func getRssiImage(_ RSSI: Int16) -> NSImage? { | ||
switch RSSI { | ||
case ..<(-90): return #imageLiteral(resourceName: "ModernSignalStrengthPoor") | ||
case ..<(-70): return #imageLiteral(resourceName: "ModernSignalStrengthFair") | ||
default: return #imageLiteral(resourceName: "ModernSignalStrengthGood") | ||
} | ||
} | ||
} |
Oops, something went wrong.