Skip to content

Commit

Permalink
Open Realm database file
Browse files Browse the repository at this point in the history
  • Loading branch information
luosheng committed May 7, 2017
1 parent 9ae6bb7 commit e554a3d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion OpenSim/ExtraApplicationActionable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protocol ExtraApplicationActionable: ApplicationActionable {

extension ExtraApplicationActionable {

private var appPath: String? {
var appPath: String? {
return NSWorkspace.shared().absolutePathForApplication(withBundleIdentifier: appBundleIdentifier)
}

Expand Down
21 changes: 19 additions & 2 deletions OpenSim/OpenRealmAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,33 @@ final class OpenRealmAction: ExtraApplicationActionable {

var application: Application?

let appBundleIdentifier = "io.realm.Realm-Browser"
let appBundleIdentifier = "io.realm.realmbrowser"

let title = "Open Realm Database"

var isAvailable: Bool {
return appPath != nil && realmPath != nil
}

var realmPath: String?

init(application: Application) {
self.application = application

if let sandboxUrl = application.sandboxUrl,
let enumerator = FileManager.default.enumerator(at: sandboxUrl, includingPropertiesForKeys: nil) {
while let fileUrl = enumerator.nextObject() as? URL {
if fileUrl.pathExtension.lowercased() == "realm" {
realmPath = fileUrl.path
}
}
}
}

func perform() {

if let realmPath = realmPath {
NSWorkspace.shared().openFile(realmPath, withApplication: "Realm Browser")
}
}

}

0 comments on commit e554a3d

Please sign in to comment.