Skip to content

Commit e554a3d

Browse files
committed
Open Realm database file
#24
1 parent 9ae6bb7 commit e554a3d

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

OpenSim/ExtraApplicationActionable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ protocol ExtraApplicationActionable: ApplicationActionable {
1616

1717
extension ExtraApplicationActionable {
1818

19-
private var appPath: String? {
19+
var appPath: String? {
2020
return NSWorkspace.shared().absolutePathForApplication(withBundleIdentifier: appBundleIdentifier)
2121
}
2222

OpenSim/OpenRealmAction.swift

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,33 @@ final class OpenRealmAction: ExtraApplicationActionable {
1212

1313
var application: Application?
1414

15-
let appBundleIdentifier = "io.realm.Realm-Browser"
15+
let appBundleIdentifier = "io.realm.realmbrowser"
1616

1717
let title = "Open Realm Database"
1818

19+
var isAvailable: Bool {
20+
return appPath != nil && realmPath != nil
21+
}
22+
23+
var realmPath: String?
24+
1925
init(application: Application) {
2026
self.application = application
27+
28+
if let sandboxUrl = application.sandboxUrl,
29+
let enumerator = FileManager.default.enumerator(at: sandboxUrl, includingPropertiesForKeys: nil) {
30+
while let fileUrl = enumerator.nextObject() as? URL {
31+
if fileUrl.pathExtension.lowercased() == "realm" {
32+
realmPath = fileUrl.path
33+
}
34+
}
35+
}
2136
}
2237

2338
func perform() {
24-
39+
if let realmPath = realmPath {
40+
NSWorkspace.shared().openFile(realmPath, withApplication: "Realm Browser")
41+
}
2542
}
2643

2744
}

0 commit comments

Comments
 (0)