Skip to content

Commit

Permalink
Merge pull request #73 from gnattu/fix-migration
Browse files Browse the repository at this point in the history
Fix migration logic
  • Loading branch information
anthonylavado authored May 13, 2024
2 parents 0c6e1b0 + 87fb95b commit 009cdb0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Jellyfin Server/ActionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ enum ActionManager {
}

static func showLogs() {
let logFolder = applicationSupportJellyfinFolder.appendingPathComponent("/log")
let logFolder = directoryExists(path: localShareJellyfinFolder.path) ? localShareJellyfinFolder.appendingPathComponent("/log") : applicationSupportJellyfinFolder.appendingPathComponent("/log")
NSWorkspace.shared.selectFile(nil, inFileViewerRootedAtPath: logFolder.path)
}

Expand Down
39 changes: 7 additions & 32 deletions Jellyfin Server/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_: Notification) {
statusItem.button?.image = NSImage(named: "StatusBarButtonImage")

createAppFolder()
startJellyfinTask()
createStatusBarMenu()
}
Expand All @@ -28,36 +27,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
jellyfinProcess.waitUntilExit()
}

private func createAppFolder() {
// Old contents were stored in ~/.local/share
// Move to ~/Library/Application Support/Jellyfin
if directoryExists(path: localShareJellyfinFolder.path) {
do {
let contents = try FileManager.default.contentsOfDirectory(atPath: localShareJellyfinFolder.path)

for contentName in contents {
let oldPath = localShareJellyfinFolder.appendingPathComponent(contentName)
let newPath = applicationSupportJellyfinFolder.appendingPathComponent(contentName)
try FileManager.default.moveItem(atPath: oldPath.path,
toPath: newPath.path)
}

try FileManager.default.removeItem(atPath: localShareJellyfinFolder.path)
} catch {
present(alert: "Jellyfin Server was unable to properly migrate old directories.")
}
}

if !directoryExists(path: applicationSupportJellyfinFolder.path) {
do {
try FileManager.default.createDirectory(atPath: applicationSupportJellyfinFolder.path,
withIntermediateDirectories: true)
} catch {
present(alert: "Jellyfin Server was unable to properly create necessary directories.")
}
}
}

private func startJellyfinTask() {
let jellyfinPath = Bundle.main.path(forAuxiliaryExecutable: "jellyfin")
let ffmpegPath = Bundle.main.path(forAuxiliaryExecutable: "ffmpeg")
Expand All @@ -74,7 +43,13 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}

jellyfinProcess.launchPath = jellyfinPath
jellyfinProcess.arguments = ["--webdir", webUIPath, "--ffmpeg", ffmpegPath, "--datadir", applicationSupportJellyfinFolder.path]
jellyfinProcess.arguments = ["--webdir", webUIPath, "--ffmpeg", ffmpegPath, "--datadir"]

if directoryExists(path: localShareJellyfinFolder.path) {
jellyfinProcess.arguments?.append(localShareJellyfinFolder.path)
} else {
jellyfinProcess.arguments?.append(applicationSupportJellyfinFolder.path)
}

do {
try jellyfinProcess.run()
Expand Down

0 comments on commit 009cdb0

Please sign in to comment.