Skip to content

Commit

Permalink
add localisation and monitoring feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Disconnecter committed Aug 1, 2024
1 parent a14ed76 commit 0113252
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 11 deletions.
10 changes: 10 additions & 0 deletions Mic-Status-Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSServices</key>
<array>
<dict/>
</array>
</dict>
</plist>
13 changes: 11 additions & 2 deletions MicStatus.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
2A6049C82AAA129300C2B381 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A6049C72AAA129300C2B381 /* AppDelegate.swift */; };
2A6049CA2AAA129400C2B381 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2A6049C92AAA129400C2B381 /* Assets.xcassets */; };
2A6049CD2AAA129400C2B381 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2A6049CB2AAA129400C2B381 /* MainMenu.xib */; };
2A990C652C5B99D10089BF50 /* Localizable.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = 2A990C642C5B99D10089BF50 /* Localizable.xcstrings */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -18,6 +19,7 @@
2A6049C92AAA129400C2B381 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
2A6049CC2AAA129400C2B381 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = "<group>"; };
2A6049CE2AAA129400C2B381 /* MicStatus.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = MicStatus.entitlements; sourceTree = "<group>"; };
2A990C642C5B99D10089BF50 /* Localizable.xcstrings */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; path = Localizable.xcstrings; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -54,6 +56,7 @@
2A6049C92AAA129400C2B381 /* Assets.xcassets */,
2A6049CB2AAA129400C2B381 /* MainMenu.xib */,
2A6049CE2AAA129400C2B381 /* MicStatus.entitlements */,
2A990C642C5B99D10089BF50 /* Localizable.xcstrings */,
);
path = MicStatus;
sourceTree = "<group>";
Expand Down Expand Up @@ -100,6 +103,7 @@
knownRegions = (
en,
Base,
uk,
);
mainGroup = 2A6049BB2AAA129300C2B381;
productRefGroup = 2A6049C52AAA129300C2B381 /* Products */;
Expand All @@ -118,6 +122,7 @@
files = (
2A6049CA2AAA129400C2B381 /* Assets.xcassets in Resources */,
2A6049CD2AAA129400C2B381 /* MainMenu.xib in Resources */,
2A990C652C5B99D10089BF50 /* Localizable.xcstrings in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -150,6 +155,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
Expand Down Expand Up @@ -196,6 +202,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MACOSX_DEPLOYMENT_TARGET = 13.3;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
Expand All @@ -210,6 +217,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
Expand Down Expand Up @@ -250,6 +258,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MACOSX_DEPLOYMENT_TARGET = 13.3;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
Expand Down Expand Up @@ -284,7 +293,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 12.0;
MARKETING_VERSION = 1.0;
MARKETING_VERSION = 1.0.1;
PRODUCT_BUNDLE_IDENTIFIER = com.zabolotnyy.mic.status;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down Expand Up @@ -317,7 +326,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 12.0;
MARKETING_VERSION = 1.0;
MARKETING_VERSION = 1.0.1;
PRODUCT_BUNDLE_IDENTIFIER = com.zabolotnyy.mic.status;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down
42 changes: 35 additions & 7 deletions MicStatus/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {

@IBOutlet weak var mainMenu: NSMenu!
@IBOutlet weak var quitMenuAction: NSMenuItem!
@IBOutlet weak var monitorMenuAction: NSMenuItem!

private let script = NSAppleScript(source: "input volume of (get volume settings)")
private let statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
Expand All @@ -32,11 +33,32 @@ class AppDelegate: NSObject, NSApplicationDelegate {
return image ?? NSImage()
}()

private lazy var micDown: NSImage = {
let image = NSImage(named: "mic_down")
image?.size = Self.iconSize
return image ?? NSImage()
}()

func applicationDidFinishLaunching(_ aNotification: Notification) {
timer = Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true) { [weak self] timer in
self?.setIcon()
}
startTimer()
statusItem.menu = mainMenu
quitMenuAction.title = NSLocalizedString("Menu.Quit", comment: "")
}

func applicationWillTerminate(_ aNotification: Notification) {
stopTimer()
}

func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
return true
}

@IBAction private func monitoringAction(menuItem: NSMenuItem) {
guard timer?.isValid ?? false else {
startTimer()
return
}
stopTimer()
}

private func setIcon() {
Expand All @@ -52,15 +74,21 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
}

func applicationWillTerminate(_ aNotification: Notification) {
private func stopTimer() {
guard timer?.isValid ?? true else {
return
}
timer?.invalidate()
timer = nil
monitorMenuAction.title = NSLocalizedString("Menu.Start", comment: "")
statusItem.button?.image = micDown
lastVolume = -1
}

func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
return true

private func startTimer() {
monitorMenuAction.title = NSLocalizedString("Menu.Stop", comment: "")
timer = Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true) { [weak self] timer in
self?.setIcon()
}
}
}
12 changes: 12 additions & 0 deletions MicStatus/Assets.xcassets/mic_down.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "button-off-red-switch-toggle-21532.svg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 10 additions & 2 deletions MicStatus/Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="21701" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21701"/>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22689"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
Expand All @@ -14,12 +15,19 @@
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="Mic_Status" customModuleProvider="target">
<connections>
<outlet property="mainMenu" destination="uQy-DD-JDr" id="O0K-cw-IAr"/>
<outlet property="monitorMenuAction" destination="qiq-53-DOG" id="z3B-oU-wbz"/>
<outlet property="quitMenuAction" destination="4sb-4s-VLi" id="XiH-a2-oeE"/>
</connections>
</customObject>
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
<menu title="MicStatus" systemMenu="apple" id="uQy-DD-JDr">
<items>
<menuItem title="Item" id="qiq-53-DOG">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="monitoringActionWithMenuItem:" target="Voe-Tx-rLC" id="yBI-Dh-O12"/>
</connections>
</menuItem>
<menuItem title="Quit MicStatus" keyEquivalent="q" id="4sb-4s-VLi">
<connections>
<action selector="terminate:" target="-1" id="Te7-pn-YzF"/>
Expand Down
74 changes: 74 additions & 0 deletions MicStatus/Localizable.xcstrings
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"sourceLanguage" : "en",
"strings" : {
"Menu.Quit" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Quit MicStatus"
}
},
"uk" : {
"stringUnit" : {
"state" : "translated",
"value" : "Вийти з MicStatus"
}
}
}
},
"Menu.Start" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Start Monitoring"
}
},
"uk" : {
"stringUnit" : {
"state" : "translated",
"value" : "Почати моніторинг"
}
}
}
},
"Menu.Stop" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Stop Monitoring"
}
},
"uk" : {
"stringUnit" : {
"state" : "translated",
"value" : "Зупинити моніторинг"
}
}
}
},
"Menu.Title" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "MicStatus"
}
},
"uk" : {
"stringUnit" : {
"state" : "translated",
"value" : "MicStatus"
}
}
}
}
},
"version" : "1.0"
}

0 comments on commit 0113252

Please sign in to comment.