Use modern UTI API in the save panel

This commit is contained in:
Damiano Galassi committed 2025-09-08 14:38:24 +02:00
1 parent 80e561d88c
commit d78b320322
2 files changed
+31 -5

No files matched your search

+19 -5
View File
@@ -7,6 +7,7 @@
import Cocoa
import MP42Foundation
import UniformTypeIdentifiers
final class SaveOptions: NSViewController {
@@ -46,13 +47,22 @@ final class SaveOptions: NSViewController {
fileFormat.addItem(withTitle: name)
}
fileFormat.selectItem(at: Prefs.defaultSaveFormat)
savePanel?.allowedFileTypes = [Prefs.saveFormat]
let idx = Prefs.defaultSaveFormat > -1 && Prefs.defaultSaveFormat < formats.count ? Prefs.defaultSaveFormat : 1
let format = formats[idx]
fileFormat.selectItem(at: idx)
if let filename = doc.mp4.preferredFileName() {
savePanel?.nameFieldStringValue = filename
}
if #available(macOS 15.0, *) {
let type = UTType(format) ?? .mpeg4Movie
savePanel?.currentContentType = type
} else {
savePanel?.allowedFileTypes = [Prefs.saveFormat]
}
_64bit_data.state = Prefs.mp464bitOffset ? .on : .off
_64bit_time.state = Prefs.mp464bitTimes ? .on : .off
optimize.state = Prefs.mp4SaveAsOptimize ? .on : .off
@@ -62,8 +72,7 @@ final class SaveOptions: NSViewController {
}
}
func saveUserDefaults()
{
func saveUserDefaults() {
Prefs.defaultSaveFormat = fileFormat.indexOfSelectedItem
Prefs.mp464bitOffset = _64bit_data.state == .on
Prefs.mp464bitTimes = _64bit_time.state == .on
@@ -91,7 +100,12 @@ final class SaveOptions: NSViewController {
default:
break
}
savePanel?.allowedFileTypes = [requiredFileType]
if #available(macOS 15.0, *) {
let type = UTType(filenameExtension: requiredFileType) ?? .mpeg4Movie
savePanel?.currentContentType = type
} else {
savePanel?.allowedFileTypes = [requiredFileType]
}
Prefs.saveFormat = requiredFileType
}
}
+12
View File
@@ -25,6 +25,10 @@
<string>SBDocument</string>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>mp4</string>
</array>
<key>CFBundleTypeName</key>
<string>Movie-MPEG4</string>
<key>CFBundleTypeRole</key>
@@ -39,6 +43,10 @@
<string>SBDocument</string>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>m4a</string>
</array>
<key>CFBundleTypeName</key>
<string>Audio-MPEG4</string>
<key>CFBundleTypeRole</key>
@@ -53,6 +61,10 @@
<string>SBDocument</string>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>m4b</string>
</array>
<key>CFBundleTypeName</key>
<string>Audiobook</string>
<key>CFBundleTypeRole</key>