Skip to content
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
168 changes: 100 additions & 68 deletions wled/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,16 @@
}
}
},
"Device Added" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Device Added"
}
}
}
},
Comment thread
smitty078 marked this conversation as resolved.
"Device List" : {
"comment" : "The title of the device list screen.",
"isCommentAutoGenerated" : true,
Expand Down Expand Up @@ -698,6 +708,57 @@
}
}
},
"Local Network Access Required" : {
"comment" : "Title of the warning banner that appears when the local network permission has been denied.",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Local Network Access Required"
}
},
"fr-CA" : {
"stringUnit" : {
"state" : "translated",
"value" : "Accès au réseau local requis"
}
}
}
},
"local_network_instructions" : {
"comment" : "Step-by-step instructions for enabling local network permission in iOS Settings.",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Go to Settings → WLED → Local Network"
}
},
"fr-CA" : {
"stringUnit" : {
"state" : "translated",
"value" : "Aller dans Réglages → WLED → Réseau local"
}
}
}
},
"local_network_warning_body" : {
"comment" : "Body text of the warning banner explaining why local network access is needed.",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "WLED needs Local Network access to discover and control your devices. Please enable it in Settings."
}
},
"fr-CA" : {
"stringUnit" : {
"state" : "translated",
"value" : "WLED a besoin de l'accès au réseau local pour découvrir et contrôler vos appareils. Veuillez l'activer dans les Réglages."
}
}
}
},
"Mac Address: %@" : {
"comment" : "A label displaying the MAC address of a device.",
"isCommentAutoGenerated" : true,
Expand Down Expand Up @@ -857,6 +918,23 @@
}
}
},
"Open Settings" : {
"comment" : "Button label that opens the app's Settings page so the user can enable Local Network permission.",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Open Settings"
}
},
"fr-CA" : {
"stringUnit" : {
"state" : "translated",
"value" : "Ouvrir les Réglages"
}
}
}
},
"Please do not close the app or turn off the device." : {
"comment" : "Additional instructions to show to the user while a software update is downloading.",
"isCommentAutoGenerated" : true,
Expand Down Expand Up @@ -1422,6 +1500,17 @@
}
}
},
"Use Secure Connections" : {
"comment" : "Toggle switch text for when https/wss should be used",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Use Secure Connections"
}
}
}
},
"Version %@" : {
"comment" : "A label displaying the current version of the app on a device. The argument is the current version of the app on the device.",
"isCommentAutoGenerated" : true,
Expand Down Expand Up @@ -1494,104 +1583,47 @@
}
}
},
"You don't have any visible devices" : {
"comment" : "A label displayed when a user has no visible devices.",
"isCommentAutoGenerated" : true,
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "You don't have any visible devices"
}
},
"fr-CA" : {
"stringUnit" : {
"state" : "translated",
"value" : "Vous n’avez aucun appareil visible"
}
}
}
},
"Your device is up to date" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Your device is up to date"
}
},
"fr-CA" : {
"stringUnit" : {
"state" : "translated",
"value" : "Votre appareil est à jour"
}
}
}
},
"Local Network Access Required" : {
"comment" : "Title of the warning banner that appears when the local network permission has been denied.",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Local Network Access Required"
}
},
"fr-CA" : {
"stringUnit" : {
"state" : "translated",
"value" : "Accès au réseau local requis"
}
}
}
},
"local_network_warning_body" : {
"comment" : "Body text of the warning banner explaining why local network access is needed.",
"WLED only supports HTTPS when accessed through a secure reverse proxy." : {
"comment" : "Hint text displaying warning that WLED itself does not support https, it is for when accessing through a secure reverse proxy.",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "WLED needs Local Network access to discover and control your devices. Please enable it in Settings."
}
},
"fr-CA" : {
"stringUnit" : {
"state" : "translated",
"value" : "WLED a besoin de l'accès au réseau local pour découvrir et contrôler vos appareils. Veuillez l'activer dans les Réglages."
"value" : "WLED only supports HTTPS when accessed through a secure reverse proxy."
}
}
}
},
"local_network_instructions" : {
"comment" : "Step-by-step instructions for enabling local network permission in iOS Settings.",
"You don't have any visible devices" : {
"comment" : "A label displayed when a user has no visible devices.",
"isCommentAutoGenerated" : true,
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Go to Settings → WLED → Local Network"
"value" : "You don't have any visible devices"
}
},
"fr-CA" : {
"stringUnit" : {
"state" : "translated",
"value" : "Aller dans Réglages → WLED → Réseau local"
"value" : "Vous n’avez aucun appareil visible"
}
}
}
},
"Open Settings" : {
"comment" : "Button label that opens the app's Settings page so the user can enable Local Network permission.",
"Your device is up to date" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Open Settings"
"value" : "Your device is up to date"
}
},
"fr-CA" : {
"stringUnit" : {
"state" : "translated",
"value" : "Ouvrir les Réglages"
"value" : "Votre appareil est à jour"
}
}
}
Expand Down
58 changes: 57 additions & 1 deletion wled/Service/DeviceApi/DeviceExtensions.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
import Foundation

enum DeviceAddressNormalizer {
static func normalizedAddress(from address: String, defaultScheme: String = "http") -> String? {
let trimmed = address.trimmingCharacters(in: .whitespacesAndNewlines)
guard !trimmed.isEmpty else { return nil }

let lowercasedAddress = trimmed.lowercased()
let rawAddress: String

if lowercasedAddress.hasPrefix("http://") || lowercasedAddress.hasPrefix("https://") {
rawAddress = trimmed
} else if trimmed.contains("://") {
return nil
} else {
rawAddress = "\(defaultScheme)://\(trimmed)"
}

guard var components = URLComponents(string: rawAddress),
let scheme = components.scheme?.lowercased(),
scheme == "http" || scheme == "https",
components.host?.isEmpty == false else {
return nil
}

components.user = nil
components.password = nil
components.path = ""
components.query = nil
components.fragment = nil
components.scheme = scheme

return components.url?.absoluteString.trimmingCharacters(in: CharacterSet(charactersIn: "/"))
}
}

extension Device {
var displayName: String {
if let name = customName, !name.isEmpty {
Expand All @@ -11,6 +45,28 @@ extension Device {
return String(localized: "(New Device)")
}

var url: URL? {
guard let address = address?.trimmingCharacters(in: .whitespacesAndNewlines),
!address.isEmpty else {
return nil
}
return URL(string: address)
}

var webSocketURL: URL? {
guard let url = url,
var components = URLComponents(url: url, resolvingAgainstBaseURL: false) else {
return nil
}

components.scheme = components.scheme?.lowercased() == "https" ? "wss" : "ws"
components.path = "/ws"
components.query = nil
components.fragment = nil

return components.url
}

func getColor(state: WledState?) -> Int64 {
guard let state = state,
let colorInfo = state.segment?.first?.colors?.first,
Expand All @@ -19,7 +75,7 @@ extension Device {
// Return neutral Gray if any data is missing
return 0x808080
}

let red = Int64(Double(colorInfo[0]) + 0.5)
let green = Int64(Double(colorInfo[1]) + 0.5)
let blue = Int64(Double(colorInfo[2]) + 0.5)
Expand Down
Loading