Skip to content

Commit

Permalink
Fix environment variables when launching via alias (PlayCover#1090)
Browse files Browse the repository at this point in the history
* fix: metalhud not working when launch from alias

* fix: environment variables

---------

Co-authored-by: José Moreno <47700212+JoseMoreville@users.noreply.github.com>
  • Loading branch information
TheMoonThatRises and JoseMoreville authored Sep 25, 2023
1 parent 9d8beb2 commit 6785597
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
25 changes: 25 additions & 0 deletions PlayCover/Model/AppInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,31 @@ public class AppInfo {
return "AppIcon"
}

var lsEnvironment: [String: String] {
get {
if self[dictionary: "LSEnvironment"] == nil {
self[dictionary: "LSEnvironment"] = NSMutableDictionary(dictionary: [String: String]())
}

return self[dictionary: "LSEnvironment"] as? [String: String] ?? [:]
}
set {
if self[dictionary: "LSEnvironment"] == nil {
self[dictionary: "LSEnvironment"] = NSMutableDictionary(dictionary: [String: String]())
}

if let key = newValue.first?.key, let value = newValue.first?.value {
self[dictionary: "LSEnvironment"]?[key] = value

do {
try write()
} catch {
Log.shared.error(error)
}
}
}
}

func assert(minimumVersion: Double) {
if let double = Double(minimumOSVersion) {
if double > 11.0 {
Expand Down
27 changes: 27 additions & 0 deletions PlayCover/Model/PlayApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,33 @@ class PlayApp: BaseApp {
}
}

func introspection(set: Bool? = nil) -> Bool {
if info.lsEnvironment["DYLD_LIBRARY_PATH"] == nil {
info.lsEnvironment["DYLD_LIBRARY_PATH"] = ""
}

if let set = set {
if set {
info.lsEnvironment["DYLD_LIBRARY_PATH"]? += "/usr/lib/system/introspection:"
} else {
info.lsEnvironment["DYLD_LIBRARY_PATH"] = info.lsEnvironment["DYLD_LIBRARY_PATH"]?
.replacingOccurrences(of: "/usr/lib/system/introspection:", with: "")
}

do {
try Shell.signApp(executable)
} catch {
Log.shared.error(error)
}
}

guard let introspection = info.lsEnvironment["DYLD_LIBRARY_PATH"] else {
return false
}

return introspection.contains("/usr/lib/system/introspection")
}

func hasAlias() -> Bool {
return FileManager.default.fileExists(atPath: aliasURL.path)
}
Expand Down
13 changes: 11 additions & 2 deletions PlayCover/Views/AppSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ struct AppSettingsView: View {
}
.disabled(!(hasPlayTools ?? true))
BypassesView(settings: $viewModel.settings,
hasPlayTools: $hasPlayTools)
hasPlayTools: $hasPlayTools,
hasIntrospection: viewModel.app.introspection(),
app: viewModel.app)
.tabItem {
Text("settings.tab.bypasses")
}
Expand Down Expand Up @@ -442,6 +444,10 @@ struct BypassesView: View {
@Binding var settings: AppSettings
@Binding var hasPlayTools: Bool?

@State var hasIntrospection: Bool

var app: PlayApp

var body: some View {
ScrollView {
VStack {
Expand All @@ -462,13 +468,16 @@ struct BypassesView: View {
}
Spacer()
HStack {
Toggle("settings.toggle.introspection", isOn: $settings.settings.injectIntrospection)
Toggle("settings.toggle.introspection", isOn: $hasIntrospection)
.help("settings.toggle.introspection.help")
Spacer()
}
}
.padding()
}
.onChange(of: hasIntrospection) {_ in
_ = app.introspection(set: hasIntrospection)
}
}
}

Expand Down

0 comments on commit 6785597

Please sign in to comment.