mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-27 15:14:33 +00:00
Fix: Migrations
This commit is contained in:
parent
471fb6723e
commit
be152c1531
41 changed files with 2373 additions and 1321 deletions
|
|
@ -26,13 +26,6 @@ struct AppIcons {
|
|||
return getIcon(file: path)
|
||||
}
|
||||
|
||||
func getIcon(application: String) -> NSImage? {
|
||||
guard let path = NSWorkspace.shared.fullPath(forApplication: application)
|
||||
else { return nil }
|
||||
|
||||
return getIcon(file: path)
|
||||
}
|
||||
|
||||
/// Easily read Info.plist as a Dictionary from any bundle by accessing .infoDictionary on Bundle
|
||||
func bundle(forBundleID: String) -> Bundle? {
|
||||
guard let url = NSWorkspace.shared.urlForApplication(withBundleIdentifier: forBundleID)
|
||||
|
|
|
|||
67
DynamicIsland/helpers/MediaChecker.swift
Normal file
67
DynamicIsland/helpers/MediaChecker.swift
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
//
|
||||
// MediaChecker.swift
|
||||
// DynamicIsland
|
||||
//
|
||||
// Created by Alexander on 2025-07-26.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
@MainActor
|
||||
final class MediaChecker: Sendable {
|
||||
private(set) var isNowPlayingDeprecated: Bool = false
|
||||
|
||||
enum MediaCheckerError: Error {
|
||||
case missingResources
|
||||
case processExecutionFailed
|
||||
case timeout
|
||||
}
|
||||
|
||||
func checkDeprecationStatus() async throws -> Bool {
|
||||
guard let scriptURL = Bundle.main.url(forResource: "mediaremote-adapter", withExtension: "pl"),
|
||||
let nowPlayingTestClientPath = Bundle.main.url(forResource: "NowPlayingTestClient", withExtension: nil)?.path,
|
||||
let frameworkPath = Bundle.main.privateFrameworksPath?.appending("/MediaRemoteAdapter.framework")
|
||||
else {
|
||||
throw MediaCheckerError.missingResources
|
||||
}
|
||||
|
||||
let process = Process()
|
||||
process.executableURL = URL(fileURLWithPath: "/usr/bin/perl")
|
||||
process.arguments = [scriptURL.path, frameworkPath, nowPlayingTestClientPath, "test"]
|
||||
let pipe = Pipe()
|
||||
process.standardOutput = pipe
|
||||
|
||||
do {
|
||||
try process.run()
|
||||
} catch {
|
||||
throw MediaCheckerError.processExecutionFailed
|
||||
}
|
||||
|
||||
// Timeout after 10 seconds
|
||||
let result: String = try await withThrowingTaskGroup(of: String?.self) { group in
|
||||
group.addTask {
|
||||
process.waitUntilExit()
|
||||
let data = pipe.fileHandleForReading.readDataToEndOfFile()
|
||||
return String(data: data, encoding: .utf8)
|
||||
}
|
||||
group.addTask {
|
||||
try await Task.sleep(for: .seconds(10))
|
||||
if process.isRunning {
|
||||
process.terminate()
|
||||
}
|
||||
return "0" // Default value if process takes too long
|
||||
}
|
||||
for try await output in group {
|
||||
if let output = output {
|
||||
group.cancelAll()
|
||||
return output
|
||||
}
|
||||
}
|
||||
throw MediaCheckerError.timeout
|
||||
}
|
||||
|
||||
let isDeprecated = result.trimmingCharacters(in: .whitespacesAndNewlines).last == "1"
|
||||
self.isNowPlayingDeprecated = isDeprecated
|
||||
return isDeprecated
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue