Skip to content
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

Add UI for OSX #15

Closed
wants to merge 2 commits into from
Closed
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
Binary file added ExampleImages/Example-01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,28 @@ This project is not an official Google project. It is not supported by
Google and Google specifically disclaims all warranties as to its quality,
merchantability, or fitness for a particular purpose.

# WLED–OSX

An MacOS menu bar to control [WLED](https://github.com/Aircoookie/WLED).

## Features

- Power on / off controll
- Brightness controll
- Selection of defined presed
- Automatic device detection in local network

![](./ExampleImages/Example-01.png)

## Ideas / To Implement

- [ ] Set timer / sunrise …
- [ ] Open website for detailed configuration
- [ ] Open link to WLED-documentation
- [ ] Manage devices, store devices, rename devices
- [ ] Refresh devices
- [ ] Improve button position

## Thanks

To [Christophe Gagnier](https://github.com/Moustachauve) ([WLED-Native-iOS](https://github.com/Moustachauve/WLED-Native-iOS)) for inspiration and showing how networking can be done for WLED in Swift.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions wled-native-ios/wled-native-ios.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# wled native ios

This directory should only contain files used by the wled native iOS app.

15 changes: 15 additions & 0 deletions wled-native-macOS/API-Extensions/String.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// String.swift
// wled-native-macOS
//
// Created by Robert Brune on 01.12.23.
//

import Foundation
import WledLib

extension String: WledHost {
public var hostname: String {
return self
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions wled-native-macOS/Assets.xcassets/012_rip.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "012_rip.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"images" : [
{
"filename" : "mac-16x16.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "16x16"
},
{
"filename" : "[email protected]",
"idiom" : "mac",
"scale" : "2x",
"size" : "16x16"
},
{
"filename" : "mac-32x32.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "32x32"
},
{
"filename" : "[email protected]",
"idiom" : "mac",
"scale" : "2x",
"size" : "32x32"
},
{
"filename" : "mac-128x128.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "128x128"
},
{
"filename" : "[email protected]",
"idiom" : "mac",
"scale" : "2x",
"size" : "128x128"
},
{
"filename" : "mac-256x256.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "256x256"
},
{
"filename" : "[email protected]",
"idiom" : "mac",
"scale" : "2x",
"size" : "256x256"
},
{
"filename" : "mac-512x512.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "512x512"
},
{
"filename" : "[email protected]",
"idiom" : "mac",
"scale" : "2x",
"size" : "512x512"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions wled-native-macOS/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "wled_logo_akemi.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions wled-native-macOS/Documentation.docc/Collections/Model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Model WLED strips

The data model representing the WLED strips.

## Topics

### Device Collection

- ``DeviceCollection``

### Device

- ``DeviceActor``
- ``DeviceIdentifier``

### Error

- ``DeviceError``

### Extensions

- ``Swift/String``
19 changes: 19 additions & 0 deletions wled-native-macOS/Documentation.docc/Collections/View.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# View

The Views of the macOS application.

## Overview

## Topics

### Main

- ``WLEDNativeBar``

### Content
- ``ContentView``
- ``DeviceView``

### Extensions
- ``AppKit/NSImage``
- ``DeveloperToolsSupport/ImageResource``
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# View Protocols

Protocols defining the data interface for the views.

## Topics

- ``CollectionProvider``
- ``DeviceProvider``
24 changes: 24 additions & 0 deletions wled-native-macOS/Documentation.docc/Documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# ``wled native macOS``

Menu bar for macOS to interact with WLED strips.

## Topics

### Model

The data model of the application.

- <doc:Model>

### View Protocols

The interface for the data model for the View.

- <doc:ViewProtocols>

### View

The views of the applications.

- <doc:View>

100 changes: 100 additions & 0 deletions wled-native-macOS/Model/DeviceActor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
//
// Device-Actor.swift
// wled-native-macOS
//
// Created by Robert Brune on 21.11.23.
//

import Foundation
import CoreData
import OSLog
import Combine
import WledLib

actor DeviceActor:Identifiable, ObservableObject {

let id:UUID

@MainActor let identifier:DeviceIdentifier
@MainActor private var webSocketTask: URLSessionWebSocketTask? = nil

@MainActor @Published var ds:Device? = nil
@MainActor @Published var presets:Presets? = nil


@MainActor
init(device: DeviceIdentifier) {
self.id = UUID()
self.identifier = device

createWebSocket()
fetchPresets()
}

nonisolated func createWebSocket() {
DispatchQueue.main.async {
do {
self.webSocketTask = try self.address.getWebsocketReceiver(
handleData: self.receiveData(stateData:),
handleError: self.error(error:)
)
} catch {
Logger().error("\(error.localizedDescription)")
}
}
}

nonisolated func fetchPresets() {
do {
try identifier.address.get { data in
DispatchQueue.main.async {
self.presets = data
Logger().log("Presets loaded: \(String(reflecting: data))")
}
}
handleError: { error in
self.error(error: error)
}
} catch {
self.error(error: error)
}
}

nonisolated func post(state: State) {
do {
try identifier.address.send(data: state) { (message: SuccessMessage) in
guard message.success else {
self.error(error: DeviceError.invalidUpdate)
return
}
Logger().info("Update successful.")
}
handleError: { error in
self.error(error: error)
}
} catch {
self.error(error: error)
}
}


nonisolated func error(error: Error) {
Logger().error("Device Error: \(error.localizedDescription)")
DispatchQueue.main.async {
self.ds = nil
self.webSocketTask?.cancel()
self.createWebSocket()
}
}

nonisolated func receiveData(stateData: Device) {
Logger().debug("Data receive: \(String(reflecting: stateData))")
DispatchQueue.main.async {
self.ds = stateData
}
}
}

enum DeviceError : Error {
case invalidUpdate
}
Loading