Skip to content

Commit

Permalink
[iOS] Admin Dashboard - Active Devices Icons (#1275)
Browse files Browse the repository at this point in the history
* Add Device images & Reference using the Enum as a filler if the NowPlayingItem is Nil

* Localize DeviceTypes.DisplayTitles

* Review changes. Last potential TODO: Image: ImageResource might not be the correct format

* DeviceType is needed to build tvOS

* Mirror Jellyfin-Blue-Blob for SVG configuration. Use ImageResource for the Device/Client Images

* Merge missing }

* Don't recreate the ImageResource since it's already generated.

* New webOS logo! Fix tvOS not having the new logos

* use if let, implicit self

* use secondary system fill for other

---------

Co-authored-by: Ethan Pippin <ethanpippin2343@gmail.com>
  • Loading branch information
JPKribs and LePips authored Oct 16, 2024
1 parent 0148e46 commit 50e0cfe
Show file tree
Hide file tree
Showing 48 changed files with 724 additions and 19 deletions.
276 changes: 276 additions & 0 deletions Shared/Extensions/JellyfinAPI/DeviceType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,276 @@
//
// Swiftfin is subject to the terms of the Mozilla Public
// License, v2.0. If a copy of the MPL was not distributed with this
// file, you can obtain one at https://mozilla.org/MPL/2.0/.
//
// Copyright (c) 2024 Jellyfin & Jellyfin Contributors
//

import SwiftUI

enum DeviceType: String, Displayable, Codable, CaseIterable {
case android
case apple
case chrome
case edge
case edgechromium
case finamp
case firefox
case homeAssistant
case html5
case kodi
case msie
case opera
case playstation
case roku
case safari
case samsungtv
case webos
case windows
case xbox
case other

// MARK: - Display Title

var displayTitle: String {
switch self {
case .android:
return "Android"
case .apple:
return "Apple"
case .chrome:
return "Chrome"
case .edge:
return "Edge"
case .edgechromium:
return "Edge Chromium"
case .finamp:
return "Finamp"
case .firefox:
return "Firefox"
case .homeAssistant:
return "Home Assistant"
case .html5:
return "HTML5"
case .kodi:
return "Kodi"
case .msie:
return "Internet Explorer"
case .opera:
return "Opera"
case .playstation:
return "PlayStation"
case .roku:
return "Roku"
case .safari:
return "Safari"
case .samsungtv:
return "Samsung TV"
case .webos:
return "WebOS"
case .windows:
return "Windows"
case .xbox:
return "Xbox"
case .other:
return "Other"
}
}

// MARK: - Initialize the Client

init(client: String?, deviceName: String?) {
guard let client = client?.lowercased() else {
self = .other
return
}

switch client {

/* Android or Findroid */
case let str where str.range(of: #"android|findroid"#, options: .regularExpression) != nil:
self = .android

/* Apple devices: iOS, tvOS, iPadOS, Swiftfin, or Infuse */
case let str where str.range(of: #"ios|tvos|ipados|swiftfin|infuse"#, options: .regularExpression) != nil:
self = .apple

/* Finamp */
case let str where str.range(of: #"finamp"#, options: .regularExpression) != nil:
self = .finamp

/* Home Assistant or HomeAssistant */
case let str where str.range(of: #"home.assistant|homeassistant"#, options: .regularExpression) != nil:
self = .homeAssistant

/* Jellyfin Web or JellyfinWeb (Vue versions included) */
case let str where str.range(of: #"jellyfin.web|jellyfinweb"#, options: .regularExpression) != nil:
self = DeviceType(webBrowser: deviceName)

/* Kodi or JellyCon */
case let str where str.range(of: #"kodi|jellycon"#, options: .regularExpression) != nil:
self = .kodi

/* LG TV, LG Smart TV, or WebOS devices */
case let str where str.range(of: #"lg.+tv|webos"#, options: .regularExpression) != nil:
self = .webos

/* PlayStation: Sony PS3, PS4, or any PlayStation */
case let str where str.range(of: #"sony\sps[3-4]|playstation"#, options: .regularExpression) != nil:
self = .playstation

/* Roku devices */
case let str where str.range(of: #"roku"#, options: .regularExpression) != nil:
self = .roku

/* Samsung TV, Samsung Smart TV, or devices running Tizen */
case let str where str.range(of: #"samsung.+tv|tizen"#, options: .regularExpression) != nil:
self = .samsungtv

/* Xbox One or any Xbox device */
case let str where str.range(of: #"xbox"#, options: .regularExpression) != nil:
self = .xbox

/* Default case for anything else */
default:
self = .other
}
}

// MARK: - Initialize the Browser if Jellyfin-Web

private init(webBrowser: String?) {
guard let webBrowser = webBrowser?.lowercased() else {
self = .html5
return
}

switch webBrowser {

/* Matches any string containing 'chrome' */
case let str where str.range(of: #"chrome"#, options: .regularExpression) != nil:
self = .chrome

/* Matches any string containing 'edge chromium' or 'edgechromium' */
case let str where str.range(of: #"edge.chromium|edgechromium"#, options: .regularExpression) != nil:
self = .edgechromium

/* Matches any string containing 'edge' but not 'chromium' */
case let str
where str.range(of: #"edge"#, options: .regularExpression) != nil && str
.range(of: #"chromium"#, options: .regularExpression) == nil:
self = .edge

/* Matches any string containing 'firefox' */
case let str where str.range(of: #"firefox"#, options: .regularExpression) != nil:
self = .firefox

/* Matches any string containing 'internet explorer', 'IE', 'MSIE', or 'MSFT IE' */
case let str
where str.range(of: #"internet.explorer|internetexplorer|ie\d|ie.\d|msie|msft.ie"#, options: .regularExpression) != nil:
self = .msie

/* Matches any string containing 'opera' */
case let str where str.range(of: #"opera"#, options: .regularExpression) != nil:
self = .opera

/* Matches any string containing 'safari' */
case let str where str.range(of: #"safari"#, options: .regularExpression) != nil:
self = .safari

/* Default case for anything else */
default:
self = .html5
}
}

// MARK: - Client Image

var image: ImageResource {
switch self {
case .android:
return .deviceClientAndroid
case .apple:
return .deviceClientApple
case .chrome:
return .deviceBrowserChrome
case .edge:
return .deviceBrowserEdge
case .edgechromium:
return .deviceBrowserEdgechromium
case .finamp:
return .deviceClientFinamp
case .firefox:
return .deviceBrowserFirefox
case .homeAssistant:
return .deviceOtherHomeassistant
case .html5:
return .deviceBrowserHtml5
case .kodi:
return .deviceClientKodi
case .msie:
return .deviceBrowserMsie
case .opera:
return .deviceBrowserOpera
case .playstation:
return .deviceClientPlaystation
case .roku:
return .deviceClientRoku
case .safari:
return .deviceBrowserSafari
case .samsungtv:
return .deviceClientSamsungtv
case .webos:
return .deviceClientWebos
case .windows:
return .deviceClientWindows
case .xbox:
return .deviceClientXbox
case .other:
return .deviceOtherOther
}
}

// MARK: - Client Color

var clientColor: Color {
switch self {
case .android:
return Color(red: 0.18, green: 0.8, blue: 0.44) // Android Green
case .apple:
return Color(red: 0.35, green: 0.35, blue: 0.35) // Apple Gray
case .chrome:
return Color(red: 0.98, green: 0.75, blue: 0.18) // Chrome Yellow
case .edge:
return Color(red: 0.19, green: 0.31, blue: 0.51) // Edge Gray
case .edgechromium:
return Color(red: 0.0, green: 0.45, blue: 0.75) // Edge Chromium Blue
case .firefox:
return Color(red: 1.0, green: 0.33, blue: 0.0) // Firefox Orange
case .finamp:
return Color(red: 0.61, green: 0.32, blue: 0.88) // Finamp Purple
case .homeAssistant:
return Color(red: 0.0, green: 0.55, blue: 0.87) // Home Assistant Blue
case .kodi:
return Color(red: 0.0, green: 0.58, blue: 0.83) // Kodi Blue
case .msie:
return Color(red: 0.0, green: 0.53, blue: 1.0) // Internet Explorer Blue
case .opera:
return Color(red: 1.0, green: 0.0, blue: 0.0) // Opera Red
case .playstation:
return Color(red: 0.0, green: 0.32, blue: 0.65) // PlayStation Blue
case .roku:
return Color(red: 0.31, green: 0.09, blue: 0.55) // Roku Purple
case .safari:
return Color(red: 0.0, green: 0.48, blue: 1.0) // Safari Blue
case .samsungtv:
return Color(red: 0.0, green: 0.44, blue: 0.74) // Samsung Blue
case .webos:
return Color(red: 0.6667, green: 0.1569, blue: 0.2745) // WebOS Pink
case .xbox:
return Color(red: 0.0, green: 0.5, blue: 0.0) // Xbox Green
default:
return Color.secondarySystemFill
}
}
}
7 changes: 7 additions & 0 deletions Shared/Extensions/JellyfinAPI/SessionInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ import JellyfinAPI

extension SessionInfo {

var device: DeviceType {
DeviceType(
client: client,
deviceName: deviceName
)
}

var playMethodDisplayTitle: String? {
guard nowPlayingItem != nil, let playState, let playMethod = playState.playMethod else { return nil }

Expand Down
14 changes: 14 additions & 0 deletions Swiftfin.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
/* Begin PBXBuildFile section */
091B5A8A2683142E00D78B61 /* ServerDiscovery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 091B5A872683142E00D78B61 /* ServerDiscovery.swift */; };
091B5A8D268315D400D78B61 /* ServerDiscovery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 091B5A872683142E00D78B61 /* ServerDiscovery.swift */; };
4E0253BD2CBF0C06007EB9CD /* DeviceType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E12F9152CBE9615006C217E /* DeviceType.swift */; };
4E0A8FFB2CAF74D20014B047 /* TaskCompletionStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E0A8FFA2CAF74CD0014B047 /* TaskCompletionStatus.swift */; };
4E0A8FFC2CAF74D20014B047 /* TaskCompletionStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E0A8FFA2CAF74CD0014B047 /* TaskCompletionStatus.swift */; };
4E11805F2CBF52380077A588 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5377CBF8263B596B003A4E83 /* Assets.xcassets */; };
4E12F9172CBE9619006C217E /* DeviceType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E12F9152CBE9615006C217E /* DeviceType.swift */; };
4E16FD512C0183DB00110147 /* LetterPickerButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E16FD502C0183DB00110147 /* LetterPickerButton.swift */; };
4E16FD532C01840C00110147 /* LetterPickerBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E16FD522C01840C00110147 /* LetterPickerBar.swift */; };
4E16FD572C01A32700110147 /* LetterPickerOrientation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E16FD562C01A32700110147 /* LetterPickerOrientation.swift */; };
Expand Down Expand Up @@ -57,6 +60,8 @@
4EB1A8CA2C9A766200F43898 /* ActiveSessionsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EB1A8C92C9A765800F43898 /* ActiveSessionsView.swift */; };
4EB1A8CC2C9B1BA200F43898 /* ServerTaskButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EB1A8CB2C9B1B9700F43898 /* ServerTaskButton.swift */; };
4EB1A8CE2C9B2D0800F43898 /* ActiveSessionRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EB1A8CD2C9B2D0100F43898 /* ActiveSessionRow.swift */; };
4EB4ECE32CBEFC4D002FF2FC /* SessionInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EB4ECE22CBEFC49002FF2FC /* SessionInfo.swift */; };
4EB4ECE42CBEFC4D002FF2FC /* SessionInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EB4ECE22CBEFC49002FF2FC /* SessionInfo.swift */; };
4EB7B33B2CBDE645004A342E /* ChevronAlertButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EB7B33A2CBDE63F004A342E /* ChevronAlertButton.swift */; };
4EBE06462C7E9509004A6C03 /* PlaybackCompatibility.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EBE06452C7E9509004A6C03 /* PlaybackCompatibility.swift */; };
4EBE06472C7E9509004A6C03 /* PlaybackCompatibility.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EBE06452C7E9509004A6C03 /* PlaybackCompatibility.swift */; };
Expand Down Expand Up @@ -1023,6 +1028,7 @@
/* Begin PBXFileReference section */
091B5A872683142E00D78B61 /* ServerDiscovery.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ServerDiscovery.swift; sourceTree = "<group>"; };
4E0A8FFA2CAF74CD0014B047 /* TaskCompletionStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaskCompletionStatus.swift; sourceTree = "<group>"; };
4E12F9152CBE9615006C217E /* DeviceType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceType.swift; sourceTree = "<group>"; };
4E16FD502C0183DB00110147 /* LetterPickerButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LetterPickerButton.swift; sourceTree = "<group>"; };
4E16FD522C01840C00110147 /* LetterPickerBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LetterPickerBar.swift; sourceTree = "<group>"; };
4E16FD562C01A32700110147 /* LetterPickerOrientation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LetterPickerOrientation.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1057,6 +1063,7 @@
4EB1A8C92C9A765800F43898 /* ActiveSessionsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActiveSessionsView.swift; sourceTree = "<group>"; };
4EB1A8CB2C9B1B9700F43898 /* ServerTaskButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerTaskButton.swift; sourceTree = "<group>"; };
4EB1A8CD2C9B2D0100F43898 /* ActiveSessionRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActiveSessionRow.swift; sourceTree = "<group>"; };
4EB4ECE22CBEFC49002FF2FC /* SessionInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionInfo.swift; sourceTree = "<group>"; };
4EB7B33A2CBDE63F004A342E /* ChevronAlertButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChevronAlertButton.swift; sourceTree = "<group>"; };
4EBE06452C7E9509004A6C03 /* PlaybackCompatibility.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaybackCompatibility.swift; sourceTree = "<group>"; };
4EBE064C2C7EB6D3004A6C03 /* VideoPlayerType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoPlayerType.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3569,6 +3576,8 @@
E1ED7FDA2CAA4B6D00ACB6E3 /* PlayerStateInfo.swift */,
E1CB758A2C80F9EC00217C76 /* CodecProfile.swift */,
4EBE06502C7ED0E1004A6C03 /* DeviceProfile.swift */,
4E12F9152CBE9615006C217E /* DeviceType.swift */,
4EB4ECE22CBEFC49002FF2FC /* SessionInfo.swift */,
4E0A8FFA2CAF74CD0014B047 /* TaskCompletionStatus.swift */,
E1CB75712C80E71800217C76 /* DirectPlayProfile.swift */,
E1722DB029491C3900CC0239 /* ImageBlurHashes.swift */,
Expand Down Expand Up @@ -4157,6 +4166,7 @@
53913BF026D323FE00EB3286 /* Localizable.strings in Resources */,
53913C0826D323FE00EB3286 /* Localizable.strings in Resources */,
53913C1126D323FE00EB3286 /* Localizable.strings in Resources */,
4E11805F2CBF52380077A588 /* Assets.xcassets in Resources */,
535870672669D21700D05A09 /* Assets.xcassets in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -4279,6 +4289,7 @@
E1B490452967E26300D3EDCE /* PersistentLogHandler.swift in Sources */,
E193D53327193F7D00900D82 /* FilterCoordinator.swift in Sources */,
E18E021E2887492B0022598C /* RowDivider.swift in Sources */,
4EB4ECE42CBEFC4D002FF2FC /* SessionInfo.swift in Sources */,
E1DC983E296DEB9B00982F06 /* UnwatchedIndicator.swift in Sources */,
4E2AC4BF2C6C48D200DD600D /* CustomDeviceProfileAction.swift in Sources */,
4EBE06472C7E9509004A6C03 /* PlaybackCompatibility.swift in Sources */,
Expand Down Expand Up @@ -4450,6 +4461,7 @@
E1575E6C293E77B5001665B1 /* SliderType.swift in Sources */,
E1E2F8402B757DFA00B75998 /* OnFinalDisappearModifier.swift in Sources */,
E17DC74B2BE740D900B42379 /* StoredValues+Server.swift in Sources */,
4E0253BD2CBF0C06007EB9CD /* DeviceType.swift in Sources */,
E10E842A29A587110064EA49 /* LoadingView.swift in Sources */,
E193D53927193F8E00900D82 /* SearchCoordinator.swift in Sources */,
E13316FF2ADE42B6009BF865 /* OnSizeChangedModifier.swift in Sources */,
Expand Down Expand Up @@ -4678,6 +4690,7 @@
621338932660107500A81A2A /* String.swift in Sources */,
E17AC96F2954EE4B003D2BC2 /* DownloadListViewModel.swift in Sources */,
BD39577C2C113FAA0078CEF8 /* TimestampSection.swift in Sources */,
4EB4ECE32CBEFC4D002FF2FC /* SessionInfo.swift in Sources */,
4EC6C16B2C92999800FC904B /* TranscodeSection.swift in Sources */,
62C83B08288C6A630004ED0C /* FontPickerView.swift in Sources */,
E122A9132788EAAD0060FA63 /* MediaStream.swift in Sources */,
Expand Down Expand Up @@ -5040,6 +5053,7 @@
E10B1EB62BD98C6600A92EAF /* AddUserRow.swift in Sources */,
E1CB75802C80F28F00217C76 /* SubtitleProfile.swift in Sources */,
E1DD20412BE1EB8C00C0DE51 /* AddUserButton.swift in Sources */,
4E12F9172CBE9619006C217E /* DeviceType.swift in Sources */,
E145EB422BE0A6EE003BF6F3 /* ServerSelectionMenu.swift in Sources */,
4E5E48E52AB59806003F1B48 /* CustomizeViewsSettings.swift in Sources */,
E14EA15E2BF6F72900DE757A /* PhotoPicker.swift in Sources */,
Expand Down
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,15 @@
{
"images" : [
{
"filename" : "chrome.svg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true
}
}
Loading

0 comments on commit 50e0cfe

Please sign in to comment.