Skip to content

Commit 8fc4d53

Browse files
authored
Merge pull request #47 from igorkulman/feature/argb-support
ARGB support
2 parents 67f3cb0 + cac20a0 commit 8fc4d53

6 files changed

Lines changed: 30 additions & 14 deletions

File tree

Package.resolved

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ let package = Package(
1010
],
1111
dependencies: [
1212
.package(url: "https://github.com/apple/swift-argument-parser", from: "0.3.1"),
13-
.package(url: "https://github.com/thii/SwiftHEXColors.git", from: "1.3.1"),
1413
.package(url: "https://github.com/onevcat/Rainbow", from: "3.0.0"),
1514
.package(url: "https://github.com/JohnSundell/Files", from: "4.0.0")
1615
],
@@ -21,7 +20,6 @@ let package = Package(
2120
name: "ChangeMenuBarColor",
2221
dependencies: [
2322
.product(name: "ArgumentParser", package: "swift-argument-parser"),
24-
.product(name: "SwiftHEXColors", package: "SwiftHEXColors"),
2523
.product(name: "Rainbow", package: "Rainbow"),
2624
.product(name: "Files", package: "Files")
2725
]),

Sources/ChangeMenuBarColor/ChangeMenuBarColor.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import ArgumentParser
99
import Foundation
1010
import Cocoa
11-
import SwiftHEXColors
1211

1312
struct ChangeMenuBarColor: ParsableCommand {
1413
static let configuration = CommandConfiguration(

Sources/ChangeMenuBarColor/Commands/Abstract/Command.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import ArgumentParser
99
import Files
1010
import Foundation
1111
import Cocoa
12-
import SwiftHEXColors
1312

1413
class Command {
1514
func createWallpaper(screen: NSScreen) -> NSImage? {

Sources/ChangeMenuBarColor/Commands/SolidColor.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import ArgumentParser
99
import Foundation
1010
import Cocoa
11-
import SwiftHEXColors
1211

1312
final class SolidColor: Command, ParsableCommand {
1413
static let configuration = CommandConfiguration(
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// File.swift
3+
//
4+
//
5+
// Created by Igor Kulman on 07.02.2021.
6+
//
7+
// adapted from https://stackoverflow.com/a/33397427
8+
9+
import Foundation
10+
import Cocoa
11+
12+
extension NSColor {
13+
convenience init?(hexString: String) {
14+
let hex = hexString.trimmingCharacters(in: CharacterSet.alphanumerics.inverted)
15+
var int = UInt64()
16+
Scanner(string: hex).scanHexInt64(&int)
17+
let a, r, g, b: UInt64
18+
switch hex.count {
19+
case 3: // RGB (12-bit)
20+
(a, r, g, b) = (255, (int >> 8) * 17, (int >> 4 & 0xF) * 17, (int & 0xF) * 17)
21+
case 6: // RGB (24-bit)
22+
(a, r, g, b) = (255, int >> 16, int >> 8 & 0xFF, int & 0xFF)
23+
case 8: // ARGB (32-bit)
24+
(a, r, g, b) = (int >> 24, int >> 16 & 0xFF, int >> 8 & 0xFF, int & 0xFF)
25+
default:
26+
return nil
27+
}
28+
self.init(red: CGFloat(r) / 255, green: CGFloat(g) / 255, blue: CGFloat(b) / 255, alpha: CGFloat(a) / 255)
29+
}
30+
}

0 commit comments

Comments
 (0)