Skip to content

Commit 7aff2a3

Browse files
committed
Added UTType definitions for file formats
1 parent dc3a76d commit 7aff2a3

File tree

6 files changed

+88
-1
lines changed

6 files changed

+88
-1
lines changed

Demos/Subtitle Viewer/Subtitle Viewer/DocumentController.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Foundation
99
import AppKit
1010
import SwiftUI
1111

12+
import UniformTypeIdentifiers
1213
import SwiftSubtitles
1314

1415
/// Note that this is instantiated in the Storyboard
@@ -25,7 +26,18 @@ class DocumentController: NSDocumentController {
2526
openPanel.allowsMultipleSelection = false
2627
openPanel.canChooseFiles = true
2728
openPanel.canChooseDirectories = false
28-
openPanel.allowedFileTypes = ["srt", "sub", "vtt", "sbv", "csv", "json"]
29+
30+
openPanel.allowedContentTypes = [
31+
UTType.srt,
32+
UTType.sub,
33+
UTType.vtt,
34+
UTType.sbv,
35+
UTType.commaSeparatedText,
36+
UTType.json,
37+
UTType.lrc
38+
]
39+
40+
//openPanel.allowedFileTypes = ["srt", "sub", "vtt", "sbv", "csv", "json", "lrc"]
2941

3042
openPanel.accessoryView = a.view
3143
openPanel.delegate = openAccessory

Demos/Subtitle Viewer/Subtitle Viewer/Info.plist

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,20 @@
8888
<key>NSDocumentClass</key>
8989
<string>$(PRODUCT_MODULE_NAME).Document</string>
9090
</dict>
91+
<dict>
92+
<key>CFBundleTypeName</key>
93+
<string>Lyrics file</string>
94+
<key>CFBundleTypeRole</key>
95+
<string>Viewer</string>
96+
<key>LSHandlerRank</key>
97+
<string>Default</string>
98+
<key>LSItemContentTypes</key>
99+
<array>
100+
<string>public.lrc</string>
101+
</array>
102+
<key>NSDocumentClass</key>
103+
<string>$(PRODUCT_MODULE_NAME).Document</string>
104+
</dict>
91105
</array>
92106
<key>UTImportedTypeDeclarations</key>
93107
<array>
@@ -205,6 +219,27 @@
205219
</array>
206220
</dict>
207221
</dict>
222+
<dict>
223+
<key>UTTypeConformsTo</key>
224+
<array>
225+
<string>public.plain-text</string>
226+
</array>
227+
<key>UTTypeDescription</key>
228+
<string>Lyrics file</string>
229+
<key>UTTypeIcons</key>
230+
<dict/>
231+
<key>UTTypeIdentifier</key>
232+
<string>public.lrc</string>
233+
<key>UTTypeReferenceURL</key>
234+
<string>https://en.wikipedia.org/wiki/LRC_(file_format)</string>
235+
<key>UTTypeTagSpecification</key>
236+
<dict>
237+
<key>public.filename-extension</key>
238+
<array>
239+
<string>lrc</string>
240+
</array>
241+
</dict>
242+
</dict>
208243
</array>
209244
</dict>
210245
</plist>

Sources/SwiftSubtitles/coding/PodcastsIndex.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@
2828

2929
import Foundation
3030

31+
#if canImport(UniformTypeIdentifiers)
32+
import UniformTypeIdentifiers
33+
@available(macOS 11.0, iOS 14, tvOS 14, watchOS 7, *)
34+
extension UTType {
35+
public static var podcastsIndex: UTType {
36+
UTType(importedAs: "public.podcastsindex", conformingTo: .json)
37+
}
38+
}
39+
#endif
40+
3141
extension Subtitles.Coder {
3242
/// A [Podcast Index Transcript](https://github.com/Podcastindex-org/podcast-namespace/blob/main/transcripts/transcripts.md#json) encoder/decoder
3343
public struct PodcastsIndex: SubtitlesCodable, SubtitlesTextCodable, Codable {

Sources/SwiftSubtitles/coding/SBV.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@
2727
import DSFRegex
2828
import Foundation
2929

30+
#if canImport(UniformTypeIdentifiers)
31+
import UniformTypeIdentifiers
32+
@available(macOS 11.0, iOS 14, tvOS 14, watchOS 7, *)
33+
extension UTType {
34+
public static var sbv: UTType {
35+
UTType(importedAs: "public.sbv", conformingTo: .plainText)
36+
}
37+
}
38+
#endif
39+
3040
extension Subtitles.Coder {
3141
/// SBV (SubViewer) decoder/encoder
3242
///

Sources/SwiftSubtitles/coding/SUB.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@
2626

2727
import Foundation
2828

29+
#if canImport(UniformTypeIdentifiers)
30+
import UniformTypeIdentifiers
31+
@available(macOS 11.0, iOS 14, tvOS 14, watchOS 7, *)
32+
extension UTType {
33+
public static var sub: UTType {
34+
UTType(importedAs: "public.microdvd.sub", conformingTo: .plainText)
35+
}
36+
}
37+
#endif
38+
2939
public extension Subtitles.Coder {
3040
/// SUB (MicroDVD) decoder/encoder
3141
///

Sources/SwiftSubtitles/coding/VTT.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@
2727
import DSFRegex
2828
import Foundation
2929

30+
#if canImport(UniformTypeIdentifiers)
31+
import UniformTypeIdentifiers
32+
@available(macOS 11.0, iOS 14, tvOS 14, watchOS 7, *)
33+
extension UTType {
34+
public static var vtt: UTType {
35+
UTType(importedAs: "org.w3.webvtt", conformingTo: .plainText)
36+
}
37+
}
38+
#endif
39+
3040
extension Subtitles.Coder {
3141
/// VTT (WebVTT) decoder/Encoder
3242
///

0 commit comments

Comments
 (0)