Skip to content

Commit e993d36

Browse files
authored
Merge pull request #221 from niklasr22/220-cli
220 cli
2 parents 4fc8ef9 + 704dc63 commit e993d36

File tree

8 files changed

+333
-25
lines changed

8 files changed

+333
-25
lines changed

BrightIntosh.xcodeproj/project.pbxproj

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
/* Begin PBXBuildFile section */
1010
1E05D3952B90E50E006FE96A /* StatusBarMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E05D3942B90E50E006FE96A /* StatusBarMenu.swift */; };
1111
1E05D3962B90E50E006FE96A /* StatusBarMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E05D3942B90E50E006FE96A /* StatusBarMenu.swift */; };
12+
9C17DFAB2DCF748000185CDA /* Cli.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C17DFAA2DCF747D00185CDA /* Cli.swift */; };
13+
9C17DFAC2DCF748000185CDA /* Cli.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C17DFAA2DCF747D00185CDA /* Cli.swift */; };
14+
9C17DFAF2DD0CA3500185CDA /* cli.sh in Resources */ = {isa = PBXBuildFile; fileRef = 9C17DFAD2DD0CA3200185CDA /* cli.sh */; };
1215
9C1C8BE72C8B3EA300754474 /* UserStatusModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C1C8BE62C8B3EA300754474 /* UserStatusModifier.swift */; };
1316
9C1C8BE82C8B4A1C00754474 /* UserStatusModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C1C8BE62C8B3EA300754474 /* UserStatusModifier.swift */; };
1417
9C1C8BEA2C8B4FC000754474 /* Trial.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C1C8BE92C8B4FC000754474 /* Trial.swift */; };
@@ -85,6 +88,8 @@
8588

8689
/* Begin PBXFileReference section */
8790
1E05D3942B90E50E006FE96A /* StatusBarMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusBarMenu.swift; sourceTree = "<group>"; };
91+
9C17DFAA2DCF747D00185CDA /* Cli.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Cli.swift; sourceTree = "<group>"; };
92+
9C17DFAD2DD0CA3200185CDA /* cli.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = cli.sh; sourceTree = "<group>"; };
8893
9C1C8BE62C8B3EA300754474 /* UserStatusModifier.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserStatusModifier.swift; sourceTree = "<group>"; };
8994
9C1C8BE92C8B4FC000754474 /* Trial.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Trial.swift; sourceTree = "<group>"; };
9095
9C1C8BEC2C8B817B00754474 /* BrightIntoshStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrightIntoshStore.swift; sourceTree = "<group>"; };
@@ -183,6 +188,8 @@
183188
C1DF94472A5EF20000FA285F /* BrightIntosh */ = {
184189
isa = PBXGroup;
185190
children = (
191+
9C17DFAD2DD0CA3200185CDA /* cli.sh */,
192+
9C17DFAA2DCF747D00185CDA /* Cli.swift */,
186193
C1DF94512A5EF20E00FA285F /* AppDelegate.swift */,
187194
9C9C78022A62AEE800778CAE /* Assets.xcassets */,
188195
9C534AC72ACB06210029E050 /* AutomationManager.swift */,
@@ -314,6 +321,7 @@
314321
9CE3C37F2C8C8A1800E7FDBA /* Localizable.xcstrings in Resources */,
315322
9CEDBABC2D870EBA00490820 /* Products.storekit in Resources */,
316323
9C9C78032A62AEE800778CAE /* Assets.xcassets in Resources */,
324+
9C17DFAF2DD0CA3500185CDA /* cli.sh in Resources */,
317325
);
318326
runOnlyForDeploymentPostprocessing = 0;
319327
};
@@ -337,6 +345,7 @@
337345
9C1C8BEB2C8B4FC000754474 /* Trial.swift in Sources */,
338346
9CE3C3822C8C8D3B00E7FDBA /* Styles.swift in Sources */,
339347
9C8803772A72625E00476017 /* OverlayWindow.swift in Sources */,
348+
9C17DFAB2DCF748000185CDA /* Cli.swift in Sources */,
340349
9C88037A2A72625E00476017 /* Overlay.swift in Sources */,
341350
9CCAC9372C3AF53B00B105D1 /* EntitlementHandler.swift in Sources */,
342351
9C534ACC2ACB2A050029E050 /* Alerts.swift in Sources */,
@@ -366,6 +375,7 @@
366375
9C1C8BED2C8B817B00754474 /* BrightIntoshStore.swift in Sources */,
367376
9CE3C3812C8C8D3B00E7FDBA /* Styles.swift in Sources */,
368377
C1D044EB2A60205E0022B970 /* OverlayWindow.swift in Sources */,
378+
9C17DFAC2DCF748000185CDA /* Cli.swift in Sources */,
369379
9C534ACB2ACB2A050029E050 /* Alerts.swift in Sources */,
370380
C1B5215C2A5EFFDB00E9B7AC /* Overlay.swift in Sources */,
371381
C1B5215D2A5EFFDB00E9B7AC /* main.swift in Sources */,
@@ -392,7 +402,7 @@
392402
CODE_SIGN_ENTITLEMENTS = BrightIntosh/BrightIntosh_SE.entitlements;
393403
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
394404
CODE_SIGN_STYLE = Automatic;
395-
CURRENT_PROJECT_VERSION = 67;
405+
CURRENT_PROJECT_VERSION = 68;
396406
DEAD_CODE_STRIPPING = YES;
397407
DEVELOPMENT_ASSET_PATHS = "";
398408
DEVELOPMENT_TEAM = 9K32WDUN2H;
@@ -419,7 +429,7 @@
419429
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
420430
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
421431
MACOSX_DEPLOYMENT_TARGET = 13.0;
422-
MARKETING_VERSION = 4.1.0;
432+
MARKETING_VERSION = 4.2.0;
423433
PRODUCT_BUNDLE_IDENTIFIER = de.brightintosh.app;
424434
PRODUCT_NAME = BrightIntosh;
425435
SDKROOT = auto;
@@ -444,7 +454,7 @@
444454
CODE_SIGN_ENTITLEMENTS = BrightIntosh/BrightIntosh_SE.entitlements;
445455
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
446456
CODE_SIGN_STYLE = Automatic;
447-
CURRENT_PROJECT_VERSION = 67;
457+
CURRENT_PROJECT_VERSION = 68;
448458
DEAD_CODE_STRIPPING = YES;
449459
DEVELOPMENT_ASSET_PATHS = "";
450460
DEVELOPMENT_TEAM = 9K32WDUN2H;
@@ -471,7 +481,7 @@
471481
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
472482
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
473483
MACOSX_DEPLOYMENT_TARGET = 13.0;
474-
MARKETING_VERSION = 4.1.0;
484+
MARKETING_VERSION = 4.2.0;
475485
PRODUCT_BUNDLE_IDENTIFIER = de.brightintosh.app;
476486
PRODUCT_NAME = BrightIntosh;
477487
SDKROOT = auto;
@@ -494,7 +504,7 @@
494504
CODE_SIGN_ENTITLEMENTS = BrightIntosh/BrightIntosh.entitlements;
495505
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
496506
CODE_SIGN_STYLE = Automatic;
497-
CURRENT_PROJECT_VERSION = 67;
507+
CURRENT_PROJECT_VERSION = 68;
498508
DEAD_CODE_STRIPPING = YES;
499509
DEVELOPMENT_ASSET_PATHS = "";
500510
DEVELOPMENT_TEAM = 9K32WDUN2H;
@@ -521,7 +531,7 @@
521531
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
522532
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
523533
MACOSX_DEPLOYMENT_TARGET = 13.0;
524-
MARKETING_VERSION = 4.1.0;
534+
MARKETING_VERSION = 4.2.0;
525535
PRODUCT_BUNDLE_IDENTIFIER = de.brightintosh.app;
526536
PRODUCT_NAME = "$(TARGET_NAME)";
527537
SDKROOT = auto;
@@ -545,7 +555,7 @@
545555
CODE_SIGN_IDENTITY = "Apple Development";
546556
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
547557
CODE_SIGN_STYLE = Automatic;
548-
CURRENT_PROJECT_VERSION = 67;
558+
CURRENT_PROJECT_VERSION = 68;
549559
DEAD_CODE_STRIPPING = YES;
550560
DEVELOPMENT_ASSET_PATHS = "";
551561
DEVELOPMENT_TEAM = 9K32WDUN2H;
@@ -572,7 +582,7 @@
572582
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
573583
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
574584
MACOSX_DEPLOYMENT_TARGET = 13.0;
575-
MARKETING_VERSION = 4.1.0;
585+
MARKETING_VERSION = 4.2.0;
576586
PRODUCT_BUNDLE_IDENTIFIER = de.brightintosh.app;
577587
PRODUCT_NAME = "$(TARGET_NAME)";
578588
SDKROOT = auto;

BrightIntosh.xcodeproj/xcshareddata/xcschemes/BrightIntosh (Store Editon).xcscheme

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@
4949
ReferencedContainer = "container:BrightIntosh.xcodeproj">
5050
</BuildableReference>
5151
</BuildableProductRunnable>
52-
<CommandLineArguments>
53-
<CommandLineArgument
54-
argument = "--no-app-transaction"
55-
isEnabled = "NO">
56-
</CommandLineArgument>
57-
</CommandLineArguments>
5852
<StoreKitConfigurationFileReference
5953
identifier = "../../BrightIntosh/Products.storekit">
6054
</StoreKitConfigurationFileReference>

BrightIntosh/Cli.swift

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
//
2+
// Cli.swift
3+
// BrightIntosh
4+
//
5+
// Created by Niklas Rousset on 10.05.25.
6+
//
7+
import Foundation
8+
9+
@MainActor func notifyUpdate() {
10+
let center = DistributedNotificationCenter.default()
11+
center.postNotificationName(UserDefaults.didChangeNotification, object: nil, userInfo: nil, deliverImmediately: true)
12+
}
13+
14+
@MainActor func toggleCli() {
15+
Settings.shared.brightintoshActive.toggle()
16+
notifyUpdate()
17+
}
18+
19+
@MainActor func setActiveStateCli(active: Bool) {
20+
Settings.shared.brightintoshActive = active
21+
notifyUpdate()
22+
}
23+
24+
@MainActor func setBrightnessOffsetCli() {
25+
if CommandLine.argc <= 2 {
26+
print("Usage: brightintosh set <0-100>")
27+
return
28+
}
29+
guard let brightnessValue = Int(CommandLine.arguments[2]), brightnessValue <= 100, brightnessValue >= 0 else {
30+
print("Usage: brightintosh set <0-100>")
31+
return
32+
}
33+
Settings.shared.brightness = 1.0 + (getDeviceMaxBrightness() - 1.0) * Float(brightnessValue) / 100.0
34+
notifyUpdate()
35+
}
36+
37+
@MainActor func statusCli() {
38+
let status = Settings.shared.brightintoshActive
39+
let brightness = Settings.shared.brightness
40+
let brightnessPercentage = Int(round((brightness - 1.0) / (getDeviceMaxBrightness() - 1.0) * 100.0))
41+
print("Status: \(status ? "Enabled" : "Disabled")")
42+
print("Brightness: \(brightnessPercentage)")
43+
}
44+
45+
enum CliCommand: String, CaseIterable {
46+
case enable = "enable"
47+
case disable = "disable"
48+
case set = "set"
49+
case status = "status"
50+
case toggle = "toggle"
51+
case help = "help"
52+
}
53+
54+
func getHelpText() -> String {
55+
return
56+
"""
57+
BrightIntosh CLI
58+
Usage: brightintosh <command> [options]
59+
60+
Note: This CLI is additional and does require the main app to be running.
61+
62+
Commands:
63+
enable Enable BrightIntosh
64+
disable Disable BrightIntosh
65+
set <value> Set brightness offset (0-100)
66+
status Show current status and brightness
67+
toggle Toggle BrightIntosh on/off
68+
help Show this help message
69+
"""
70+
}
71+
72+
func helpCli() {
73+
print(getHelpText())
74+
}
75+
76+
@MainActor func cliBase() -> Bool {
77+
if CommandLine.argc > 1 {
78+
guard let command = CliCommand(rawValue: CommandLine.arguments[1]) else {
79+
helpCli()
80+
return false
81+
}
82+
83+
switch command {
84+
case CliCommand.toggle:
85+
toggleCli()
86+
return true
87+
case CliCommand.enable:
88+
setActiveStateCli(active: true)
89+
return true
90+
case CliCommand.disable:
91+
setActiveStateCli(active: false)
92+
return true
93+
case CliCommand.set:
94+
setBrightnessOffsetCli()
95+
return true
96+
case CliCommand.status:
97+
statusCli()
98+
return true
99+
case CliCommand.help:
100+
helpCli()
101+
return true
102+
}
103+
}
104+
return false
105+
}

BrightIntosh/Localizable.xcstrings

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@
101101
"value" : ""
102102
}
103103
}
104-
}
104+
},
105+
"shouldTranslate" : false
105106
},
106107
"About us" : {
107108
"localizations" : {
@@ -592,6 +593,17 @@
592593
}
593594
}
594595
},
596+
"Close" : {
597+
"localizations" : {
598+
"en" : {
599+
"stringUnit" : {
600+
"state" : "translated",
601+
"value" : "Close"
602+
}
603+
}
604+
},
605+
"shouldTranslate" : false
606+
},
595607
"Deactivate" : {
596608
"localizations" : {
597609
"de" : {
@@ -1249,6 +1261,74 @@
12491261
}
12501262
}
12511263
},
1264+
"Install BrightIntosh CLI" : {
1265+
"localizations" : {
1266+
"de" : {
1267+
"stringUnit" : {
1268+
"state" : "translated",
1269+
"value" : "BrightIntosh CLI installieren"
1270+
}
1271+
},
1272+
"en" : {
1273+
"stringUnit" : {
1274+
"state" : "translated",
1275+
"value" : "Install BrightIntosh CLI"
1276+
}
1277+
},
1278+
"es" : {
1279+
"stringUnit" : {
1280+
"state" : "translated",
1281+
"value" : "Instalar BrightIntosh CLI"
1282+
}
1283+
},
1284+
"fr" : {
1285+
"stringUnit" : {
1286+
"state" : "translated",
1287+
"value" : "Installer BrightIntosh CLI"
1288+
}
1289+
},
1290+
"pt-PT" : {
1291+
"stringUnit" : {
1292+
"state" : "translated",
1293+
"value" : "Instalar a CLI do BrightIntosh"
1294+
}
1295+
}
1296+
}
1297+
},
1298+
"Install the BrightIntosh CLI" : {
1299+
"localizations" : {
1300+
"de" : {
1301+
"stringUnit" : {
1302+
"state" : "translated",
1303+
"value" : "Installiere das BrightIntosh CLI"
1304+
}
1305+
},
1306+
"en" : {
1307+
"stringUnit" : {
1308+
"state" : "translated",
1309+
"value" : "Install the BrightIntosh CLI"
1310+
}
1311+
},
1312+
"es" : {
1313+
"stringUnit" : {
1314+
"state" : "translated",
1315+
"value" : "Instalar el CLI de BrightIntosh"
1316+
}
1317+
},
1318+
"fr" : {
1319+
"stringUnit" : {
1320+
"state" : "translated",
1321+
"value" : "Installer le CLI BrightIntosh"
1322+
}
1323+
},
1324+
"pt-PT" : {
1325+
"stringUnit" : {
1326+
"state" : "translated",
1327+
"value" : "Instalar o BrightIntosh CLI"
1328+
}
1329+
}
1330+
}
1331+
},
12521332
"Launch on login" : {
12531333
"localizations" : {
12541334
"de" : {

0 commit comments

Comments
 (0)