add migration

This commit is contained in:
Ethan Pippin 2022-08-08 21:54:56 -06:00
parent f608b5e65f
commit 596470d9bc
4 changed files with 67 additions and 32 deletions

View File

@ -11,6 +11,7 @@
0919395722C35C1400392D55 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0919395622C35C1400392D55 /* Assets.xcassets */; };
0919395A22C35C1400392D55 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0919395822C35C1400392D55 /* Main.storyboard */; };
0924531822D5BC7E00B2E710 /* ffmpeg LICENSE.txt in Resources */ = {isa = PBXBuildFile; fileRef = 0924531622D5BC7E00B2E710 /* ffmpeg LICENSE.txt */; };
E1293F4B28A2059B0076A445 /* Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1293F4A28A2059B0076A445 /* Helpers.swift */; };
E174A306289B755C0092450E /* LaunchAtLogin in Frameworks */ = {isa = PBXBuildFile; productRef = E174A305289B755C0092450E /* LaunchAtLogin */; };
E174A312289B84F90092450E /* PreferencesViewController.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E174A311289B84F90092450E /* PreferencesViewController.storyboard */; };
E174A314289B855C0092450E /* PreferencesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E174A313289B855C0092450E /* PreferencesViewController.swift */; };
@ -41,6 +42,7 @@
0924531622D5BC7E00B2E710 /* ffmpeg LICENSE.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "ffmpeg LICENSE.txt"; sourceTree = "<group>"; };
09A23D5B2468FB9B0071B5A9 /* Jellyfin Server.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Jellyfin Server.app"; sourceTree = BUILT_PRODUCTS_DIR; };
09A23D5C2468FBAB0071B5A9 /* Server.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Server.entitlements; sourceTree = "<group>"; };
E1293F4A28A2059B0076A445 /* Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Helpers.swift; sourceTree = "<group>"; };
E174A311289B84F90092450E /* PreferencesViewController.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = PreferencesViewController.storyboard; sourceTree = "<group>"; };
E174A313289B855C0092450E /* PreferencesViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesViewController.swift; sourceTree = "<group>"; };
E174A317289B86820092450E /* PreferencesWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesWindow.swift; sourceTree = "<group>"; };
@ -74,14 +76,15 @@
0919395122C35C1400392D55 /* Jellyfin Server */ = {
isa = PBXGroup;
children = (
09A23D5C2468FBAB0071B5A9 /* Server.entitlements */,
0919395222C35C1400392D55 /* AppDelegate.swift */,
E174A31A289B8D700092450E /* ActionManager.swift */,
0919395222C35C1400392D55 /* AppDelegate.swift */,
E1293F4A28A2059B0076A445 /* Helpers.swift */,
E174A320289B926C0092450E /* AlertWindow */,
E174A319289B8D520092450E /* PreferencesWindow */,
0919395622C35C1400392D55 /* Assets.xcassets */,
0919395822C35C1400392D55 /* Main.storyboard */,
0919395B22C35C1400392D55 /* Info.plist */,
0919395822C35C1400392D55 /* Main.storyboard */,
09A23D5C2468FBAB0071B5A9 /* Server.entitlements */,
);
path = "Jellyfin Server";
sourceTree = "<group>";
@ -195,6 +198,7 @@
buildActionMask = 2147483647;
files = (
E19E5327289B932300A94983 /* AlertWindow.swift in Sources */,
E1293F4B28A2059B0076A445 /* Helpers.swift in Sources */,
0919395322C35C1400392D55 /* AppDelegate.swift in Sources */,
E174A318289B86820092450E /* PreferencesWindow.swift in Sources */,
E174A314289B855C0092450E /* PreferencesViewController.swift in Sources */,
@ -340,7 +344,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = TY84JMYEFE;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = "Jellyfin Server/Info.plist";
LD_RUNPATH_SEARCH_PATHS = (
@ -364,7 +368,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = TY84JMYEFE;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = "Jellyfin Server/Info.plist";
LD_RUNPATH_SEARCH_PATHS = (

View File

@ -11,17 +11,12 @@ import AppKit
enum ActionManager {
static let shareFolder: URL = {
FileManager.default.homeDirectoryForCurrentUser
.appendingPathComponent(".local/share")
}()
static func launchWebUI() {
NSWorkspace.shared.open(.init(string: "http://localhost:8096")!)
}
static func showLogs() {
let logFolder = shareFolder.appendingPathComponent("jellyfin/log")
let logFolder = applicationSupportJellyfinFolder.appendingPathComponent("/log")
NSWorkspace.shared.selectFile(nil, inFileViewerRootedAtPath: logFolder.path)
}

View File

@ -25,24 +25,36 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
func applicationWillTerminate(_ aNotification: Notification) {
print("app will terminate received")
jellyfinProcess.terminate()
jellyfinProcess.waitUntilExit()
}
private func createAppFolder() {
var isDirectory: ObjCBool = false
let shareFolderExists = FileManager.default.fileExists(atPath: ActionManager.shareFolder.path,
isDirectory: &isDirectory)
if !shareFolderExists || !isDirectory.boolValue {
// Old contents were stored in ~/.local/share
// Move to ~/Library/Application Support/Jellyfin
if directoryExists(path: localShareJellyfinFolder.path) {
do {
try FileManager.default.createDirectory(at: ActionManager.shareFolder, withIntermediateDirectories: true)
} catch {
let alertWindow = AlertWindow(text: "Jellyfin Server was unable to properly create expected directories.")
let contents = try FileManager.default.contentsOfDirectory(atPath: localShareJellyfinFolder.path)
windowController.window = alertWindow
windowController.showWindow(self)
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.")
}
}
}
@ -52,24 +64,17 @@ class AppDelegate: NSObject, NSApplicationDelegate {
let webUIPath = Bundle.main.resourceURL!.appendingPathComponent("jellyfin-web").path
guard let jellyfinPath = jellyfinPath else {
let alertWindow = AlertWindow(text: "Jellyfin Server was unable to start underlying jellyfin task.")
windowController.window = alertWindow
windowController.showWindow(self)
present(alert: "Jellyfin Server was unable to start underlying jellyfin task.")
return
}
jellyfinProcess.launchPath = jellyfinPath
jellyfinProcess.arguments = ["--webdir", webUIPath]
jellyfinProcess.arguments = ["--webdir", webUIPath, "--cache", applicationSupportJellyfinFolder.path]
do {
try jellyfinProcess.run()
} catch {
let alertWindow = AlertWindow(text: "Jellyfin Server was unable to start underlying jellyfin process.")
windowController.window = alertWindow
windowController.showWindow(self)
present(alert: "Jellyfin Server was unable to start underlying jellyfin process.")
}
}
@ -104,4 +109,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
windowController.window = window
windowController.showWindow(self)
}
private func present(alert: String) {
let alertWindow = AlertWindow(text: alert)
windowController.window = alertWindow
windowController.showWindow(self)
}
}

View File

@ -0,0 +1,24 @@
//
// 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) 2022 Jellyfin & Jellyfin Contributors
//
import Foundation
let localShareJellyfinFolder: URL = {
FileManager.default.homeDirectoryForCurrentUser
.appendingPathComponent(".local/share/jellyfin")
}()
let applicationSupportJellyfinFolder: URL = {
FileManager.default.homeDirectoryForCurrentUser
.appendingPathComponent("/Library/Application Support/jellyfin")
}()
func directoryExists(path: String) -> Bool {
var isDirectory: ObjCBool = false
return FileManager.default.fileExists(atPath: path, isDirectory: &isDirectory)
}