Skip to content

Commit 74a0e7f

Browse files
committed
Use mirror when running shell commands
1 parent 5462a12 commit 74a0e7f

3 files changed

Lines changed: 45 additions & 4 deletions

File tree

Applite.xcodeproj/project.pbxproj

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
4101EB4C2DCE66D100BE0670 /* Array+SafeSubscript.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4101EB4B2DCE66D100BE0670 /* Array+SafeSubscript.swift */; };
2222
4101EB4E2DCE670400BE0670 /* URL+ChecksumInBase64.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4101EB4D2DCE670400BE0670 /* URL+ChecksumInBase64.swift */; };
2323
4101EB502DCE6BBB00BE0670 /* SettingsView+Mirrors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4101EB4F2DCE6BBB00BE0670 /* SettingsView+Mirrors.swift */; };
24+
4101EB552DCE7FA000BE0670 /* MirrorEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4101EB542DCE7FA000BE0670 /* MirrorEnvironment.swift */; };
2425
4104D7432A8FC52C00F84F9B /* Preferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4104D7422A8FC52C00F84F9B /* Preferences.swift */; };
2526
41062C952A3794EA00FD48EA /* BrewPaths.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41062C942A3794EA00FD48EA /* BrewPaths.swift */; };
2627
41062C972A3A20F900FD48EA /* UninstallSelf.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41062C962A3A20F900FD48EA /* UninstallSelf.swift */; };
@@ -176,6 +177,7 @@
176177
4101EB4B2DCE66D100BE0670 /* Array+SafeSubscript.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Array+SafeSubscript.swift"; sourceTree = "<group>"; };
177178
4101EB4D2DCE670400BE0670 /* URL+ChecksumInBase64.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "URL+ChecksumInBase64.swift"; sourceTree = "<group>"; };
178179
4101EB4F2DCE6BBB00BE0670 /* SettingsView+Mirrors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SettingsView+Mirrors.swift"; sourceTree = "<group>"; };
180+
4101EB542DCE7FA000BE0670 /* MirrorEnvironment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MirrorEnvironment.swift; sourceTree = "<group>"; };
179181
4104D7422A8FC52C00F84F9B /* Preferences.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Preferences.swift; sourceTree = "<group>"; };
180182
41062C942A3794EA00FD48EA /* BrewPaths.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrewPaths.swift; sourceTree = "<group>"; };
181183
41062C962A3A20F900FD48EA /* UninstallSelf.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UninstallSelf.swift; sourceTree = "<group>"; };
@@ -361,6 +363,14 @@
361363
path = String;
362364
sourceTree = "<group>";
363365
};
366+
4101EB532DCE7F7F00BE0670 /* Mirror */ = {
367+
isa = PBXGroup;
368+
children = (
369+
4101EB542DCE7FA000BE0670 /* MirrorEnvironment.swift */,
370+
);
371+
path = Mirror;
372+
sourceTree = "<group>";
373+
};
364374
4104D7442A8FC53200F84F9B /* Preferences */ = {
365375
isa = PBXGroup;
366376
children = (
@@ -560,6 +570,7 @@
560570
4126353F2A77C71F00155034 /* Shell */,
561571
41B731352A878993008BF6B9 /* App Migration */,
562572
413E60B52BBAE58B00978F6A /* Network Proxy */,
573+
4101EB532DCE7F7F00BE0670 /* Mirror */,
563574
419256652D1E18A500D9EF10 /* Alert Manager */,
564575
419256102D1DDB9700D9EF10 /* Other */,
565576
);
@@ -879,6 +890,7 @@
879890
files = (
880891
413F87322D33E30400D4BE10 /* SortingOptions.swift in Sources */,
881892
4196C90028F9E1F400EADDDA /* InstalledView.swift in Sources */,
893+
4101EB552DCE7FA000BE0670 /* MirrorEnvironment.swift in Sources */,
882894
415563A42A98C54300AE2F2E /* AppdirSelectorView.swift in Sources */,
883895
4140750528DF5FA60073EB22 /* AppView.swift in Sources */,
884896
415135642D32C4360025DB70 /* Cask+Identifiable.swift in Sources */,
@@ -1142,7 +1154,7 @@
11421154
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
11431155
CODE_SIGN_STYLE = Automatic;
11441156
COMBINE_HIDPI_IMAGES = YES;
1145-
CURRENT_PROJECT_VERSION = 17;
1157+
CURRENT_PROJECT_VERSION = 18;
11461158
DEAD_CODE_STRIPPING = YES;
11471159
DEVELOPMENT_ASSET_PATHS = "\"Applite/Preview Content\"";
11481160
ENABLE_HARDENED_RUNTIME = YES;
@@ -1158,7 +1170,7 @@
11581170
"@executable_path/../Frameworks",
11591171
);
11601172
MACOSX_DEPLOYMENT_TARGET = 13.0;
1161-
MARKETING_VERSION = 1.3.0;
1173+
MARKETING_VERSION = 1.3.1;
11621174
PRODUCT_BUNDLE_IDENTIFIER = dev.aerolite.Applite;
11631175
PRODUCT_NAME = "$(TARGET_NAME)";
11641176
SWIFT_EMIT_LOC_STRINGS = YES;
@@ -1176,7 +1188,7 @@
11761188
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
11771189
CODE_SIGN_STYLE = Automatic;
11781190
COMBINE_HIDPI_IMAGES = YES;
1179-
CURRENT_PROJECT_VERSION = 17;
1191+
CURRENT_PROJECT_VERSION = 18;
11801192
DEAD_CODE_STRIPPING = YES;
11811193
DEVELOPMENT_ASSET_PATHS = "\"Applite/Preview Content\"";
11821194
ENABLE_HARDENED_RUNTIME = YES;
@@ -1192,7 +1204,7 @@
11921204
"@executable_path/../Frameworks",
11931205
);
11941206
MACOSX_DEPLOYMENT_TARGET = 13.0;
1195-
MARKETING_VERSION = 1.3.0;
1207+
MARKETING_VERSION = 1.3.1;
11961208
PRODUCT_BUNDLE_IDENTIFIER = dev.aerolite.Applite;
11971209
PRODUCT_NAME = "$(TARGET_NAME)";
11981210
SWIFT_EMIT_LOC_STRINGS = YES;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// MirrorEnvironment.swift
3+
// Applite
4+
//
5+
// Created by Milán Várady on 2025.05.09.
6+
//
7+
8+
import Foundation
9+
10+
enum MirrorEnvironment {
11+
static func getEnvironmentVariables() -> [String: String]? {
12+
let defaults = UserDefaults.standard
13+
let isEnabled = defaults.bool(forKey: Preferences.mirrorEnabled.rawValue)
14+
15+
guard isEnabled else { return nil }
16+
17+
return [
18+
"HOMEBREW_API_DOMAIN": defaults.string(forKey: Preferences.mirrorAPIDomain.rawValue) ?? "",
19+
"HOMEBREW_BREW_GIT_REMOTE": defaults.string(forKey: Preferences.mirrorBrewGitRemote.rawValue) ?? "",
20+
"HOMEBREW_CORE_GIT_REMOTE": defaults.string(forKey: Preferences.mirrorCoreGitRemote.rawValue) ?? "",
21+
"HOMEBREW_BOTTLE_DOMAIN": defaults.string(forKey: Preferences.mirrorBottleDomain.rawValue) ?? ""
22+
]
23+
}
24+
}

Applite/Utilities/Shell/Shell.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ enum Shell {
163163
environment["ALL_PROXY"] = proxySettings.fullString
164164
}
165165

166+
if let mirrorEnvironmentVariables = MirrorEnvironment.getEnvironmentVariables() {
167+
logger.info("Mirror enabled. API domain: \(mirrorEnvironmentVariables["HOMEBREW_API_DOMAIN"] ?? "not set")")
168+
environment.merge(mirrorEnvironmentVariables) { (_, new) in new }
169+
}
170+
166171
task.standardOutput = pipe
167172
task.standardError = pipe
168173
task.environment = environment

0 commit comments

Comments
 (0)