Skip to content

Commit bc7f767

Browse files
authored
Merge pull request #49 from luosheng/develop
Version 0.4.2
2 parents 0ea85a5 + 61a78c7 commit bc7f767

15 files changed

Lines changed: 140 additions & 39 deletions

OpenSim.xcodeproj/project.pbxproj

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
objects = {
88

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

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

8388
/* Begin PBXGroup section */
89+
31C4BF2321A8AA3D008B97A1 /* AppDelegate */ = {
90+
isa = PBXGroup;
91+
children = (
92+
B3A1E3221BF049690090EC58 /* AppDelegate.swift */,
93+
);
94+
name = AppDelegate;
95+
sourceTree = "<group>";
96+
};
97+
31C4BF2721A8AA52008B97A1 /* Supporting Files */ = {
98+
isa = PBXGroup;
99+
children = (
100+
B3A1E3241BF049690090EC58 /* Assets.xcassets */,
101+
31C4BF3021A8AC56008B97A1 /* Localizable.strings */,
102+
B3A1E3261BF049690090EC58 /* MainMenu.xib */,
103+
B3A1E3291BF049690090EC58 /* Info.plist */,
104+
);
105+
name = "Supporting Files";
106+
sourceTree = "<group>";
107+
};
84108
B36856AC1CA41BA8009BE4CC /* Models */ = {
85109
isa = PBXGroup;
86110
children = (
@@ -117,6 +141,7 @@
117141
B39B2B601EBEF1A100CDD74C /* AppMenuItem.swift */,
118142
B32480541EBEB705000633FC /* ActionMenu.swift */,
119143
B39B2B621EBEFFB700CDD74C /* AppInfoView.swift */,
144+
312A27FC21A753E600699668 /* Constants.swift */,
120145
);
121146
name = UI;
122147
sourceTree = "<group>";
@@ -153,14 +178,12 @@
153178
B3A1E3211BF049690090EC58 /* OpenSim */ = {
154179
isa = PBXGroup;
155180
children = (
156-
B3A1E3221BF049690090EC58 /* AppDelegate.swift */,
181+
31C4BF2321A8AA3D008B97A1 /* AppDelegate */,
157182
B36856AC1CA41BA8009BE4CC /* Models */,
158183
B39B2B6D1EBF511200CDD74C /* Actions */,
159184
B36856AD1CA41BCB009BE4CC /* Utilities */,
160185
B36856AE1CA41BD4009BE4CC /* UI */,
161-
B3A1E3241BF049690090EC58 /* Assets.xcassets */,
162-
B3A1E3261BF049690090EC58 /* MainMenu.xib */,
163-
B3A1E3291BF049690090EC58 /* Info.plist */,
186+
31C4BF2721A8AA52008B97A1 /* Supporting Files */,
164187
);
165188
path = OpenSim;
166189
sourceTree = "<group>";
@@ -208,6 +231,7 @@
208231
knownRegions = (
209232
en,
210233
Base,
234+
"pt-BR",
211235
);
212236
mainGroup = B3A1E3161BF049690090EC58;
213237
productRefGroup = B3A1E3201BF049690090EC58 /* Products */;
@@ -225,6 +249,7 @@
225249
buildActionMask = 2147483647;
226250
files = (
227251
B3A1E3251BF049690090EC58 /* Assets.xcassets in Resources */,
252+
31C4BF3221A8AC56008B97A1 /* Localizable.strings in Resources */,
228253
B3A1E3281BF049690090EC58 /* MainMenu.xib in Resources */,
229254
);
230255
runOnlyForDeploymentPostprocessing = 0;
@@ -256,6 +281,7 @@
256281
B39B2B671EBF0D0600CDD74C /* LaunchAtLoginHelper.swift in Sources */,
257282
B39B2B631EBEFFB700CDD74C /* AppInfoView.swift in Sources */,
258283
B3A1E3301BF05F980090EC58 /* DeviceManager.swift in Sources */,
284+
312A27FD21A753E600699668 /* Constants.swift in Sources */,
259285
B3A1E3231BF049690090EC58 /* AppDelegate.swift in Sources */,
260286
B39B2B6F1EBF567F00CDD74C /* CopyToPasteboardAction.swift in Sources */,
261287
B39B2B731EBF573C00CDD74C /* UninstallAction.swift in Sources */,
@@ -268,6 +294,15 @@
268294
/* End PBXSourcesBuildPhase section */
269295

270296
/* Begin PBXVariantGroup section */
297+
31C4BF3021A8AC56008B97A1 /* Localizable.strings */ = {
298+
isa = PBXVariantGroup;
299+
children = (
300+
31C4BF3121A8AC56008B97A1 /* Base */,
301+
31C4BF3421A8AC72008B97A1 /* pt-BR */,
302+
);
303+
name = Localizable.strings;
304+
sourceTree = "<group>";
305+
};
271306
B3A1E3261BF049690090EC58 /* MainMenu.xib */ = {
272307
isa = PBXVariantGroup;
273308
children = (
@@ -283,6 +318,7 @@
283318
isa = XCBuildConfiguration;
284319
buildSettings = {
285320
ALWAYS_SEARCH_USER_PATHS = NO;
321+
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
286322
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
287323
CLANG_CXX_LIBRARY = "libc++";
288324
CLANG_ENABLE_MODULES = YES;
@@ -338,6 +374,7 @@
338374
isa = XCBuildConfiguration;
339375
buildSettings = {
340376
ALWAYS_SEARCH_USER_PATHS = NO;
377+
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
341378
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
342379
CLANG_CXX_LIBRARY = "libc++";
343380
CLANG_ENABLE_MODULES = YES;

OpenSim/ActionMenu.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ final class ActionMenu: NSMenu {
4545
private func buildMenuItems() {
4646
let createAction: (ApplicationActionable.Type) -> ApplicationActionable = { $0.init(application: self.application) }
4747

48-
self.buildMenuSection(title: NSLocalizedString("Actions", comment: ""), actions: ActionMenu.standardActions.map(createAction))
49-
self.buildMenuSection(title: NSLocalizedString("Extensions", comment: ""), actions: ActionMenu.extraActions.map(createAction))
50-
self.addItem(self.buildSectionTitle(title: NSLocalizedString("App Information", comment: "")))
48+
self.buildMenuSection(title: UIConstants.strings.menuHeaderActions, actions: ActionMenu.standardActions.map(createAction))
49+
self.buildMenuSection(title: UIConstants.strings.menuHeaderExtensions, actions: ActionMenu.extraActions.map(createAction))
50+
self.addItem(self.buildSectionTitle(title: UIConstants.strings.menuHeaderAppInformation))
5151
self.addItem(appInfoItem)
5252
}
5353

OpenSim/AppInfoView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ final class AppInfoView: NSView {
5656
sizeDescription = ByteCountFormatter.string(fromByteCount: Int64(size), countStyle: .file)
5757
}
5858
let string = "\(application.bundleID)\n" +
59-
"Version: \(application.bundleVersion) (\(application.bundleShortVersion))\n" +
60-
"Size: \(sizeDescription)"
59+
"\(UIConstants.strings.appInfoVersion): \(application.bundleVersion) (\(application.bundleShortVersion))\n" +
60+
"\(UIConstants.strings.appInfoSize): \(sizeDescription)"
6161
textField.stringValue = string
6262
}
6363

OpenSim/Application.swift

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,14 @@ final class Application {
8989
block(size)
9090
} else {
9191
Application.sizeDispatchQueue.async {
92-
var size: UInt64 = 0
93-
let filesEnumerator = FileManager.default.enumerator(at: self.url, includingPropertiesForKeys: nil, options: [], errorHandler: { (url, error) -> Bool in
94-
return true
95-
})
96-
while let fileUrl = filesEnumerator?.nextObject() as? URL {
97-
let attributes = try? FileManager.default.attributesOfItem(atPath: fileUrl.path) as NSDictionary
98-
size += attributes?.fileSize() ?? 0
92+
let duResult = shell("/usr/bin/du", arguments: ["-sk", self.url.path])
93+
let stringBytes = String(duResult.split(separator: "\t").first ?? "")
94+
var bytes: UInt64 = 0
95+
if let kbytes = UInt64(stringBytes) {
96+
bytes = kbytes * 1000
97+
self.size = bytes;
9998
}
100-
self.size = size
101-
block(size)
99+
block(bytes)
102100
}
103101
}
104102
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"Menu.Quit" = "Quit";
2+
"Menu.LaunchAtLogin" = "Launch at Login";
3+
"Menu.Refresh" = "Refresh";
4+
"Menu.Version" = "Version";
5+
"Action.RevealInFinder" = "Reveal Sandbox in Finder";
6+
"Action.CopyPathPasteboard" = "Copy Sandbox Path to Pasteboard";
7+
"Action.OpenInTerminal" = "Open Sandbox in Terminal";
8+
"Action.Uninstall" = "Uninstall";
9+
"Action.UninstallAlertConfirmButton" = "Uninstall";
10+
"Action.UninstallAlertCancelButton" = "Cancel";
11+
"Action.UninstallAlertMessage" = "Are you sure you want to uninstall %@ from %@?";
12+
"Extension.OpenInIterm" = "Open Sandbox in iTerm";
13+
"Extension.OpenRealmDatabase" = "Open Realm Database";
14+
"AppInfo.Version" = "Version";
15+
"AppInfo.Size" = "Size";
16+
"MenuHeader.Actions" = "Actions";
17+
"MenuHeader.Extensions" = "Extensions";
18+
"MenuHeader.AppInformation" = "App Information";

OpenSim/Constants.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
import Foundation
3+
4+
struct UIConstants {
5+
6+
struct strings {
7+
static let menuQuitButton = NSLocalizedString("Menu.Quit", comment: "Quit menu button")
8+
static let menuLaunchAtLoginButton = NSLocalizedString("Menu.LaunchAtLogin", comment: "Launch at login menu button")
9+
static let menuRefreshButton = NSLocalizedString("Menu.Refresh", comment: "Refresh menu button")
10+
static let menuVersionLabel = NSLocalizedString("Menu.Version", comment: "Version label")
11+
static let actionRevealInFinder = NSLocalizedString("Action.RevealInFinder", comment: "Reveal in Finder label")
12+
static let actionCopyPathPasteboard = NSLocalizedString("Action.CopyPathPasteboard", comment: "Copy Sandbox path to pasteboard label")
13+
static let actionOpenInTerminal = NSLocalizedString("Action.OpenInTerminal", comment: "Open in Terminal label")
14+
static let actionUninstall = NSLocalizedString("Action.Uninstall", comment: "Uninstall label")
15+
static let actionUninstallAlertConfirmButton = NSLocalizedString("Action.UninstallAlertConfirmButton", comment: "Uninstall confirm button")
16+
static let actionUninstallAlertCancelButton = NSLocalizedString("Action.UninstallAlertCancelButton", comment: "Uninstall cancel button")
17+
static let actionUninstallAlertMessage = NSLocalizedString("Action.UninstallAlertMessage", comment: "Uninstall confirmation message")
18+
static let extensionOpenInIterm = NSLocalizedString("Extension.OpenInIterm", comment: "Open in iTerm label")
19+
static let extensionOpenRealmDatabase = NSLocalizedString("Extension.OpenRealmDatabase", comment: "Open Realm Database label")
20+
static let appInfoVersion = NSLocalizedString("AppInfo.Version", comment: "App Info Version Label")
21+
static let appInfoSize = NSLocalizedString("AppInfo.Size", comment: "App Info Size Label")
22+
static let menuHeaderActions = NSLocalizedString("MenuHeader.Actions", comment: "Actions header label")
23+
static let menuHeaderExtensions = NSLocalizedString("MenuHeader.Extensions", comment: "Extensions header label")
24+
static let menuHeaderAppInformation = NSLocalizedString("MenuHeader.AppInformation", comment: "App Information header label")
25+
}
26+
}

OpenSim/CopyToPasteboardAction.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ final class CopyToPasteboardAction: ApplicationActionable {
1212

1313
var application: Application?
1414

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

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

OpenSim/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<key>CFBundlePackageType</key>
1818
<string>APPL</string>
1919
<key>CFBundleShortVersionString</key>
20-
<string>0.4.1</string>
20+
<string>0.4.2</string>
2121
<key>CFBundleSignature</key>
2222
<string>????</string>
2323
<key>CFBundleVersion</key>

OpenSim/MenuManager.swift

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ protocol MenuManagerDelegate {
6161
return
6262
}
6363
menu.addItem(NSMenuItem.separator())
64-
let titleItem = NSMenuItem(title: "\(runtime) Simulators", action: nil, keyEquivalent: "")
64+
let titleItem = NSMenuItem(title: "\(runtime)", action: nil, keyEquivalent: "")
6565
titleItem.isEnabled = false
6666
menu.addItem(titleItem)
6767

@@ -90,29 +90,34 @@ protocol MenuManagerDelegate {
9090
}
9191

9292
menu.addItem(NSMenuItem.separator())
93-
94-
let refreshMenuItem = menu.addItem(withTitle: NSLocalizedString("Refresh", comment: ""), action: #selector(self.refreshItemClicked(_:)), keyEquivalent: "r")
93+
94+
let refreshMenuItem = menu.addItem(withTitle: UIConstants.strings.menuRefreshButton, action: #selector(self.refreshItemClicked(_:)), keyEquivalent: "r")
9595
refreshMenuItem.target = self
96-
97-
let launchAtLoginMenuItem = menu.addItem(withTitle: NSLocalizedString("Launch at Login", comment: ""), action: #selector(self.launchItemClicked(_:)), keyEquivalent: "")
96+
97+
let launchAtLoginMenuItem = menu.addItem(withTitle: UIConstants.strings.menuLaunchAtLoginButton, action: #selector(self.launchItemClicked(_:)), keyEquivalent: "")
9898
launchAtLoginMenuItem.target = self
9999
if existingItem(itemUrl: Bundle.main.bundleURL) != nil {
100100
launchAtLoginMenuItem.state = .on
101101
} else {
102102
launchAtLoginMenuItem.state = .off
103103
}
104-
105-
let quitMenu = menu.addItem(withTitle: NSLocalizedString("Quit", comment: ""), action: #selector(self.quitItemClicked(_:)), keyEquivalent: "q")
104+
105+
let quitMenu = menu.addItem(withTitle: UIConstants.strings.menuQuitButton, action: #selector(self.quitItemClicked(_:)), keyEquivalent: "q")
106106
quitMenu.target = self
107107

108+
if let versionNumber = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String {
109+
menu.addItem(NSMenuItem.separator())
110+
menu.addItem(withTitle: "\(UIConstants.strings.menuVersionLabel) \(versionNumber)", action: nil, keyEquivalent: "")
111+
}
112+
108113
self.statusItem.menu = menu
109114
}
110115
}
111116

112117
private func buildWatcher() {
113118
watcher = DirectoryWatcher(in: URLHelper.deviceURL)
114119
watcher.completionCallback = { [weak self] in
115-
self?.reloadWhenReady()
120+
self?.reloadWhenReady(delay: 5)
116121
self?.buildSubWatchers()
117122
}
118123
try? watcher.start()
@@ -137,9 +142,9 @@ protocol MenuManagerDelegate {
137142
}
138143

139144

140-
private func reloadWhenReady() {
145+
private func reloadWhenReady(delay: TimeInterval = 1) {
141146
dispatch_cancel_block_t(self.block)
142-
self.block = dispatch_block_t(1) { [weak self] in
147+
self.block = dispatch_block_t(delay) { [weak self] in
143148
self?.watcher.stop()
144149
self?.buildMenu()
145150
try? self?.watcher.start()

OpenSim/OpenInItermAction.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class OpenInItermAction: ExtraApplicationActionable {
1414

1515
let appBundleIdentifier = "com.googlecode.iterm2"
1616

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

1919
required init(application: Application) {
2020
self.application = application

0 commit comments

Comments
 (0)