forked from quoid/userscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtilities.swift
More file actions
53 lines (49 loc) · 1.36 KB
/
Copy pathUtilities.swift
File metadata and controls
53 lines (49 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import SwiftUI
import os.log
func USLogger(_ category: String) -> Logger? {
let subsystem = Bundle.main.bundleIdentifier!
#if DEBUG // Always enable logger in DEBUG builds
return Logger(subsystem: subsystem, category: category)
#else
if Preferences.enableLogger {
return Logger(subsystem: subsystem, category: category)
}
return nil
#endif
}
func getDocumentsDirectory() -> URL {
let fm = FileManager.default
let paths = fm.urls(for: .documentDirectory, in: .userDomainMask)
let documentsDirectory = paths[0]
return documentsDirectory
}
func directoryExists(path: String) -> Bool {
var isDirectory = ObjCBool(true)
let exists = FileManager.default.fileExists(atPath: path, isDirectory: &isDirectory)
let inTrash = path.contains(".Trash") ? false : true
return exists && inTrash && isDirectory.boolValue
}
func getPlatform() -> String {
#if os(macOS)
return "macos"
#elseif os(iOS)
// https://developer.apple.com/documentation/uikit/uiuserinterfaceidiom
// There is no reliable way to detect visionOS for now, will match `.phone` in Apple Vision (Designed for iPad) mode
switch UIDevice.current.userInterfaceIdiom {
case .phone:
return "ios"
case .pad, .mac:
return "ipados"
case .vision:
return "visionos"
case .tv:
return "tvos"
case .carPlay:
return "carplay"
case .unspecified:
return "unspecified"
@unknown default:
return "unknown"
}
#endif
}