mirror of
https://github.com/swiftbar/SwiftBar.git
synced 2024-09-11 16:05:33 +03:00
Add weight and scale options to SF Configuration
Signed-off-by: Alex Mazanov <alexandr.mazanov@gmail.com>
This commit is contained in:
parent
601a862f72
commit
fdecdf9adc
@ -521,8 +521,9 @@
|
||||
3920747225460FD000213DBE /* Project object */ = {
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
BuildIndependentTargetsInParallel = YES;
|
||||
LastSwiftUpdateCheck = 1200;
|
||||
LastUpgradeCheck = 1410;
|
||||
LastUpgradeCheck = 1500;
|
||||
TargetAttributes = {
|
||||
3920747925460FD000213DBE = {
|
||||
CreatedOnToolsVersion = 12.0.1;
|
||||
@ -698,7 +699,7 @@
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "if which swiftformat >/dev/null; then\n swiftformat .\nelse\n echo \"warning: SwiftFormat not installed, download from https://github.com/nicklockwood/SwiftFormat\"\nfi\n";
|
||||
shellScript = "if which swiftformat >/dev/null; then\n swiftformat --swiftversion 5.9 .\nelse\n echo \"warning: SwiftFormat not installed, download from https://github.com/nicklockwood/SwiftFormat\"\nfi\n";
|
||||
};
|
||||
FAD14BF62583256A00CB7BBE /* Codesign Sparkle */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
@ -907,6 +908,7 @@
|
||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
ENABLE_TESTABILITY = YES;
|
||||
ENABLE_USER_SCRIPT_SANDBOXING = NO;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu11;
|
||||
GCC_DYNAMIC_NO_PIC = NO;
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
@ -970,6 +972,7 @@
|
||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||
ENABLE_NS_ASSERTIONS = NO;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
ENABLE_USER_SCRIPT_SANDBOXING = NO;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu11;
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
|
@ -57,18 +57,78 @@ struct MenuLineParameters: Codable {
|
||||
return params
|
||||
}
|
||||
|
||||
struct SFMulticolor: Codable {
|
||||
struct SFConfig: Codable {
|
||||
enum RenderingMode: String, Codable {
|
||||
case Hierarchical
|
||||
case Palette
|
||||
}
|
||||
|
||||
enum Scale: String, Codable {
|
||||
case small
|
||||
case medium
|
||||
case large
|
||||
}
|
||||
|
||||
enum Weight: String, Codable {
|
||||
case ultralight
|
||||
case thin
|
||||
case light
|
||||
case regular
|
||||
case medium
|
||||
case semibold
|
||||
case bold
|
||||
case heavy
|
||||
case black
|
||||
}
|
||||
|
||||
var renderingMode: RenderingMode
|
||||
var colors: [String]
|
||||
var scale: Scale?
|
||||
var weight: Weight?
|
||||
|
||||
func getColors() -> [NSColor] {
|
||||
colors.compactMap { NSColor.webColor(from: $0) }
|
||||
}
|
||||
|
||||
@available(macOS 11.0, *)
|
||||
func getScale() -> NSImage.SymbolScale {
|
||||
switch scale {
|
||||
case .small:
|
||||
.small
|
||||
case .medium:
|
||||
.medium
|
||||
case .large:
|
||||
.large
|
||||
case .none:
|
||||
.large
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 11.0, *)
|
||||
func getWeight() -> NSFont.Weight {
|
||||
switch weight {
|
||||
case .ultralight:
|
||||
.ultraLight
|
||||
case .thin:
|
||||
.thin
|
||||
case .light:
|
||||
.light
|
||||
case .regular:
|
||||
.regular
|
||||
case .medium:
|
||||
.medium
|
||||
case .semibold:
|
||||
.semibold
|
||||
case .bold:
|
||||
.bold
|
||||
case .heavy:
|
||||
.heavy
|
||||
case .black:
|
||||
.black
|
||||
case .none:
|
||||
.regular
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var href: String? {
|
||||
@ -165,10 +225,10 @@ struct MenuLineParameters: Codable {
|
||||
params["alternate"]?.lowercased() == "true"
|
||||
}
|
||||
|
||||
func getSFMulticolor() -> SFMulticolor? {
|
||||
guard let base64 = params["sfmulticolor"]?.data(using: .utf8),
|
||||
func getSFConfig() -> SFConfig? {
|
||||
guard let base64 = params["sfconfig"]?.data(using: .utf8),
|
||||
let decodedData = Data(base64Encoded: base64),
|
||||
case let sfmc = try? JSONDecoder().decode(SFMulticolor.self, from: decodedData)
|
||||
case let sfmc = try? JSONDecoder().decode(SFConfig.self, from: decodedData)
|
||||
else { return nil }
|
||||
return sfmc
|
||||
}
|
||||
@ -176,14 +236,16 @@ struct MenuLineParameters: Codable {
|
||||
var image: NSImage? {
|
||||
if #available(OSX 11.0, *) {
|
||||
if let sfString = params["sfimage"] {
|
||||
var config = NSImage.SymbolConfiguration(scale: .medium)
|
||||
if #available(OSX 12.0, *), let sfmc = getSFMulticolor() {
|
||||
let sfmc = getSFConfig()
|
||||
var config = NSImage.SymbolConfiguration(scale: .large)
|
||||
if #available(OSX 12.0, *), let sfmc = sfmc {
|
||||
switch sfmc.renderingMode {
|
||||
case .Hierarchical:
|
||||
config = config.applying(NSImage.SymbolConfiguration(hierarchicalColor: sfmc.getColors().first ?? NSColor(Color.primary)))
|
||||
case .Palette:
|
||||
config = config.applying(NSImage.SymbolConfiguration(paletteColors: sfmc.getColors()))
|
||||
}
|
||||
config = config.applying(NSImage.SymbolConfiguration(pointSize: 0, weight: sfmc.getWeight(), scale: sfmc.getScale()))
|
||||
}
|
||||
|
||||
let image = NSImage(systemSymbolName: sfString, accessibilityDescription: nil)?.withSymbolConfiguration(config)
|
||||
|
Loading…
Reference in New Issue
Block a user