Skip to content

Commit

Permalink
Merge pull request #49 from luosheng/develop
Browse files Browse the repository at this point in the history
Version 0.4.2
  • Loading branch information
luosheng authored Nov 28, 2018
2 parents 0ea85a5 + 61a78c7 commit bc7f767
Show file tree
Hide file tree
Showing 15 changed files with 140 additions and 39 deletions.
45 changes: 41 additions & 4 deletions OpenSim.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
312A27FD21A753E600699668 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 312A27FC21A753E600699668 /* Constants.swift */; };
31A79B15219B81660024DF7B /* Simulator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31A79B14219B81660024DF7B /* Simulator.swift */; };
31C4BF3221A8AC56008B97A1 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 31C4BF3021A8AC56008B97A1 /* Localizable.strings */; };
AF9D003A1D110E750065AFD0 /* Helper.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF9D00391D110E750065AFD0 /* Helper.swift */; };
B3054E181BF381CE00F433C2 /* FileInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3054E161BF381CE00F433C2 /* FileInfo.swift */; };
B3054E1A1BF3958500F433C2 /* DirectoryWatcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3054E191BF3958500F433C2 /* DirectoryWatcher.swift */; };
Expand Down Expand Up @@ -38,7 +40,10 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
312A27FC21A753E600699668 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
31A79B14219B81660024DF7B /* Simulator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Simulator.swift; sourceTree = "<group>"; };
31C4BF3121A8AC56008B97A1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Base; path = Base.lproj/Localizable.strings; sourceTree = "<group>"; };
31C4BF3421A8AC72008B97A1 /* pt-BR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "pt-BR"; path = "pt-BR.lproj/Localizable.strings"; sourceTree = "<group>"; };
AF9D00391D110E750065AFD0 /* Helper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Helper.swift; sourceTree = "<group>"; };
B3054E161BF381CE00F433C2 /* FileInfo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileInfo.swift; sourceTree = "<group>"; };
B3054E191BF3958500F433C2 /* DirectoryWatcher.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DirectoryWatcher.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -81,6 +86,25 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
31C4BF2321A8AA3D008B97A1 /* AppDelegate */ = {
isa = PBXGroup;
children = (
B3A1E3221BF049690090EC58 /* AppDelegate.swift */,
);
name = AppDelegate;
sourceTree = "<group>";
};
31C4BF2721A8AA52008B97A1 /* Supporting Files */ = {
isa = PBXGroup;
children = (
B3A1E3241BF049690090EC58 /* Assets.xcassets */,
31C4BF3021A8AC56008B97A1 /* Localizable.strings */,
B3A1E3261BF049690090EC58 /* MainMenu.xib */,
B3A1E3291BF049690090EC58 /* Info.plist */,
);
name = "Supporting Files";
sourceTree = "<group>";
};
B36856AC1CA41BA8009BE4CC /* Models */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -117,6 +141,7 @@
B39B2B601EBEF1A100CDD74C /* AppMenuItem.swift */,
B32480541EBEB705000633FC /* ActionMenu.swift */,
B39B2B621EBEFFB700CDD74C /* AppInfoView.swift */,
312A27FC21A753E600699668 /* Constants.swift */,
);
name = UI;
sourceTree = "<group>";
Expand Down Expand Up @@ -153,14 +178,12 @@
B3A1E3211BF049690090EC58 /* OpenSim */ = {
isa = PBXGroup;
children = (
B3A1E3221BF049690090EC58 /* AppDelegate.swift */,
31C4BF2321A8AA3D008B97A1 /* AppDelegate */,
B36856AC1CA41BA8009BE4CC /* Models */,
B39B2B6D1EBF511200CDD74C /* Actions */,
B36856AD1CA41BCB009BE4CC /* Utilities */,
B36856AE1CA41BD4009BE4CC /* UI */,
B3A1E3241BF049690090EC58 /* Assets.xcassets */,
B3A1E3261BF049690090EC58 /* MainMenu.xib */,
B3A1E3291BF049690090EC58 /* Info.plist */,
31C4BF2721A8AA52008B97A1 /* Supporting Files */,
);
path = OpenSim;
sourceTree = "<group>";
Expand Down Expand Up @@ -208,6 +231,7 @@
knownRegions = (
en,
Base,
"pt-BR",
);
mainGroup = B3A1E3161BF049690090EC58;
productRefGroup = B3A1E3201BF049690090EC58 /* Products */;
Expand All @@ -225,6 +249,7 @@
buildActionMask = 2147483647;
files = (
B3A1E3251BF049690090EC58 /* Assets.xcassets in Resources */,
31C4BF3221A8AC56008B97A1 /* Localizable.strings in Resources */,
B3A1E3281BF049690090EC58 /* MainMenu.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -256,6 +281,7 @@
B39B2B671EBF0D0600CDD74C /* LaunchAtLoginHelper.swift in Sources */,
B39B2B631EBEFFB700CDD74C /* AppInfoView.swift in Sources */,
B3A1E3301BF05F980090EC58 /* DeviceManager.swift in Sources */,
312A27FD21A753E600699668 /* Constants.swift in Sources */,
B3A1E3231BF049690090EC58 /* AppDelegate.swift in Sources */,
B39B2B6F1EBF567F00CDD74C /* CopyToPasteboardAction.swift in Sources */,
B39B2B731EBF573C00CDD74C /* UninstallAction.swift in Sources */,
Expand All @@ -268,6 +294,15 @@
/* End PBXSourcesBuildPhase section */

/* Begin PBXVariantGroup section */
31C4BF3021A8AC56008B97A1 /* Localizable.strings */ = {
isa = PBXVariantGroup;
children = (
31C4BF3121A8AC56008B97A1 /* Base */,
31C4BF3421A8AC72008B97A1 /* pt-BR */,
);
name = Localizable.strings;
sourceTree = "<group>";
};
B3A1E3261BF049690090EC58 /* MainMenu.xib */ = {
isa = PBXVariantGroup;
children = (
Expand All @@ -283,6 +318,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
Expand Down Expand Up @@ -338,6 +374,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
Expand Down
6 changes: 3 additions & 3 deletions OpenSim/ActionMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ final class ActionMenu: NSMenu {
private func buildMenuItems() {
let createAction: (ApplicationActionable.Type) -> ApplicationActionable = { $0.init(application: self.application) }

self.buildMenuSection(title: NSLocalizedString("Actions", comment: ""), actions: ActionMenu.standardActions.map(createAction))
self.buildMenuSection(title: NSLocalizedString("Extensions", comment: ""), actions: ActionMenu.extraActions.map(createAction))
self.addItem(self.buildSectionTitle(title: NSLocalizedString("App Information", comment: "")))
self.buildMenuSection(title: UIConstants.strings.menuHeaderActions, actions: ActionMenu.standardActions.map(createAction))
self.buildMenuSection(title: UIConstants.strings.menuHeaderExtensions, actions: ActionMenu.extraActions.map(createAction))
self.addItem(self.buildSectionTitle(title: UIConstants.strings.menuHeaderAppInformation))
self.addItem(appInfoItem)
}

Expand Down
4 changes: 2 additions & 2 deletions OpenSim/AppInfoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ final class AppInfoView: NSView {
sizeDescription = ByteCountFormatter.string(fromByteCount: Int64(size), countStyle: .file)
}
let string = "\(application.bundleID)\n" +
"Version: \(application.bundleVersion) (\(application.bundleShortVersion))\n" +
"Size: \(sizeDescription)"
"\(UIConstants.strings.appInfoVersion): \(application.bundleVersion) (\(application.bundleShortVersion))\n" +
"\(UIConstants.strings.appInfoSize): \(sizeDescription)"
textField.stringValue = string
}

Expand Down
16 changes: 7 additions & 9 deletions OpenSim/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,14 @@ final class Application {
block(size)
} else {
Application.sizeDispatchQueue.async {
var size: UInt64 = 0
let filesEnumerator = FileManager.default.enumerator(at: self.url, includingPropertiesForKeys: nil, options: [], errorHandler: { (url, error) -> Bool in
return true
})
while let fileUrl = filesEnumerator?.nextObject() as? URL {
let attributes = try? FileManager.default.attributesOfItem(atPath: fileUrl.path) as NSDictionary
size += attributes?.fileSize() ?? 0
let duResult = shell("/usr/bin/du", arguments: ["-sk", self.url.path])
let stringBytes = String(duResult.split(separator: "\t").first ?? "")
var bytes: UInt64 = 0
if let kbytes = UInt64(stringBytes) {
bytes = kbytes * 1000
self.size = bytes;
}
self.size = size
block(size)
block(bytes)
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions OpenSim/Base.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"Menu.Quit" = "Quit";
"Menu.LaunchAtLogin" = "Launch at Login";
"Menu.Refresh" = "Refresh";
"Menu.Version" = "Version";
"Action.RevealInFinder" = "Reveal Sandbox in Finder";
"Action.CopyPathPasteboard" = "Copy Sandbox Path to Pasteboard";
"Action.OpenInTerminal" = "Open Sandbox in Terminal";
"Action.Uninstall" = "Uninstall";
"Action.UninstallAlertConfirmButton" = "Uninstall";
"Action.UninstallAlertCancelButton" = "Cancel";
"Action.UninstallAlertMessage" = "Are you sure you want to uninstall %@ from %@?";
"Extension.OpenInIterm" = "Open Sandbox in iTerm";
"Extension.OpenRealmDatabase" = "Open Realm Database";
"AppInfo.Version" = "Version";
"AppInfo.Size" = "Size";
"MenuHeader.Actions" = "Actions";
"MenuHeader.Extensions" = "Extensions";
"MenuHeader.AppInformation" = "App Information";
26 changes: 26 additions & 0 deletions OpenSim/Constants.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

import Foundation

struct UIConstants {

struct strings {
static let menuQuitButton = NSLocalizedString("Menu.Quit", comment: "Quit menu button")
static let menuLaunchAtLoginButton = NSLocalizedString("Menu.LaunchAtLogin", comment: "Launch at login menu button")
static let menuRefreshButton = NSLocalizedString("Menu.Refresh", comment: "Refresh menu button")
static let menuVersionLabel = NSLocalizedString("Menu.Version", comment: "Version label")
static let actionRevealInFinder = NSLocalizedString("Action.RevealInFinder", comment: "Reveal in Finder label")
static let actionCopyPathPasteboard = NSLocalizedString("Action.CopyPathPasteboard", comment: "Copy Sandbox path to pasteboard label")
static let actionOpenInTerminal = NSLocalizedString("Action.OpenInTerminal", comment: "Open in Terminal label")
static let actionUninstall = NSLocalizedString("Action.Uninstall", comment: "Uninstall label")
static let actionUninstallAlertConfirmButton = NSLocalizedString("Action.UninstallAlertConfirmButton", comment: "Uninstall confirm button")
static let actionUninstallAlertCancelButton = NSLocalizedString("Action.UninstallAlertCancelButton", comment: "Uninstall cancel button")
static let actionUninstallAlertMessage = NSLocalizedString("Action.UninstallAlertMessage", comment: "Uninstall confirmation message")
static let extensionOpenInIterm = NSLocalizedString("Extension.OpenInIterm", comment: "Open in iTerm label")
static let extensionOpenRealmDatabase = NSLocalizedString("Extension.OpenRealmDatabase", comment: "Open Realm Database label")
static let appInfoVersion = NSLocalizedString("AppInfo.Version", comment: "App Info Version Label")
static let appInfoSize = NSLocalizedString("AppInfo.Size", comment: "App Info Size Label")
static let menuHeaderActions = NSLocalizedString("MenuHeader.Actions", comment: "Actions header label")
static let menuHeaderExtensions = NSLocalizedString("MenuHeader.Extensions", comment: "Extensions header label")
static let menuHeaderAppInformation = NSLocalizedString("MenuHeader.AppInformation", comment: "App Information header label")
}
}
2 changes: 1 addition & 1 deletion OpenSim/CopyToPasteboardAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class CopyToPasteboardAction: ApplicationActionable {

var application: Application?

let title = NSLocalizedString("Copy Sandbox Path to Pasteboard", comment: "")
let title = UIConstants.strings.actionCopyPathPasteboard

let icon = templatize(#imageLiteral(resourceName: "share"))

Expand Down
2 changes: 1 addition & 1 deletion OpenSim/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.4.1</string>
<string>0.4.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
25 changes: 15 additions & 10 deletions OpenSim/MenuManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protocol MenuManagerDelegate {
return
}
menu.addItem(NSMenuItem.separator())
let titleItem = NSMenuItem(title: "\(runtime) Simulators", action: nil, keyEquivalent: "")
let titleItem = NSMenuItem(title: "\(runtime)", action: nil, keyEquivalent: "")
titleItem.isEnabled = false
menu.addItem(titleItem)

Expand Down Expand Up @@ -90,29 +90,34 @@ protocol MenuManagerDelegate {
}

menu.addItem(NSMenuItem.separator())

let refreshMenuItem = menu.addItem(withTitle: NSLocalizedString("Refresh", comment: ""), action: #selector(self.refreshItemClicked(_:)), keyEquivalent: "r")
let refreshMenuItem = menu.addItem(withTitle: UIConstants.strings.menuRefreshButton, action: #selector(self.refreshItemClicked(_:)), keyEquivalent: "r")
refreshMenuItem.target = self

let launchAtLoginMenuItem = menu.addItem(withTitle: NSLocalizedString("Launch at Login", comment: ""), action: #selector(self.launchItemClicked(_:)), keyEquivalent: "")
let launchAtLoginMenuItem = menu.addItem(withTitle: UIConstants.strings.menuLaunchAtLoginButton, action: #selector(self.launchItemClicked(_:)), keyEquivalent: "")
launchAtLoginMenuItem.target = self
if existingItem(itemUrl: Bundle.main.bundleURL) != nil {
launchAtLoginMenuItem.state = .on
} else {
launchAtLoginMenuItem.state = .off
}

let quitMenu = menu.addItem(withTitle: NSLocalizedString("Quit", comment: ""), action: #selector(self.quitItemClicked(_:)), keyEquivalent: "q")
let quitMenu = menu.addItem(withTitle: UIConstants.strings.menuQuitButton, action: #selector(self.quitItemClicked(_:)), keyEquivalent: "q")
quitMenu.target = self

if let versionNumber = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String {
menu.addItem(NSMenuItem.separator())
menu.addItem(withTitle: "\(UIConstants.strings.menuVersionLabel) \(versionNumber)", action: nil, keyEquivalent: "")
}

self.statusItem.menu = menu
}
}

private func buildWatcher() {
watcher = DirectoryWatcher(in: URLHelper.deviceURL)
watcher.completionCallback = { [weak self] in
self?.reloadWhenReady()
self?.reloadWhenReady(delay: 5)
self?.buildSubWatchers()
}
try? watcher.start()
Expand All @@ -137,9 +142,9 @@ protocol MenuManagerDelegate {
}


private func reloadWhenReady() {
private func reloadWhenReady(delay: TimeInterval = 1) {
dispatch_cancel_block_t(self.block)
self.block = dispatch_block_t(1) { [weak self] in
self.block = dispatch_block_t(delay) { [weak self] in
self?.watcher.stop()
self?.buildMenu()
try? self?.watcher.start()
Expand Down
2 changes: 1 addition & 1 deletion OpenSim/OpenInItermAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class OpenInItermAction: ExtraApplicationActionable {

let appBundleIdentifier = "com.googlecode.iterm2"

let title = NSLocalizedString("Open Sandbox in iTerm", comment: "")
let title = UIConstants.strings.extensionOpenInIterm

required init(application: Application) {
self.application = application
Expand Down
2 changes: 1 addition & 1 deletion OpenSim/OpenInTerminalAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class OpenInTerminalAction: ApplicationActionable {

var application: Application?

let title = NSLocalizedString("Open Sandbox in Terminal", comment: "")
let title = UIConstants.strings.actionOpenInTerminal

let icon = templatize(#imageLiteral(resourceName: "terminal"))

Expand Down
2 changes: 1 addition & 1 deletion OpenSim/OpenRealmAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class OpenRealmAction: ExtraApplicationActionable {

let appBundleIdentifier = "io.realm.realmbrowser"

let title = "Open Realm Database"
let title = UIConstants.strings.extensionOpenRealmDatabase

var isAvailable: Bool {
return appPath != nil && realmPath != nil
Expand Down
2 changes: 1 addition & 1 deletion OpenSim/RevealInFinderAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class RevealInFinderAction: ApplicationActionable {

var application: Application?

let title = NSLocalizedString("Reveal Sandbox in Finder", comment: "")
let title = UIConstants.strings.actionRevealInFinder

let icon = templatize(#imageLiteral(resourceName: "reveal"))

Expand Down
9 changes: 4 additions & 5 deletions OpenSim/UninstallAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class UninstallAction: ApplicationActionable {

var application: Application?

let title = NSLocalizedString("Uninstall…", comment: "")
let title = UIConstants.strings.actionUninstall

let icon = templatize(#imageLiteral(resourceName: "uninstall"))

Expand All @@ -27,11 +27,10 @@ final class UninstallAction: ApplicationActionable {
return
}
let alert: NSAlert = NSAlert()
let alertFormat = "Are you sure you want to uninstall %1$@ from %1$@?"
alert.messageText = String(format: NSLocalizedString(alertFormat, comment: ""), application.bundleDisplayName, application.device.name)
alert.messageText = String(format: UIConstants.strings.actionUninstallAlertMessage, application.bundleDisplayName, application.device.name)
alert.alertStyle = .critical
alert.addButton(withTitle: NSLocalizedString("Uninstall", comment: ""))
alert.addButton(withTitle: NSLocalizedString("Cancel", comment: ""))
alert.addButton(withTitle: UIConstants.strings.actionUninstallAlertConfirmButton)
alert.addButton(withTitle: UIConstants.strings.actionUninstallAlertCancelButton)
let response = alert.runModal()
if response == NSApplication.ModalResponse.alertFirstButtonReturn {
application.uninstall()
Expand Down
18 changes: 18 additions & 0 deletions OpenSim/pt-BR.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"Menu.Quit" = "Sair";
"Menu.LaunchAtLogin" = "Iniciar junto com sistema";
"Menu.Refresh" = "Atualizar";
"Menu.Version" = "Versão";
"Action.RevealInFinder" = "Abrir Sandbox no Finder";
"Action.CopyPathPasteboard" = "Copiar caminho do Sandbox para o Pasteboard";
"Action.OpenInTerminal" = "Abrir Sandbox no Terminal";
"Action.Uninstall" = "Desinstalar";
"Action.UninstallAlertConfirmButton" = "Desinstalar";
"Action.UninstallAlertCancelButton" = "Cancelar";
"Action.UninstallAlertMessage" = "Você tem certeza que quer desinstalar %@ do %@?";
"Extension.OpenInIterm" = "Abrir Sandbox no iTerm";
"Extension.OpenRealmDatabase" = "Abrir Realm Database";
"AppInfo.Version" = "Versão";
"AppInfo.Size" = "Tamanho";
"MenuHeader.Actions" = "Ações";
"MenuHeader.Extensions" = "Extensões";
"MenuHeader.AppInformation" = "Informação do App";

0 comments on commit bc7f767

Please sign in to comment.