Skip to content

OSX: Add MenuBar support #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
392 changes: 374 additions & 18 deletions wled-native.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1600"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E15C19CD2CA1CABD00431441"
BuildableName = "wled-native-osx.app"
BlueprintName = "wled-native-osx"
ReferencedContainer = "container:wled-native.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E15C19CD2CA1CABD00431441"
BuildableName = "wled-native-osx.app"
BlueprintName = "wled-native-osx"
ReferencedContainer = "container:wled-native.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E15C19CD2CA1CABD00431441"
BuildableName = "wled-native-osx.app"
BlueprintName = "wled-native-osx"
ReferencedContainer = "container:wled-native.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
12 changes: 0 additions & 12 deletions wled-native/Model/Branch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,3 @@ enum Branch: String {
case beta = "beta"
case stable = "stable"
}

extension Device {
var branchValue: Branch {
get {
guard let branch = self.branch else { return .unknown }
return Branch(rawValue: String(branch)) ?? .unknown
}
set {
self.branch = String(newValue.rawValue)
}
}
}
74 changes: 74 additions & 0 deletions wled-native/Model/Device.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//
// Device.swift
// wled-native
//
// Created by Robert Brune on 20.03.25.
//

import Foundation
import SwiftUI

extension Device {


var displayName: String {
let emptyName = String(localized: "(New Device)")
guard let name = self.name else {
return emptyName
}
return name.isEmpty ? emptyName : name
}

var updateAvailable: Bool {
return false
/*
self.managedObjectContext?.performAndWait {
return !(self.latestUpdateVersionTagAvailable ?? "").isEmpty
} ?? false
*/
}

func displayColor(colorScheme: ColorScheme) -> Color {
colorFromHex(colorScheme: colorScheme)
}

func colorFromHex(colorScheme: ColorScheme) -> Color {
// & binary AND operator to zero out other color values
// >> bitwise right shift operator
// Divide by 0xFF because UIColor takes CGFloats between 0.0 and 1.0

let rgbValue = Int(self.color)

let red = CGFloat((rgbValue & 0xFF0000) >> 16) / 0xFF
let green = CGFloat((rgbValue & 0x00FF00) >> 8) / 0xFF
let blue = CGFloat(rgbValue & 0x0000FF) / 0xFF
let alpha = CGFloat(1.0)
// TODO: Fix Colors also for XOS
#if os(iOS)
return fixColor(colorScheme: colorScheme, color: UIColor(red: red, green: green, blue: blue, alpha: alpha))
#else
return Color(red: red, green: green, blue: blue, opacity: alpha)
#endif
}
#if os(iOS)
// Fixes the color if it is too dark or too bright depending of the dark/light theme
func fixColor(colorScheme: ColorScheme, color: UIColor) -> Color {
var h = CGFloat(0), s = CGFloat(0), b = CGFloat(0), a = CGFloat(0)
color.getHue(&h, saturation: &s, brightness: &b, alpha: &a)
b = colorScheme == .dark ? fmax(b, 0.2) : fmin(b, 0.75)
return Color(UIColor(hue: h, saturation: s, brightness: b, alpha: a))
}
#endif
}

extension Device {
var branchValue: Branch {
get {
guard let branch = self.branch else { return .unknown }
return Branch(rawValue: String(branch)) ?? .unknown
}
set {
self.branch = String(newValue.rawValue)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

import Foundation
import CoreData

struct WLEDChangeStateRequest: WLEDRequest {
let state: WLEDStateChange
let context: NSManagedObjectContext
}
5 changes: 1 addition & 4 deletions wled-native/Model/DeviceApi/Request/WLEDRefreshRequest.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@

import Foundation
import CoreData

struct WLEDRefreshRequest: WLEDRequest {
let context: NSManagedObjectContext
}
struct WLEDRefreshRequest: WLEDRequest { }
4 changes: 1 addition & 3 deletions wled-native/Model/DeviceApi/Request/WLEDRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@
import Foundation
import CoreData

protocol WLEDRequest {
var context: NSManagedObjectContext { get }
}
protocol WLEDRequest: Sendable { }
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@

import Foundation
import CoreData

struct WLEDSoftwareUpdateRequest: WLEDRequest {
let context: NSManagedObjectContext
let binaryFile: URL
let onCompletion: () -> ()
let onFailure: () -> ()
let onCompletion: @MainActor () -> ()
let onFailure: @MainActor () -> ()
}
2 changes: 1 addition & 1 deletion wled-native/Persistence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import CoreData
struct PersistenceController {
static let shared = PersistenceController()

static var preview: PersistenceController = {
static let preview: PersistenceController = {
let result = PersistenceController(inMemory: true)
let viewContext = result.container.viewContext
for i in 0..<10 {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
13 changes: 8 additions & 5 deletions wled-native/Service/DeviceApi/DeviceExtensions.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@

import Foundation

extension Device {
var requestManager: WLEDRequestManager {
get {
return DeviceStateFactory.shared.getStateForDevice(self).getRequestManager(device: self)
}
extension Device: @unchecked Sendable {

func refresh() async {
await self.getRequestManager().addRequest(WLEDRefreshRequest())
}

func getRequestManager() async -> WLEDRequestManager {
await WLEDRequestManagerProvider.shared.getRequestManager(device: self)
}

func getColor(state: WledState) -> Int64 {
Expand Down
Loading