mirror of
https://github.com/chrisbenincasa/tunarr.git
synced 2026-04-18 09:03:35 -04:00
fix: bundle and start meilisearch properly on macOS
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,14 @@
|
||||
<?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>SchemeUserState</key>
|
||||
<dict>
|
||||
<key>Tunarr.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>0</integer>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -6,31 +6,64 @@
|
||||
//
|
||||
|
||||
import AppKit
|
||||
import OSLog
|
||||
import SwiftUI
|
||||
|
||||
class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
let bundle = Bundle.main
|
||||
let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "Tunarr Subprocess")
|
||||
var task = Process()
|
||||
|
||||
func applicationDidFinishLaunching(_ notification: Notification) {
|
||||
guard let executablePath = Bundle.main.url(forAuxiliaryExecutable: "tunarr-macos")
|
||||
else {
|
||||
/// TODO: Do a popup here.
|
||||
NSLog("Error: Bundled executable 'tunarr-macos' not found.")
|
||||
logger.error("Error: Bundled executable 'tunarr-macos' not found.")
|
||||
return
|
||||
}
|
||||
|
||||
guard let meilisearchPath = Bundle.main.url(forAuxiliaryExecutable: "meilisearch")
|
||||
else {
|
||||
logger.error("Error: Bundled executable 'meilisearch' not found")
|
||||
return
|
||||
}
|
||||
|
||||
task.executableURL = executablePath
|
||||
var env = ProcessInfo.processInfo.environment
|
||||
env["TUNARR_MEILISEARCH_PATH"] = meilisearchPath.absoluteURL.path()
|
||||
task.currentDirectoryURL = FileManager.default
|
||||
.homeDirectoryForCurrentUser
|
||||
.appendingPathComponent(
|
||||
"Library"
|
||||
).appendingPathComponent("Preferences")
|
||||
.appendingPathComponent("tunarr")
|
||||
task.environment = env
|
||||
logger.info("\(env, privacy: .public)")
|
||||
|
||||
let errorPipe = Pipe()
|
||||
task.standardError = errorPipe
|
||||
|
||||
do {
|
||||
errorPipe.fileHandleForReading.readabilityHandler = { pipe in
|
||||
let data = pipe.availableData
|
||||
if let line = String(data: data, encoding: .utf8) {
|
||||
if line.count > 0 {
|
||||
self.logger.info(
|
||||
"Process stderr: \(line.trimmingCharacters(in: .whitespacesAndNewlines), privacy: .public)"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
try task.run()
|
||||
NSLog("Successfully started Tunarr subprocess.")
|
||||
|
||||
logger.info("Successfully started Tunarr subprocess.")
|
||||
} catch {
|
||||
NSLog("Could not launch Tunarr. Reason: \(error)")
|
||||
logger.error("Could not launch Tunarr. Reason: \(error, privacy: .public)")
|
||||
}
|
||||
}
|
||||
|
||||
func applicationWillTerminate(_ aNotification: Notification) {
|
||||
NSLog("Shutting down Tunarr.")
|
||||
logger.info("Shutting down Tunarr.")
|
||||
task.terminate()
|
||||
task.waitUntilExit()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user