Compare commits
25 Commits
ac4c22c2fb
...
3.2
| Author | SHA1 | Date | |
|---|---|---|---|
| 1c9916c69d | |||
| cfd023be69 | |||
| 719359b940 | |||
| f4d0bd7ca0 | |||
| 26a13c27d6 | |||
| cfe5063828 | |||
| 69742ce2d9 | |||
| 5b3787f19f | |||
| 9b0f6e2123 | |||
| 2d4eae9676 | |||
| 848c4c2b55 | |||
| a6ca763730 | |||
| 0916de60f3 | |||
| cfc6e6c411 | |||
| bc54735d1f | |||
| 04d23bec1e | |||
| 3aa819eccc | |||
| 718518c3f2 | |||
| f3053c1db1 | |||
| 58a43a617e | |||
| 85fd112a1a | |||
| 8ac494049d | |||
| 4e3bcb406a | |||
| ec1ee508b3 | |||
| 4e8cd11d8f |
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
/.env
|
||||
ios/build/
|
||||
fastlane/report.xml
|
||||
fastlane/Preview.html
|
||||
fastlane/screenshots/
|
||||
fastlane/test_output/
|
||||
6
fastlane/Appfile
Normal file
6
fastlane/Appfile
Normal file
@@ -0,0 +1,6 @@
|
||||
apple_id("james.magahern@mac.com")
|
||||
app_identifier("net.buzzert.QueueCube")
|
||||
team_id("DQQH5H6GBD")
|
||||
team_name("James Magahern")
|
||||
itc_team_id("127764897")
|
||||
itc_team_name("James Magahern")
|
||||
129
fastlane/Fastfile
Normal file
129
fastlane/Fastfile
Normal file
@@ -0,0 +1,129 @@
|
||||
require "fileutils"
|
||||
require "open3"
|
||||
require "shellwords"
|
||||
require "tempfile"
|
||||
|
||||
default_platform(:ios)
|
||||
|
||||
BUNDLE_IDENTIFIER = "net.buzzert.QueueCube"
|
||||
DEVELOPMENT_TEAM = "DQQH5H6GBD"
|
||||
APP_ROOT = File.expand_path("..", File.expand_path(__dir__))
|
||||
IOS_PROJECT_DIR = File.join(APP_ROOT, "ios")
|
||||
XCODE_PROJECT = File.join(IOS_PROJECT_DIR, "QueueCube.xcodeproj")
|
||||
SCHEME = "QueueCube"
|
||||
ARCHIVE_PATH = File.join(IOS_PROJECT_DIR, "build", "#{SCHEME}.xcarchive")
|
||||
EXPORT_PATH = File.join(IOS_PROJECT_DIR, "build", "upload")
|
||||
|
||||
def shell_command(*parts)
|
||||
parts.flatten.map { |part| part.to_s.shellescape }.join(" ")
|
||||
end
|
||||
|
||||
def archive_path
|
||||
ARCHIVE_PATH
|
||||
end
|
||||
|
||||
def export_path
|
||||
EXPORT_PATH
|
||||
end
|
||||
|
||||
def git_output(*args)
|
||||
stdout, stderr, status = Open3.capture3("git", *args, chdir: APP_ROOT)
|
||||
UI.user_error!("git #{args.join(' ')} failed: #{stderr.strip}") unless status.success?
|
||||
|
||||
stdout.strip
|
||||
end
|
||||
|
||||
def app_version
|
||||
tag = git_output("describe", "--tags", "--abbrev=0")
|
||||
version = tag.sub(/\Av/, "")
|
||||
unless version.match?(/\A\d+(?:\.\d+){0,2}\z/)
|
||||
UI.user_error!("Latest git tag #{tag.inspect} is not a valid App Store version. Use a tag like 1.5.2 or v1.5.2.")
|
||||
end
|
||||
|
||||
version
|
||||
end
|
||||
|
||||
def build_number
|
||||
git_output("rev-list", "--count", "HEAD")
|
||||
end
|
||||
|
||||
def upload_export_options
|
||||
<<~PLIST
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>method</key>
|
||||
<string>app-store-connect</string>
|
||||
<key>signingStyle</key>
|
||||
<string>automatic</string>
|
||||
<key>teamID</key>
|
||||
<string>#{DEVELOPMENT_TEAM}</string>
|
||||
<key>manageAppVersionAndBuildNumber</key>
|
||||
<false/>
|
||||
<key>stripSwiftSymbols</key>
|
||||
<true/>
|
||||
<key>uploadSymbols</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
PLIST
|
||||
end
|
||||
|
||||
platform :ios do
|
||||
desc "Build QueueCube for iOS and upload the archive to TestFlight"
|
||||
lane :beta do
|
||||
version = app_version
|
||||
build = build_number
|
||||
UI.message("Using QueueCube version #{version} (build #{build}) from git")
|
||||
|
||||
FileUtils.rm_rf(archive_path)
|
||||
FileUtils.rm_rf(export_path)
|
||||
|
||||
Dir.chdir(IOS_PROJECT_DIR) do
|
||||
sh(shell_command(
|
||||
"xcodebuild",
|
||||
"-project", XCODE_PROJECT,
|
||||
"-scheme", SCHEME,
|
||||
"-configuration", "Release",
|
||||
"-destination", "generic/platform=iOS",
|
||||
"-archivePath", archive_path,
|
||||
"-allowProvisioningUpdates",
|
||||
"clean",
|
||||
"archive",
|
||||
"DEVELOPMENT_TEAM=#{DEVELOPMENT_TEAM}",
|
||||
"PRODUCT_BUNDLE_IDENTIFIER=#{BUNDLE_IDENTIFIER}",
|
||||
"MARKETING_VERSION=#{version}",
|
||||
"CURRENT_PROJECT_VERSION=#{build}"
|
||||
))
|
||||
end
|
||||
|
||||
export_options = Tempfile.new(["queuecube-export-options", ".plist"])
|
||||
export_options.write(upload_export_options)
|
||||
export_options.close
|
||||
|
||||
FileUtils.rm_rf(export_path)
|
||||
Dir.chdir(IOS_PROJECT_DIR) do
|
||||
sh(shell_command(
|
||||
"xcodebuild",
|
||||
"-exportArchive",
|
||||
"-archivePath", archive_path,
|
||||
"-exportPath", export_path,
|
||||
"-exportOptionsPlist", export_options.path,
|
||||
"-allowProvisioningUpdates"
|
||||
))
|
||||
end
|
||||
|
||||
ipa_path = Dir[File.join(export_path, "*.ipa")].first
|
||||
UI.user_error!("No IPA found in #{export_path}") unless ipa_path
|
||||
|
||||
upload_to_testflight(
|
||||
app_identifier: BUNDLE_IDENTIFIER,
|
||||
ipa: ipa_path,
|
||||
skip_waiting_for_build_processing: true,
|
||||
uses_non_exempt_encryption: false
|
||||
)
|
||||
ensure
|
||||
export_options&.unlink
|
||||
end
|
||||
end
|
||||
32
fastlane/README.md
Normal file
32
fastlane/README.md
Normal file
@@ -0,0 +1,32 @@
|
||||
fastlane documentation
|
||||
----
|
||||
|
||||
# Installation
|
||||
|
||||
Make sure you have the latest version of the Xcode command line tools installed:
|
||||
|
||||
```sh
|
||||
xcode-select --install
|
||||
```
|
||||
|
||||
For _fastlane_ installation instructions, see [Installing _fastlane_](https://docs.fastlane.tools/#installing-fastlane)
|
||||
|
||||
# Available Actions
|
||||
|
||||
## iOS
|
||||
|
||||
### ios beta
|
||||
|
||||
```sh
|
||||
[bundle exec] fastlane ios beta
|
||||
```
|
||||
|
||||
Build QueueCube for iOS and upload the archive to TestFlight
|
||||
|
||||
----
|
||||
|
||||
This README.md is auto-generated and will be re-generated every time [_fastlane_](https://fastlane.tools) is run.
|
||||
|
||||
More information about _fastlane_ can be found on [fastlane.tools](https://fastlane.tools).
|
||||
|
||||
The documentation of _fastlane_ can be found on [docs.fastlane.tools](https://docs.fastlane.tools).
|
||||
@@ -14,6 +14,7 @@
|
||||
CD8ACBBF2DC5B8F2008BF856 /* Exceptions for "QueueCube" folder in "QueueCube" target */ = {
|
||||
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
|
||||
membershipExceptions = (
|
||||
App/Entitlements.plist,
|
||||
App/Info.plist,
|
||||
);
|
||||
target = CD4E9B962D7691C20066FC17 /* QueueCube */;
|
||||
@@ -268,7 +269,7 @@
|
||||
CODE_SIGN_IDENTITY = "Apple Development";
|
||||
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 5;
|
||||
CURRENT_PROJECT_VERSION = 13;
|
||||
DEVELOPMENT_TEAM = DQQH5H6GBD;
|
||||
ENABLE_PREVIEWS = YES;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
@@ -283,7 +284,7 @@
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
MARKETING_VERSION = 1.2;
|
||||
MARKETING_VERSION = 1.5.2;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = net.buzzert.QueueCube;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
|
||||
@@ -304,7 +305,7 @@
|
||||
CODE_SIGN_IDENTITY = "Apple Development";
|
||||
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 5;
|
||||
CURRENT_PROJECT_VERSION = 13;
|
||||
DEVELOPMENT_TEAM = DQQH5H6GBD;
|
||||
ENABLE_PREVIEWS = YES;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
@@ -319,7 +320,7 @@
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
MARKETING_VERSION = 1.2;
|
||||
MARKETING_VERSION = 1.5.2;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = net.buzzert.QueueCube;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
|
||||
|
||||
@@ -16,9 +16,19 @@ struct MediaItem: Codable
|
||||
let current: Bool?
|
||||
let playing: Bool?
|
||||
let metadata: Metadata?
|
||||
let playbackError: String?
|
||||
|
||||
var displayTitle: String {
|
||||
metadata?.title ?? title ?? filename ?? "item \(id)"
|
||||
metadata?.title ?? title ?? displayFilename ?? "item \(id)"
|
||||
}
|
||||
|
||||
private var displayFilename: String? {
|
||||
guard let filename else { return nil }
|
||||
if let url = URL(string: filename) {
|
||||
return url.lastPathComponent
|
||||
}
|
||||
|
||||
return filename
|
||||
}
|
||||
|
||||
// MARK: - Types
|
||||
@@ -234,8 +244,6 @@ actor API
|
||||
private static func notifyError(_ error: any Swift.Error, continuation: AsyncStream<StreamEvent>.Continuation) {
|
||||
print("Websocket Error: \(error)")
|
||||
|
||||
let nsError = error as NSError
|
||||
|
||||
// Always notify observers of WebSocket errors so reconnection can happen
|
||||
// The UI layer can decide whether to show the error to the user
|
||||
continuation.yield(.error(.websocketError(error)))
|
||||
@@ -273,6 +281,7 @@ actor API
|
||||
case favoritesUpdate = "favorites_update"
|
||||
case metadataUpdate = "metadata_update"
|
||||
case mpdUpdate = "mpd_update"
|
||||
case playbackError = "playback_error"
|
||||
|
||||
// Private UI events
|
||||
case receivedWebsocketPong
|
||||
|
||||
@@ -104,6 +104,16 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"DELETE" : {
|
||||
"localizations" : {
|
||||
"en" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "Delete"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"DISCOVERED" : {
|
||||
"localizations" : {
|
||||
"en" : {
|
||||
@@ -247,6 +257,16 @@
|
||||
},
|
||||
"Nothing here yet." : {
|
||||
|
||||
},
|
||||
"PLAYBACK_ERROR" : {
|
||||
"localizations" : {
|
||||
"en" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "Playback Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"PLAYLIST" : {
|
||||
"localizations" : {
|
||||
@@ -360,6 +380,16 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"Unknown error" : {
|
||||
"localizations" : {
|
||||
"en" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "Unknown Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"URL" : {
|
||||
"localizations" : {
|
||||
"en" : {
|
||||
|
||||
@@ -46,4 +46,6 @@ extension LocalizedStringKey
|
||||
static let notPlaying = LocalizedStringKey("NOT_PLAYING")
|
||||
static let url = LocalizedStringKey("URL")
|
||||
static let title = LocalizedStringKey("TITLE")
|
||||
static let playbackError = LocalizedStringKey("PLAYBACK_ERROR")
|
||||
static let delete = LocalizedStringKey("DELETE")
|
||||
}
|
||||
|
||||
@@ -10,17 +10,23 @@ import SwiftUI
|
||||
struct AddMediaView: View
|
||||
{
|
||||
@Binding var model: ViewModel
|
||||
@FocusState var fieldFocused: Bool
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
Form {
|
||||
// Add URL
|
||||
Section {
|
||||
TextField(.addAnyURL, text: $model.fieldContents)
|
||||
HStack {
|
||||
AutofocusingTextField(String(localized: "ADD_ANY_URL"), text: $model.fieldContents)
|
||||
.autocapitalization(.none)
|
||||
.autocorrectionDisabled()
|
||||
.focused($fieldFocused)
|
||||
|
||||
PasteButton(payloadType: String.self) { payload in
|
||||
guard let contents = payload.first else { return }
|
||||
model.fieldContents = contents
|
||||
}
|
||||
.labelStyle(.iconOnly)
|
||||
}
|
||||
}
|
||||
|
||||
if model.supportsSearch {
|
||||
@@ -35,8 +41,6 @@ struct AddMediaView: View
|
||||
}
|
||||
}
|
||||
}
|
||||
.task { fieldFocused = true }
|
||||
.onAppear { model.activeDetent = ViewModel.Detent.collapsed.value }
|
||||
.navigationTitle(.addMedia)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
@@ -72,21 +76,6 @@ struct AddMediaView: View
|
||||
var onSearch: () -> Void = { }
|
||||
var supportsSearch: Bool = true
|
||||
|
||||
var activeDetent: PresentationDetent = Detent.collapsed.value
|
||||
|
||||
enum Detent: CaseIterable
|
||||
{
|
||||
case collapsed
|
||||
case expanded
|
||||
|
||||
var value: PresentationDetent {
|
||||
switch self {
|
||||
case .collapsed: .height(320.0)
|
||||
case .expanded: .large
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate func addButtonTapped() {
|
||||
onAdd(fieldContents)
|
||||
}
|
||||
@@ -107,11 +96,8 @@ struct SearchMediaView: View
|
||||
Image(systemName: "magnifyingglass")
|
||||
.foregroundColor(.secondary)
|
||||
|
||||
TextField(.searchForMedia, text: $searchText)
|
||||
AutofocusingTextField(String(localized: "SEARCH_FOR_MEDIA"), text: $searchText, onSubmit: performSearch)
|
||||
.focused($searchFieldFocused)
|
||||
.onSubmit {
|
||||
performSearch()
|
||||
}
|
||||
|
||||
if !searchText.isEmpty {
|
||||
Button {
|
||||
@@ -153,7 +139,6 @@ struct SearchMediaView: View
|
||||
.navigationTitle(.searchForMedia)
|
||||
.presentationBackground(.regularMaterial)
|
||||
.onAppear {
|
||||
model.activeDetent = AddMediaView.ViewModel.Detent.expanded.value
|
||||
searchFieldFocused = true
|
||||
}
|
||||
}
|
||||
|
||||
71
ios/QueueCube/Views/AutofocusingTextField.swift
Normal file
71
ios/QueueCube/Views/AutofocusingTextField.swift
Normal file
@@ -0,0 +1,71 @@
|
||||
//
|
||||
// AutofocusingTextField.swift
|
||||
// QueueCube
|
||||
//
|
||||
// Created by James Magahern on 11/15/25.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import UIKit
|
||||
|
||||
/// Stupid: it appears to be impossible to make it so SwiftUI's `.focused(_:)` modifier takes place during the
|
||||
/// presentation of a sheet, so this needs to exist just to make sure it's made first responder as soon as it moves to
|
||||
/// the view hierarchy.
|
||||
struct AutofocusingTextField: UIViewRepresentable
|
||||
{
|
||||
let placeholder: String
|
||||
@Binding var text: String
|
||||
var onSubmit: () -> Void = {}
|
||||
|
||||
init(_ placeholder: String, text: Binding<String>, onSubmit: @escaping () -> Void = {}) {
|
||||
self.placeholder = placeholder
|
||||
self._text = text
|
||||
self.onSubmit = onSubmit
|
||||
}
|
||||
|
||||
func makeUIView(context: Context) -> UITextField {
|
||||
let tf = FirstResponderTextField()
|
||||
tf.placeholder = placeholder
|
||||
tf.delegate = context.coordinator
|
||||
tf.returnKeyType = .done
|
||||
tf.setContentHuggingPriority(.defaultHigh, for: .vertical)
|
||||
tf.autocorrectionType = .no
|
||||
tf.autocapitalizationType = .none
|
||||
return tf
|
||||
}
|
||||
|
||||
func updateUIView(_ uiView: UITextField, context: Context) {
|
||||
if uiView.text != text {
|
||||
uiView.text = text
|
||||
}
|
||||
context.coordinator.parent = self // keep latest onSubmit/text binding
|
||||
}
|
||||
|
||||
func makeCoordinator() -> Coordinator {
|
||||
Coordinator(parent: self)
|
||||
}
|
||||
|
||||
final class Coordinator: NSObject, UITextFieldDelegate {
|
||||
var parent: AutofocusingTextField
|
||||
|
||||
init(parent: AutofocusingTextField) {
|
||||
self.parent = parent
|
||||
}
|
||||
|
||||
func textFieldDidChangeSelection(_ textField: UITextField) {
|
||||
parent.text = textField.text ?? ""
|
||||
}
|
||||
|
||||
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
|
||||
parent.onSubmit()
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final class FirstResponderTextField: UITextField {
|
||||
override func didMoveToSuperview() {
|
||||
super.didMoveToSuperview()
|
||||
becomeFirstResponder()
|
||||
}
|
||||
}
|
||||
@@ -29,10 +29,6 @@ struct ContentView: View
|
||||
.sheet(isPresented: $model.isAddMediaSheetPresented) {
|
||||
AddMediaView(model: $model.addMediaViewModel)
|
||||
.presentationBackground(.regularMaterial)
|
||||
.presentationDetents(
|
||||
Set(AddMediaView.ViewModel.Detent.allCases.map { $0.value }),
|
||||
selection: $model.addMediaViewModel.activeDetent
|
||||
)
|
||||
}
|
||||
.sheet(isPresented: $model.isEditSheetPresented) {
|
||||
EditItemView(model: $model.editMediaViewModel)
|
||||
@@ -91,7 +87,8 @@ extension ContentView
|
||||
title: mediaItem.displayTitle,
|
||||
filename: mediaItem.filename ?? "<null>",
|
||||
index: idx,
|
||||
isCurrent: mediaItem.current ?? false
|
||||
isCurrent: mediaItem.current ?? false,
|
||||
playbackError: mediaItem.playbackError
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -104,7 +101,8 @@ extension ContentView
|
||||
id: String(mediaItem.id),
|
||||
title: mediaItem.displayTitle,
|
||||
filename: mediaItem.filename ?? "<null>",
|
||||
isCurrent: nowPlaying.playingItem?.filename == mediaItem.filename
|
||||
isCurrent: nowPlaying.playingItem?.filename == mediaItem.filename,
|
||||
playbackError: mediaItem.playbackError
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -121,9 +119,15 @@ extension ContentView
|
||||
await clearConnectionErrorIfNecessary()
|
||||
await handle(event: event)
|
||||
case .error(let error):
|
||||
// Ignore if we're in the bg
|
||||
guard scenePhase == .active else { break }
|
||||
|
||||
// Check if this is a backgrounding error (connection abort)
|
||||
let nsError = error as NSError
|
||||
let isBackgroundingError = nsError.code == 53
|
||||
var isBackgroundingError = false
|
||||
if case let .websocketError(wsError) = error {
|
||||
let nsError = wsError as NSError
|
||||
isBackgroundingError = nsError.code == 53
|
||||
}
|
||||
|
||||
// Only show connection error to user if it's not a backgrounding error
|
||||
if !isBackgroundingError {
|
||||
@@ -158,7 +162,8 @@ extension ContentView
|
||||
|
||||
case .websocketReconnected: fallthrough
|
||||
case .metadataUpdate: fallthrough
|
||||
case .mpdUpdate:
|
||||
case .mpdUpdate: fallthrough
|
||||
case .playbackError:
|
||||
await refresh([.playlist, .nowPlaying, .favorites])
|
||||
|
||||
case .receivedWebsocketPong:
|
||||
|
||||
@@ -325,18 +325,9 @@ struct ServerSelectionToolbarModifier: ViewModifier
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if false
|
||||
// TODO
|
||||
Section {
|
||||
Button(.addServer) {
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
} label: {
|
||||
Label(model.selectedServer?.displayName ?? "Servers", systemImage: "chevron.down")
|
||||
.labelStyle(.titleAndIcon)
|
||||
.labelStyle(.titleOnly)
|
||||
}
|
||||
.buttonBorderShape(.capsule)
|
||||
.buttonStyle(.bordered)
|
||||
|
||||
@@ -41,16 +41,16 @@ struct NowPlayingView: View
|
||||
VStack {
|
||||
if let title = model.title {
|
||||
Text(title)
|
||||
.font(.title2)
|
||||
.font(.title3)
|
||||
.lineLimit(1)
|
||||
.bold()
|
||||
}
|
||||
|
||||
if let subtitle = model.subtitle {
|
||||
Text(subtitle)
|
||||
.font(.title3)
|
||||
.font(.subheadline)
|
||||
.foregroundStyle(.secondary)
|
||||
.lineLimit(1)
|
||||
.lineLimit(2)
|
||||
}
|
||||
|
||||
if nothingQueued {
|
||||
|
||||
@@ -14,17 +14,19 @@ struct MediaListItem: Identifiable
|
||||
let filename: String
|
||||
let index: Int?
|
||||
let isCurrent: Bool
|
||||
let playbackError: String?
|
||||
|
||||
var id: String {
|
||||
_id + filename // temporary: we get duplicate ids from the server sometimes...
|
||||
}
|
||||
|
||||
init(id: String, title: String, filename: String, index: Int? = nil, isCurrent: Bool = false) {
|
||||
init(id: String, title: String, filename: String, index: Int? = nil, isCurrent: Bool = false, playbackError: String? = nil) {
|
||||
self._id = id
|
||||
self.title = title
|
||||
self.filename = filename
|
||||
self.index = index
|
||||
self.isCurrent = isCurrent
|
||||
self.playbackError = playbackError
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +47,7 @@ class MediaListViewModel
|
||||
var onQueue: (MediaListItem) -> Void = { _ in }
|
||||
var onEdit: (MediaListItem) -> Void = { _ in }
|
||||
var onFavorite: (MediaListItem) -> Void = { _ in }
|
||||
var onDelete: (MediaListItem) -> Void = { _ in }
|
||||
|
||||
init(mode: MediaListMode) {
|
||||
self.mode = mode
|
||||
@@ -54,6 +57,8 @@ class MediaListViewModel
|
||||
struct MediaListView: View
|
||||
{
|
||||
@Binding var model: MediaListViewModel
|
||||
@State private var errorAlertItem: MediaListItem? = nil
|
||||
@State private var isShowingErrorAlert: Bool = false
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
@@ -70,20 +75,29 @@ struct MediaListView: View
|
||||
let state = item.isCurrent ? (model.isPlaying ? MediaItemCell.State.playing : MediaItemCell.State.paused) : .queued
|
||||
|
||||
Button {
|
||||
if let _ = item.playbackError {
|
||||
errorAlertItem = item
|
||||
isShowingErrorAlert = true
|
||||
} else {
|
||||
switch model.mode {
|
||||
case .playlist:
|
||||
model.onSeek(item)
|
||||
case .favorites:
|
||||
model.onPlay(item)
|
||||
}
|
||||
}
|
||||
} label: {
|
||||
MediaItemCell(
|
||||
title: item.title,
|
||||
subtitle: item.filename,
|
||||
state: state
|
||||
state: state,
|
||||
playbackError: item.playbackError
|
||||
)
|
||||
}
|
||||
.listRowBackground((model.mode == .playlist && state != .queued) ? Color.accentColor.opacity(0.10) : nil)
|
||||
.listRowBackground(
|
||||
item.playbackError != nil ? Color.red.opacity(0.15) :
|
||||
(model.mode == .playlist && state != .queued ? Color.accentColor.opacity(0.10) : nil)
|
||||
)
|
||||
.contextMenu {
|
||||
Button(.copyTitle) {
|
||||
UIPasteboard.general.string = item.title
|
||||
@@ -123,6 +137,20 @@ struct MediaListView: View
|
||||
}
|
||||
}
|
||||
}
|
||||
.alert(.playbackError, isPresented: $isShowingErrorAlert, presenting: errorAlertItem) { item in
|
||||
Button(.cancel, role: .cancel) {
|
||||
errorAlertItem = nil
|
||||
isShowingErrorAlert = false
|
||||
}
|
||||
Button(.delete, role: .destructive) {
|
||||
model.items.removeAll { $0.id == item.id }
|
||||
model.onDelete(item)
|
||||
errorAlertItem = nil
|
||||
isShowingErrorAlert = false
|
||||
}
|
||||
} message: { item in
|
||||
Text(item.playbackError ?? "Unknown error")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -134,26 +162,24 @@ struct MediaItemCell: View
|
||||
let title: String
|
||||
let subtitle: String
|
||||
let state: State
|
||||
let playbackError: String?
|
||||
|
||||
var body: some View {
|
||||
let icon: String = switch state {
|
||||
case .queued: "play.fill"
|
||||
case .playing: "speaker.wave.3.fill"
|
||||
case .paused: "speaker.fill"
|
||||
}
|
||||
|
||||
HStack {
|
||||
Image(systemName: icon)
|
||||
.tint(Color.primary)
|
||||
Image(systemName: iconName)
|
||||
.tint(playbackError == nil ? Color.primary : Color.orange)
|
||||
.frame(width: 15.0)
|
||||
.padding(.trailing, 10.0)
|
||||
|
||||
VStack(alignment: .leading) {
|
||||
Text(title)
|
||||
.bold()
|
||||
.font(.subheadline)
|
||||
.tint(.primary)
|
||||
.lineLimit(1)
|
||||
|
||||
Text(subtitle)
|
||||
.font(.caption)
|
||||
.foregroundColor(.secondary)
|
||||
.lineLimit(1)
|
||||
}
|
||||
@@ -161,6 +187,19 @@ struct MediaItemCell: View
|
||||
Spacer()
|
||||
}
|
||||
.padding([.top, .bottom], 4.0)
|
||||
.frame(minHeight: 44.0)
|
||||
}
|
||||
|
||||
private var iconName: String {
|
||||
if playbackError != nil {
|
||||
return "exclamationmark.triangle.fill"
|
||||
}
|
||||
|
||||
switch state {
|
||||
case .queued: return "play.fill"
|
||||
case .playing: return "speaker.wave.3.fill"
|
||||
case .paused: return "speaker.fill"
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Types
|
||||
@@ -171,4 +210,3 @@ struct MediaItemCell: View
|
||||
case paused
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 196 KiB After Width: | Height: | Size: 196 KiB |
@@ -30,6 +30,11 @@ interface PendingCommand {
|
||||
reject: (reason: any) => void;
|
||||
}
|
||||
|
||||
enum ObservedProperty {
|
||||
MediaTitle = 1,
|
||||
Metadata = 2,
|
||||
}
|
||||
|
||||
enum UserEvent {
|
||||
PlaylistUpdate = "playlist_update",
|
||||
NowPlayingUpdate = "now_playing_update",
|
||||
@@ -37,6 +42,7 @@ enum UserEvent {
|
||||
FavoritesUpdate = "favorites_update",
|
||||
MetadataUpdate = "metadata_update",
|
||||
MPDUpdate = "mpd_update",
|
||||
PlaybackError = "playback_error",
|
||||
}
|
||||
|
||||
export interface Features {
|
||||
@@ -57,6 +63,11 @@ export class MediaPlayer {
|
||||
private dataBuffer: string = '';
|
||||
private metadata: Map<string, LinkMetadata> = new Map();
|
||||
private bonjourInstance: Bonjour | null = null;
|
||||
private playbackErrors: Map<string, string> = new Map();
|
||||
private currentFile: string | null = null;
|
||||
private lastLoadCandidate: string | null = null;
|
||||
private currentMediaTitle: string | null = null;
|
||||
private currentPlaybackMetadata: Record<string, string> = {};
|
||||
|
||||
constructor() {
|
||||
this.socket = this.tryRespawnPlayerProcess();
|
||||
@@ -110,10 +121,9 @@ export class MediaPlayer {
|
||||
const socketFilename = Math.random().toString(36).substring(2, 10);
|
||||
const socketPath = `/tmp/mpv-${socketFilename}`;
|
||||
const enableVideo = process.env.ENABLE_VIDEO || false;
|
||||
const ytdlFormat = process.env.MPV_YTDL_FORMAT;
|
||||
const logfilePath = `/tmp/mpv-logfile.txt`;
|
||||
|
||||
console.log("Starting player process (video: " + (enableVideo ? "enabled" : "disabled") + ")");
|
||||
this.playerProcess = spawn("mpv", [
|
||||
const playerArgs = [
|
||||
"--video=" + (enableVideo ? "auto" : "no"),
|
||||
"--fullscreen",
|
||||
"--no-terminal",
|
||||
@@ -121,25 +131,38 @@ export class MediaPlayer {
|
||||
"--input-ipc-server=" + socketPath,
|
||||
"--log-file=" + logfilePath,
|
||||
"--msg-level=all=v"
|
||||
]);
|
||||
];
|
||||
|
||||
if (ytdlFormat) {
|
||||
playerArgs.push("--ytdl-format=" + ytdlFormat);
|
||||
}
|
||||
|
||||
console.log("Starting player process (video: " + (enableVideo ? "enabled" : "disabled") + ")");
|
||||
this.playerProcess = spawn("mpv", playerArgs);
|
||||
|
||||
|
||||
let socketReady!: (s: Socket) => void;
|
||||
let socketPromise = new Promise<Socket>(resolve => {
|
||||
let socketFailed!: (reason?: unknown) => void;
|
||||
let socketPromise = new Promise<Socket>((resolve, reject) => {
|
||||
socketReady = resolve;
|
||||
socketFailed = reject;
|
||||
});
|
||||
|
||||
this.playerProcess.on("spawn", () => {
|
||||
console.log(`Player process spawned, opening socket @ ${socketPath}`);
|
||||
setTimeout(() => {
|
||||
let socket = this.connectToSocket(socketPath);
|
||||
socketReady(socket);
|
||||
}, 500);
|
||||
this.connectToSocket(socketPath)
|
||||
.then(socket => socketReady(socket))
|
||||
.catch((error: unknown) => {
|
||||
console.error(`Failed to connect to mpv socket @ ${socketPath}:`, error);
|
||||
console.log("Continuing without mpv player...");
|
||||
socketFailed(error);
|
||||
});
|
||||
});
|
||||
|
||||
this.playerProcess.on("error", (error) => {
|
||||
this.playerProcess.on("error", (error: unknown) => {
|
||||
console.error("Player process error:", error);
|
||||
console.log("Continuing without mpv player...");
|
||||
socketFailed(error);
|
||||
});
|
||||
|
||||
return socketPromise;
|
||||
@@ -150,10 +173,15 @@ export class MediaPlayer {
|
||||
.then((response) => {
|
||||
// Enhance playlist items with metadata
|
||||
const playlist = response.data as PlaylistItem[];
|
||||
return playlist.map((item: PlaylistItem) => ({
|
||||
return playlist.map((item: PlaylistItem) => {
|
||||
const enhancedItem = {
|
||||
...item,
|
||||
metadata: this.metadata.get(item.filename) || {}
|
||||
}));
|
||||
metadata: this.metadata.get(item.filename) || {},
|
||||
playbackError: this.playbackErrors.get(item.filename)
|
||||
};
|
||||
|
||||
return item.current ? this.withCurrentDynamicTitle(enhancedItem) : enhancedItem;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -162,29 +190,37 @@ export class MediaPlayer {
|
||||
const currentlyPlayingSong = playlist.find((item: PlaylistItem) => item.current);
|
||||
const fetchMediaTitle = async (): Promise<string | null> => {
|
||||
try {
|
||||
return (await this.writeCommand("get_property", ["media-title"])).data;
|
||||
const mediaTitle = (await this.writeCommand("get_property", ["media-title"])).data;
|
||||
this.currentMediaTitle = typeof mediaTitle === "string" ? mediaTitle : null;
|
||||
return this.currentMediaTitle;
|
||||
} catch (err) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
const mediaTitle = await fetchMediaTitle();
|
||||
|
||||
if (currentlyPlayingSong !== undefined) {
|
||||
const dynamicTitle = this.getCurrentDynamicTitle(currentlyPlayingSong);
|
||||
if (dynamicTitle) {
|
||||
return this.withCurrentDynamicTitle(currentlyPlayingSong, dynamicTitle);
|
||||
}
|
||||
|
||||
// Use media title if we don't have a title
|
||||
if (currentlyPlayingSong.title === undefined && currentlyPlayingSong.metadata?.title === undefined) {
|
||||
return {
|
||||
...currentlyPlayingSong,
|
||||
title: await fetchMediaTitle() || currentlyPlayingSong.filename
|
||||
title: mediaTitle || currentlyPlayingSong.filename
|
||||
};
|
||||
}
|
||||
|
||||
return currentlyPlayingSong;
|
||||
}
|
||||
|
||||
const mediaTitle = await fetchMediaTitle() || "";
|
||||
return {
|
||||
id: 0,
|
||||
filename: mediaTitle,
|
||||
title: mediaTitle
|
||||
filename: mediaTitle || "",
|
||||
title: mediaTitle || ""
|
||||
};
|
||||
}
|
||||
|
||||
@@ -352,6 +388,8 @@ export class MediaPlayer {
|
||||
}
|
||||
|
||||
private async loadFile(url: string, mode: string, fetchMetadata: boolean = true, options: string[] = []) {
|
||||
this.lastLoadCandidate = url;
|
||||
this.playbackErrors.delete(url);
|
||||
this.modify(UserEvent.PlaylistUpdate, () => this.writeCommand("loadfile", [url, mode, "-1", options.join(',')]));
|
||||
|
||||
if (fetchMetadata) {
|
||||
@@ -390,7 +428,7 @@ export class MediaPlayer {
|
||||
socket.write(commandObject + '\n');
|
||||
} catch (e: any) {
|
||||
console.error(`Error writing to socket: ${e}. Trying to respawn.`)
|
||||
this.tryRespawnPlayerProcess();
|
||||
this.socket = this.tryRespawnPlayerProcess();
|
||||
}
|
||||
|
||||
// Add timeout to prevent hanging promises
|
||||
@@ -429,12 +467,52 @@ export class MediaPlayer {
|
||||
}
|
||||
}
|
||||
|
||||
private connectToSocket(path: string): Socket {
|
||||
let socket = new Socket();
|
||||
socket.connect(path);
|
||||
socket.on("data", data => this.receiveData(data.toString()));
|
||||
private connectToSocket(path: string): Promise<Socket> {
|
||||
const retryDelayMs = 100;
|
||||
const maxAttempts = 50;
|
||||
|
||||
return socket;
|
||||
return new Promise((resolve, reject) => {
|
||||
type SocketError = Error & { code?: string };
|
||||
|
||||
const attemptConnection = (attempt: number) => {
|
||||
const socket = new Socket();
|
||||
|
||||
const onError = (error: SocketError) => {
|
||||
socket.removeAllListeners();
|
||||
socket.destroy();
|
||||
|
||||
const shouldRetry = (error.code === "ENOENT" || error.code === "ECONNREFUSED") && attempt < maxAttempts;
|
||||
if (shouldRetry) {
|
||||
setTimeout(() => attemptConnection(attempt + 1), retryDelayMs);
|
||||
return;
|
||||
}
|
||||
|
||||
reject(error);
|
||||
};
|
||||
|
||||
socket.once("connect", () => {
|
||||
socket.removeListener("error", onError);
|
||||
socket.on("data", (data: unknown) => this.receiveData(String(data)));
|
||||
socket.on("error", (error: unknown) => {
|
||||
console.error("MPV socket error:", error);
|
||||
});
|
||||
resolve(socket);
|
||||
this.registerMpvObservers().catch((error: unknown) => {
|
||||
console.error("Failed to register mpv observers:", error);
|
||||
});
|
||||
});
|
||||
|
||||
socket.once("error", onError);
|
||||
socket.connect(path);
|
||||
};
|
||||
|
||||
attemptConnection(1);
|
||||
});
|
||||
}
|
||||
|
||||
private async registerMpvObservers() {
|
||||
await this.writeCommand("observe_property", [ObservedProperty.MediaTitle, "media-title"]);
|
||||
await this.writeCommand("observe_property", [ObservedProperty.Metadata, "metadata"]);
|
||||
}
|
||||
|
||||
private handleEvent(event: string, data: any) {
|
||||
@@ -470,6 +548,29 @@ export class MediaPlayer {
|
||||
this.pendingCommands.delete(response.request_id);
|
||||
}
|
||||
} else if (response.event) {
|
||||
if (response.event === "start-file") {
|
||||
// Clear any previous error for the file that is starting
|
||||
const file = response.file || this.lastLoadCandidate;
|
||||
if (file) {
|
||||
this.currentFile = file;
|
||||
this.playbackErrors.delete(file);
|
||||
}
|
||||
|
||||
this.currentMediaTitle = null;
|
||||
this.currentPlaybackMetadata = {};
|
||||
} else if (response.event === "property-change") {
|
||||
this.handlePropertyChange(response);
|
||||
} else if (response.event === "end-file" && response.reason === "error") {
|
||||
const file = response.file || this.currentFile || this.lastLoadCandidate || "Unknown file";
|
||||
const errorMessage = response.error || response["file-error"] || "Unknown playback error";
|
||||
|
||||
this.playbackErrors.set(file, errorMessage);
|
||||
this.handleEvent(UserEvent.PlaybackError, {
|
||||
filename: file,
|
||||
error: errorMessage
|
||||
});
|
||||
}
|
||||
|
||||
this.handleEvent(UserEvent.MPDUpdate, response);
|
||||
} else {
|
||||
console.log(response);
|
||||
@@ -480,4 +581,143 @@ export class MediaPlayer {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private handlePropertyChange(response: any) {
|
||||
const previousTitle = this.getCurrentDynamicTitle();
|
||||
|
||||
if (response.id === ObservedProperty.MediaTitle || response.name === "media-title") {
|
||||
this.currentMediaTitle = typeof response.data === "string" ? response.data : null;
|
||||
} else if (response.id === ObservedProperty.Metadata || response.name === "metadata") {
|
||||
this.currentPlaybackMetadata = this.normalizeMpvMetadata(response.data);
|
||||
}
|
||||
|
||||
const currentTitle = this.getCurrentDynamicTitle();
|
||||
if (currentTitle !== previousTitle) {
|
||||
this.handleEvent(UserEvent.MetadataUpdate, {
|
||||
url: this.currentFile,
|
||||
title: currentTitle,
|
||||
metadata: this.currentPlaybackMetadata
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private withCurrentDynamicTitle(item: PlaylistItem, dynamicTitle: string | null = this.getCurrentDynamicTitle(item)): PlaylistItem {
|
||||
if (!dynamicTitle) {
|
||||
return item;
|
||||
}
|
||||
|
||||
return {
|
||||
...item,
|
||||
title: dynamicTitle,
|
||||
metadata: {
|
||||
...item.metadata,
|
||||
title: dynamicTitle
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private getCurrentDynamicTitle(item?: PlaylistItem): string | null {
|
||||
if (this.currentMediaTitle && !this.isFallbackMediaTitle(this.currentMediaTitle, item?.filename)) {
|
||||
return this.currentMediaTitle.trim();
|
||||
}
|
||||
|
||||
return this.extractTitleFromMpvMetadata();
|
||||
}
|
||||
|
||||
private extractTitleFromMpvMetadata(): string | null {
|
||||
const titleKeys = new Set(["title", "icy-title", "icy_title", "streamtitle", "stream-title"]);
|
||||
|
||||
for (const key of Object.keys(this.currentPlaybackMetadata)) {
|
||||
const normalizedKey = key.toLowerCase();
|
||||
if (!titleKeys.has(normalizedKey)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const title = this.parseStreamTitle(this.currentPlaybackMetadata[key]);
|
||||
if (title) {
|
||||
return title;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private parseStreamTitle(value: string | undefined): string | null {
|
||||
const trimmedValue = value?.trim();
|
||||
if (!trimmedValue) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const streamTitleMatch = trimmedValue.match(/StreamTitle='([^']*)'/i);
|
||||
return (streamTitleMatch?.[1] || trimmedValue).trim() || null;
|
||||
}
|
||||
|
||||
private normalizeMpvMetadata(data: unknown): Record<string, string> {
|
||||
if (data === null || typeof data !== "object" || Array.isArray(data)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const metadata: Record<string, string> = {};
|
||||
const rawMetadata = data as Record<string, unknown>;
|
||||
|
||||
for (const key of Object.keys(rawMetadata)) {
|
||||
const value = rawMetadata[key];
|
||||
if (value !== null && value !== undefined) {
|
||||
metadata[key] = String(value);
|
||||
}
|
||||
}
|
||||
|
||||
return metadata;
|
||||
}
|
||||
|
||||
private isFallbackMediaTitle(title: string, filename?: string): boolean {
|
||||
const normalizedTitle = title.trim();
|
||||
if (!normalizedTitle) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const fallbackCandidates = new Set<string>();
|
||||
if (filename) {
|
||||
this.addFallbackTitleCandidates(fallbackCandidates, filename);
|
||||
}
|
||||
|
||||
if (this.currentFile) {
|
||||
this.addFallbackTitleCandidates(fallbackCandidates, this.currentFile);
|
||||
}
|
||||
|
||||
return fallbackCandidates.has(normalizedTitle);
|
||||
}
|
||||
|
||||
private addFallbackTitleCandidates(candidates: Set<string>, value: string) {
|
||||
candidates.add(value);
|
||||
|
||||
try {
|
||||
candidates.add(decodeURIComponent(value));
|
||||
} catch {
|
||||
// Keep the original value if it is not URI-encoded.
|
||||
}
|
||||
|
||||
try {
|
||||
const url = new URL(value);
|
||||
this.addPathTitleCandidates(candidates, url.pathname);
|
||||
} catch {
|
||||
this.addPathTitleCandidates(candidates, value);
|
||||
}
|
||||
}
|
||||
|
||||
private addPathTitleCandidates(candidates: Set<string>, path: string) {
|
||||
const pathSegments = path.split("/").filter(Boolean);
|
||||
const lastPathSegment = pathSegments[pathSegments.length - 1];
|
||||
if (!lastPathSegment) {
|
||||
return;
|
||||
}
|
||||
|
||||
candidates.add(lastPathSegment);
|
||||
|
||||
try {
|
||||
candidates.add(decodeURIComponent(lastPathSegment));
|
||||
} catch {
|
||||
// Keep the original segment if it is not URI-encoded.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,4 +29,5 @@ export interface PlaylistItem {
|
||||
playing?: boolean;
|
||||
current?: boolean;
|
||||
metadata?: LinkMetadata;
|
||||
playbackError?: string;
|
||||
}
|
||||
|
||||
6
web/flake.lock
generated
6
web/flake.lock
generated
@@ -20,11 +20,11 @@
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1740828860,
|
||||
"narHash": "sha256-cjbHI+zUzK5CPsQZqMhE3npTyYFt9tJ3+ohcfaOF/WM=",
|
||||
"lastModified": 1779560665,
|
||||
"narHash": "sha256-tpyBcxPpcQb8ukyNF7DoCwfSY3VPsxHoYwj00Cayv5o=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "303bd8071377433a2d8f76e684ec773d70c5b642",
|
||||
"rev": "64c08a7ca051951c8eae34e3e3cb1e202fe36786",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
||||
225
web/flake.nix
225
web/flake.nix
@@ -8,97 +8,7 @@
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils }:
|
||||
let
|
||||
# Define the NixOS module for the systemd service
|
||||
nixosModule = { config, lib, pkgs, ... }:
|
||||
let
|
||||
cfg = config.services.queuecube;
|
||||
in {
|
||||
options.services.queuecube = {
|
||||
enable = lib.mkEnableOption "QueueCube media player service";
|
||||
|
||||
port = lib.mkOption {
|
||||
type = lib.types.port;
|
||||
default = 3000;
|
||||
description = "Port on which QueueCube will listen";
|
||||
};
|
||||
|
||||
enable_video = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
description = "Enable video playback";
|
||||
};
|
||||
|
||||
store_path = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "/var/tmp/queuecube";
|
||||
description = "Path to the store for QueueCube";
|
||||
};
|
||||
|
||||
invidious = lib.mkOption {
|
||||
type = lib.types.submodule {
|
||||
options = {
|
||||
enable = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
description = "Enable Invidious";
|
||||
};
|
||||
|
||||
url = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "http://invidious.nor";
|
||||
description = "URL of the Invidious instance to use";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
default = {
|
||||
enable = false;
|
||||
url = "http://invidious.nor";
|
||||
};
|
||||
};
|
||||
|
||||
user = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = "User account under which QueueCube runs (required)";
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
users.users.${cfg.user} = {
|
||||
packages = [ self.packages.${pkgs.system}.queuecube ];
|
||||
};
|
||||
|
||||
systemd.user.services.queuecube = {
|
||||
description = "QueueCube media player service";
|
||||
wantedBy = [ "default.target" ];
|
||||
after = [ "pipewire.service" "pipewire-pulse.service" ];
|
||||
|
||||
serviceConfig = {
|
||||
ExecStart = "${self.packages.${pkgs.system}.queuecube}/bin/queuecube";
|
||||
Restart = "on-failure";
|
||||
RestartSec = 5;
|
||||
|
||||
# Allow access to X11 for mpv
|
||||
Environment = [ "DISPLAY=:0" ];
|
||||
};
|
||||
|
||||
environment = {
|
||||
PORT = toString cfg.port;
|
||||
ENABLE_VIDEO = if cfg.enable_video then "1" else "0";
|
||||
USE_INVIDIOUS = if cfg.invidious.enable then "1" else "0";
|
||||
INVIDIOUS_BASE_URL = cfg.invidious.url;
|
||||
STORE_PATH = cfg.store_path;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
in
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
|
||||
# Define the package using buildNpmPackage
|
||||
queuecube = pkgs.buildNpmPackage {
|
||||
mkQueuecube = pkgs: pkgs.buildNpmPackage {
|
||||
pname = "queuecube";
|
||||
version = "0.1.0";
|
||||
|
||||
@@ -163,6 +73,136 @@
|
||||
};
|
||||
};
|
||||
|
||||
# Define the NixOS module for the systemd service
|
||||
nixosModule = { config, lib, pkgs, ... }:
|
||||
let
|
||||
cfg = config.services.queuecube;
|
||||
package = mkQueuecube pkgs;
|
||||
in {
|
||||
options.services.queuecube = {
|
||||
enable = lib.mkEnableOption "QueueCube media player service";
|
||||
|
||||
port = lib.mkOption {
|
||||
type = lib.types.port;
|
||||
default = 3000;
|
||||
description = "Port on which QueueCube will listen";
|
||||
};
|
||||
|
||||
enable_video = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
description = "Enable video playback";
|
||||
};
|
||||
|
||||
enable_screenshare = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
description = "Enable screensharing";
|
||||
};
|
||||
|
||||
mpv_ytdl_format = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = "best";
|
||||
description = "yt-dlp format selector passed to mpv. Set to null to use mpv's default format selection.";
|
||||
};
|
||||
|
||||
store_path = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "/var/tmp/queuecube";
|
||||
description = "Path to the store for QueueCube";
|
||||
};
|
||||
|
||||
invidious = lib.mkOption {
|
||||
type = lib.types.submodule {
|
||||
options = {
|
||||
enable = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
description = "Enable Invidious";
|
||||
};
|
||||
|
||||
url = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "http://invidious.nor";
|
||||
description = "URL of the Invidious instance to use";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
default = {
|
||||
enable = false;
|
||||
url = "http://invidious.nor";
|
||||
};
|
||||
};
|
||||
|
||||
user = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = "User account under which QueueCube runs (required)";
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
users.users.${cfg.user} = {
|
||||
packages = [ package ];
|
||||
};
|
||||
|
||||
systemd.user.services.queuecube = {
|
||||
description = "QueueCube media player service";
|
||||
wantedBy = [ "default.target" ];
|
||||
after = [ "pipewire.service" "pipewire-pulse.service" ];
|
||||
|
||||
serviceConfig = {
|
||||
ExecStart = "${package}/bin/queuecube";
|
||||
Restart = "on-failure";
|
||||
RestartSec = 5;
|
||||
|
||||
# Remove all resource limits for mpv to function properly
|
||||
LimitNOFILE = "infinity"; # No limit on file descriptors
|
||||
LimitMEMLOCK = "infinity"; # No limit on locked memory (for real-time audio)
|
||||
LimitNPROC = "infinity"; # No limit on number of processes
|
||||
LimitAS = "infinity"; # No limit on address space
|
||||
LimitRSS = "infinity"; # No limit on resident set size
|
||||
LimitCORE = "infinity"; # Allow core dumps for debugging
|
||||
LimitDATA = "infinity"; # No limit on data segment
|
||||
LimitSTACK = "infinity"; # No limit on stack size
|
||||
LimitCPU = "infinity"; # No limit on CPU time
|
||||
LimitRTPRIO = "99"; # Allow real-time priority
|
||||
LimitRTTIME = "infinity"; # No limit on real-time scheduling
|
||||
|
||||
# Nice level for better performance
|
||||
Nice = "-10";
|
||||
|
||||
# Allow access to necessary devices and features
|
||||
PrivateDevices = false;
|
||||
ProtectHome = false;
|
||||
ProtectSystem = false;
|
||||
NoNewPrivileges = false;
|
||||
|
||||
# Environment for X11 and runtime directories
|
||||
Environment = [
|
||||
"DISPLAY=:0"
|
||||
];
|
||||
};
|
||||
|
||||
environment = {
|
||||
PORT = toString cfg.port;
|
||||
ENABLE_VIDEO = if cfg.enable_video then "1" else "0";
|
||||
ENABLE_SCREENSHARE = if cfg.enable_screenshare then "1" else "0";
|
||||
USE_INVIDIOUS = if cfg.invidious.enable then "1" else "0";
|
||||
INVIDIOUS_BASE_URL = cfg.invidious.url;
|
||||
STORE_PATH = cfg.store_path;
|
||||
} // lib.optionalAttrs (cfg.mpv_ytdl_format != null) {
|
||||
MPV_YTDL_FORMAT = cfg.mpv_ytdl_format;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
in
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
queuecube = mkQueuecube pkgs;
|
||||
|
||||
in {
|
||||
packages = {
|
||||
default = queuecube;
|
||||
@@ -177,8 +217,7 @@
|
||||
# Development environment
|
||||
devShells.default = pkgs.mkShell {
|
||||
buildInputs = with pkgs; [
|
||||
nodejs_20
|
||||
nodePackages.npm
|
||||
nodejs
|
||||
mpv
|
||||
yt-dlp
|
||||
pulseaudio
|
||||
|
||||
@@ -28,6 +28,7 @@ export interface PlaylistItem {
|
||||
id: number;
|
||||
playing: boolean | null;
|
||||
metadata?: Metadata;
|
||||
playbackError?: string;
|
||||
}
|
||||
|
||||
export const getDisplayTitle = (item: PlaylistItem): string => {
|
||||
@@ -62,6 +63,7 @@ export enum ServerEvent {
|
||||
FavoritesUpdate = "favorites_update",
|
||||
MetadataUpdate = "metadata_update",
|
||||
MPDUpdate = "mpd_update",
|
||||
PlaybackError = "playback_error",
|
||||
ScreenShare = "screen_share",
|
||||
}
|
||||
|
||||
|
||||
@@ -199,6 +199,7 @@ const App: React.FC = () => {
|
||||
case ServerEvent.NowPlayingUpdate:
|
||||
case ServerEvent.MetadataUpdate:
|
||||
case ServerEvent.MPDUpdate:
|
||||
case ServerEvent.PlaybackError:
|
||||
fetchPlaylist();
|
||||
fetchNowPlaying();
|
||||
break;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import classNames from 'classnames';
|
||||
import React, { useState, useRef, useEffect, ReactNode } from 'react';
|
||||
import { FaPlay, FaVolumeUp, FaVolumeOff } from 'react-icons/fa';
|
||||
import { FaPlay, FaVolumeUp, FaVolumeOff, FaExclamationTriangle } from 'react-icons/fa';
|
||||
import { getDisplayTitle, PlaylistItem } from '../api/player';
|
||||
|
||||
export enum PlayState {
|
||||
@@ -19,6 +19,7 @@ export interface SongRowProps {
|
||||
|
||||
const SongRow: React.FC<SongRowProps> = ({ song, auxControl, playState, onDelete, onPlay }) => {
|
||||
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false);
|
||||
const [showErrorDetails, setShowErrorDetails] = useState(false);
|
||||
const buttonRef = useRef<HTMLButtonElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -38,6 +39,7 @@ const SongRow: React.FC<SongRowProps> = ({ song, auxControl, playState, onDelete
|
||||
}, [showDeleteConfirm]);
|
||||
|
||||
const displayTitle = getDisplayTitle(song);
|
||||
const hasError = !!song.playbackError;
|
||||
|
||||
return (
|
||||
<div className={classNames(
|
||||
@@ -46,16 +48,46 @@ const SongRow: React.FC<SongRowProps> = ({ song, auxControl, playState, onDelete
|
||||
"bg-black/30": playState === PlayState.NotPlaying,
|
||||
})}>
|
||||
<div className="flex flex-row gap-2">
|
||||
<div className="relative">
|
||||
<button
|
||||
className="text-white/40 hover:text-white transition-colors px-3 py-1 rounded"
|
||||
onClick={onPlay}
|
||||
className={classNames(
|
||||
"transition-colors px-3 py-1 rounded",
|
||||
hasError ? "text-amber-300 hover:text-amber-100" : "text-white/40 hover:text-white"
|
||||
)}
|
||||
onClick={() => {
|
||||
if (hasError) {
|
||||
setShowErrorDetails((prev) => !prev);
|
||||
} else {
|
||||
onPlay();
|
||||
}
|
||||
}}
|
||||
onMouseEnter={() => {
|
||||
if (hasError) {
|
||||
setShowErrorDetails(true);
|
||||
}
|
||||
}}
|
||||
onMouseLeave={() => {
|
||||
if (hasError) {
|
||||
setShowErrorDetails(false);
|
||||
}
|
||||
}}
|
||||
title={hasError ? song.playbackError : undefined}
|
||||
>
|
||||
{
|
||||
hasError ? <FaExclamationTriangle size={12} /> :
|
||||
playState === PlayState.Playing ? <FaVolumeUp size={12} />
|
||||
: playState === PlayState.Paused ? <FaVolumeOff size={12} />
|
||||
: <FaPlay size={12} />
|
||||
}
|
||||
</button>
|
||||
|
||||
{hasError && showErrorDetails && (
|
||||
<div className="absolute z-10 top-full left-0 mt-1 w-64 p-2 text-xs text-white bg-red-600/90 rounded shadow-lg">
|
||||
<div className="font-semibold mb-1">Playback error</div>
|
||||
<div className="break-words">{song.playbackError}</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex-grow min-w-0">
|
||||
|
||||
Reference in New Issue
Block a user