Skip to content

Commit

Permalink
Merge pull request #47 from igorkulman/feature/argb-support
Browse files Browse the repository at this point in the history
ARGB support
  • Loading branch information
igorkulman authored Feb 7, 2021
2 parents 67f3cb0 + cac20a0 commit 8fc4d53
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 14 deletions.
9 changes: 0 additions & 9 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@
"revision": "92646c0cdbaca076c8d3d0207891785b3379cbff",
"version": "0.3.1"
}
},
{
"package": "SwiftHEXColors",
"repositoryURL": "https://github.com/thii/SwiftHEXColors.git",
"state": {
"branch": null,
"revision": "1f886cb20fedda14a5ac75efd09bc99c95b43a18",
"version": "1.4.1"
}
}
]
},
Expand Down
2 changes: 0 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/apple/swift-argument-parser", from: "0.3.1"),
.package(url: "https://github.com/thii/SwiftHEXColors.git", from: "1.3.1"),
.package(url: "https://github.com/onevcat/Rainbow", from: "3.0.0"),
.package(url: "https://github.com/JohnSundell/Files", from: "4.0.0")
],
Expand All @@ -21,7 +20,6 @@ let package = Package(
name: "ChangeMenuBarColor",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "SwiftHEXColors", package: "SwiftHEXColors"),
.product(name: "Rainbow", package: "Rainbow"),
.product(name: "Files", package: "Files")
]),
Expand Down
1 change: 0 additions & 1 deletion Sources/ChangeMenuBarColor/ChangeMenuBarColor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import ArgumentParser
import Foundation
import Cocoa
import SwiftHEXColors

struct ChangeMenuBarColor: ParsableCommand {
static let configuration = CommandConfiguration(
Expand Down
1 change: 0 additions & 1 deletion Sources/ChangeMenuBarColor/Commands/Abstract/Command.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import ArgumentParser
import Files
import Foundation
import Cocoa
import SwiftHEXColors

class Command {
func createWallpaper(screen: NSScreen) -> NSImage? {
Expand Down
1 change: 0 additions & 1 deletion Sources/ChangeMenuBarColor/Commands/SolidColor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import ArgumentParser
import Foundation
import Cocoa
import SwiftHEXColors

final class SolidColor: Command, ParsableCommand {
static let configuration = CommandConfiguration(
Expand Down
30 changes: 30 additions & 0 deletions Sources/ChangeMenuBarColor/Extensions/NSColor+HEX.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// File.swift
//
//
// Created by Igor Kulman on 07.02.2021.
//
// adapted from https://stackoverflow.com/a/33397427

import Foundation
import Cocoa

extension NSColor {
convenience init?(hexString: String) {
let hex = hexString.trimmingCharacters(in: CharacterSet.alphanumerics.inverted)
var int = UInt64()
Scanner(string: hex).scanHexInt64(&int)
let a, r, g, b: UInt64
switch hex.count {
case 3: // RGB (12-bit)
(a, r, g, b) = (255, (int >> 8) * 17, (int >> 4 & 0xF) * 17, (int & 0xF) * 17)
case 6: // RGB (24-bit)
(a, r, g, b) = (255, int >> 16, int >> 8 & 0xFF, int & 0xFF)
case 8: // ARGB (32-bit)
(a, r, g, b) = (int >> 24, int >> 16 & 0xFF, int >> 8 & 0xFF, int & 0xFF)
default:
return nil
}
self.init(red: CGFloat(r) / 255, green: CGFloat(g) / 255, blue: CGFloat(b) / 255, alpha: CGFloat(a) / 255)
}
}

0 comments on commit 8fc4d53

Please sign in to comment.