Replace status icon with color-agnostic shapes

Fixes #199
This commit is contained in:
Davide De Rosa 2021-11-05 20:42:58 +01:00
parent ae1aa1a268
commit 0c448e7f91
14 changed files with 93 additions and 79 deletions

View File

@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## 1.17.0 Beta 2831 (2021-10-18)
## Unreleased
### Changed

View File

@ -1,6 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
}
}

View File

@ -0,0 +1,25 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "StatusActive@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "StatusActive@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 798 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -1,55 +0,0 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "StatusBarButtonImage@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "StatusBarButtonImage@3x.png",
"idiom" : "universal",
"scale" : "3x"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 434 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 493 B

View File

@ -0,0 +1,25 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "StatusPending@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "StatusPending@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@ -5,12 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## 1.17.0 Beta 2831 (2021-10-18)
## Unreleased
### Changed
- Allow Oeck provider without any purchase.
- Status bar icon color had to be dropped in order to automatically adjust to desktop background color.
- Drop status bar icon color to automatically adjust to desktop background color. [#199](https://github.com/passepartoutvpn/passepartout-apple/issues/199)
- Migrate to SwiftPM.
### Fixed

View File

@ -20,7 +20,8 @@ internal typealias AssetImageTypeAlias = ImageAsset.Image
// swiftlint:disable identifier_name line_length nesting type_body_length type_name
internal enum Asset {
internal enum Assets {
internal static let statusBarButtonImage = ImageAsset(name: "StatusBarButtonImage")
internal static let statusActive = ImageAsset(name: "StatusActive")
internal static let statusPending = ImageAsset(name: "StatusPending")
}
internal enum Flags {
internal static let ad = ImageAsset(name: "ad")

View File

@ -57,13 +57,9 @@ class StatusMenu: NSObject {
// MARK: Button images
private let imageStatus = Asset.Assets.statusBarButtonImage.image
private let imageStatusActive = Asset.Assets.statusActive.image
private lazy var imageStatusActive: NSImage = imageStatus.tinted(withColor: Theme.current.palette.colorOn)
private lazy var imageStatusInactive: NSImage = imageStatus.tinted(withColor: Theme.current.palette.colorPrimaryText)
private lazy var imageStatusInProgress: NSImage = imageStatus.tinted(withColor: Theme.current.palette.colorIndeterminate)
private let imageStatusPending = Asset.Assets.statusPending.image
// MARK: Menu references
@ -97,10 +93,10 @@ class StatusMenu: NSObject {
}
func install() {
guard let button = statusItem.button else {
guard let _ = statusItem.button else {
return
}
button.image = imageStatus
setStatusImage(for: .inactive)
VPN.shared.prepare {
self.rebuild()
@ -237,7 +233,7 @@ class StatusMenu: NSObject {
guard let profile = profile else {
itemProfileName.title = L10n.Menu.ActiveProfile.Title.none
// itemProfileName.image = nil
statusItem.button?.image = imageStatusInactive
setStatusImage(for: .inactive)
statusItem.button?.toolTip = nil
return
}
@ -619,22 +615,18 @@ class StatusMenu: NSObject {
switch vpn.status ?? .disconnected {
case .connected:
statusItem.button?.image = imageStatusActive
statusItem.button?.alphaValue = 1.0
setStatusImage(for: .active)
Reviewer.shared.reportEvent()
case .connecting:
statusItem.button?.image = imageStatusInProgress
statusItem.button?.alphaValue = 1.0
setStatusImage(for: .pending)
case .disconnected:
statusItem.button?.image = imageStatusInactive
statusItem.button?.alphaValue = 0.5
setStatusImage(for: .inactive)
case .disconnecting:
statusItem.button?.image = imageStatusInProgress
statusItem.button?.alphaValue = 1.0
setStatusImage(for: .pending)
}
}
}
@ -686,3 +678,29 @@ extension StatusMenu: ConnectionServiceDelegate {
NotificationCenter.default.post(name: StatusMenu.didUpdateProfile, object: profile)
}
}
extension StatusMenu {
fileprivate enum ImageStatus {
case active
case pending
case inactive
}
fileprivate func setStatusImage(for imageStatus: ImageStatus) {
switch imageStatus {
case .active:
statusItem.button?.image = imageStatusActive
statusItem.button?.alphaValue = 1.0
case .pending:
statusItem.button?.image = imageStatusPending
statusItem.button?.alphaValue = 1.0
case .inactive:
statusItem.button?.image = imageStatusActive
statusItem.button?.alphaValue = 0.5
}
}
}