mirror of https://github.com/mpv-player/mpv
mac/menu: merge file and url config properties
a file path is basically an URL. both are also handled as URL objects in our code.
This commit is contained in:
parent
46a9e8c130
commit
8d4329a710
|
@ -35,8 +35,7 @@ extension MenuBar {
|
||||||
let action: Selector?
|
let action: Selector?
|
||||||
let target: AnyObject?
|
let target: AnyObject?
|
||||||
let command: String
|
let command: String
|
||||||
let url: String?
|
let url: String
|
||||||
let file: String?
|
|
||||||
let commandSpecial: MenuKey?
|
let commandSpecial: MenuKey?
|
||||||
var menuItem: MenuItem?
|
var menuItem: MenuItem?
|
||||||
var configs: [Config]?
|
var configs: [Config]?
|
||||||
|
@ -48,8 +47,7 @@ extension MenuBar {
|
||||||
action: Selector? = nil,
|
action: Selector? = nil,
|
||||||
target: AnyObject? = nil,
|
target: AnyObject? = nil,
|
||||||
command: String = "",
|
command: String = "",
|
||||||
url: String? = nil,
|
url: String = "",
|
||||||
file: String? = nil,
|
|
||||||
commandSpecial: MenuKey? = nil,
|
commandSpecial: MenuKey? = nil,
|
||||||
menuItem: MenuItem? = nil,
|
menuItem: MenuItem? = nil,
|
||||||
configs: [Config]? = nil
|
configs: [Config]? = nil
|
||||||
|
@ -61,7 +59,6 @@ extension MenuBar {
|
||||||
self.target = target
|
self.target = target
|
||||||
self.command = command
|
self.command = command
|
||||||
self.url = url
|
self.url = url
|
||||||
self.file = file
|
|
||||||
self.commandSpecial = commandSpecial
|
self.commandSpecial = commandSpecial
|
||||||
self.menuItem = menuItem
|
self.menuItem = menuItem
|
||||||
self.configs = configs
|
self.configs = configs
|
||||||
|
@ -90,13 +87,13 @@ class MenuBar: NSObject {
|
||||||
key: ",",
|
key: ",",
|
||||||
action: #selector(settings(_:)),
|
action: #selector(settings(_:)),
|
||||||
target: self,
|
target: self,
|
||||||
file: "mpv.conf"
|
url: "mpv.conf"
|
||||||
),
|
),
|
||||||
Config(
|
Config(
|
||||||
name: "Keyboard Shortcuts Config…",
|
name: "Keyboard Shortcuts Config…",
|
||||||
action: #selector(settings(_:)),
|
action: #selector(settings(_:)),
|
||||||
target: self,
|
target: self,
|
||||||
file: "input.conf"
|
url: "input.conf"
|
||||||
),
|
),
|
||||||
Config(name: "separator"),
|
Config(name: "separator"),
|
||||||
Config(name: "Services"),
|
Config(name: "Services"),
|
||||||
|
@ -229,7 +226,7 @@ class MenuBar: NSObject {
|
||||||
name: "Show log File…",
|
name: "Show log File…",
|
||||||
action: #selector(showFile(_:)),
|
action: #selector(showFile(_:)),
|
||||||
target: self,
|
target: self,
|
||||||
file: NSHomeDirectory() + "/Library/Logs/mpv.log"
|
url: NSHomeDirectory() + "/Library/Logs/mpv.log"
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -296,27 +293,26 @@ class MenuBar: NSObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func settings(_ menuItem: MenuItem) {
|
@objc func settings(_ menuItem: MenuItem) {
|
||||||
guard let menuConfig = menuItem.config,
|
guard let menuConfig = menuItem.config else { return }
|
||||||
let fileName = menuConfig.file else { return }
|
|
||||||
let configPaths: [URL] = [
|
let configPaths: [URL] = [
|
||||||
URL(fileURLWithPath: NSHomeDirectory() + "/.config/mpv/", isDirectory: true),
|
URL(fileURLWithPath: NSHomeDirectory() + "/.config/mpv/", isDirectory: true),
|
||||||
URL(fileURLWithPath: NSHomeDirectory() + "/.mpv/", isDirectory: true),
|
URL(fileURLWithPath: NSHomeDirectory() + "/.mpv/", isDirectory: true),
|
||||||
]
|
]
|
||||||
|
|
||||||
for path in configPaths {
|
for path in configPaths {
|
||||||
let configFile = path.appendingPathComponent(fileName, isDirectory: false)
|
let configFile = path.appendingPathComponent(menuConfig.url, isDirectory: false)
|
||||||
|
|
||||||
if FileManager.default.fileExists(atPath: configFile.path) {
|
if FileManager.default.fileExists(atPath: configFile.path) {
|
||||||
if NSWorkspace.shared.open(configFile) {
|
if NSWorkspace.shared.open(configFile) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
NSWorkspace.shared.open(path)
|
NSWorkspace.shared.open(path)
|
||||||
alert(title: "No Application found to open your config file.", text: "Please open the \(fileName) file with your preferred text editor in the now open folder to edit your config.")
|
alert(title: "No Application found to open your config file.", text: "Please open the \(menuConfig.url) file with your preferred text editor in the now open folder to edit your config.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if NSWorkspace.shared.open(path) {
|
if NSWorkspace.shared.open(path) {
|
||||||
alert(title: "No config file found.", text: "Please create a \(fileName) file with your preferred text editor in the now open folder.")
|
alert(title: "No config file found.", text: "Please create a \(menuConfig.url) file with your preferred text editor in the now open folder.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -378,13 +374,13 @@ class MenuBar: NSObject {
|
||||||
|
|
||||||
@objc func url(_ menuItem: MenuItem) {
|
@objc func url(_ menuItem: MenuItem) {
|
||||||
guard let menuConfig = menuItem.config,
|
guard let menuConfig = menuItem.config,
|
||||||
let url = URL(string: menuConfig.url ?? "") else { return }
|
let url = URL(string: menuConfig.url) else { return }
|
||||||
NSWorkspace.shared.open(url)
|
NSWorkspace.shared.open(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func showFile(_ menuItem: MenuItem) {
|
@objc func showFile(_ menuItem: MenuItem) {
|
||||||
guard let menuConfig = menuItem.config else { return }
|
guard let menuConfig = menuItem.config else { return }
|
||||||
let url = URL(fileURLWithPath: menuConfig.file ?? "")
|
let url = URL(fileURLWithPath: menuConfig.url)
|
||||||
if FileManager.default.fileExists(atPath: url.path) {
|
if FileManager.default.fileExists(atPath: url.path) {
|
||||||
NSWorkspace.shared.activateFileViewerSelecting([url])
|
NSWorkspace.shared.activateFileViewerSelecting([url])
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue