Skip to content

Commit

Permalink
bugfix: ios 15
Browse files Browse the repository at this point in the history
Signed-off-by: 82Flex <[email protected]>
  • Loading branch information
Lessica committed Jul 27, 2024
1 parent ab8a1e6 commit 5a23ef7
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 59 deletions.
138 changes: 84 additions & 54 deletions TrollFools/AppListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,7 @@ final class AppListModel: ObservableObject {

func rebuildIconCache() throws {
// Sadly, we can't call `trollstorehelper` directly because only TrollStore can launch it without error.
LSApplicationWorkspace.default()
.openApplication(withBundleID: "com.opa334.TrollStore")
LSApplicationWorkspace.default().openApplication(withBundleID: "com.opa334.TrollStore")
}
}

Expand Down Expand Up @@ -258,6 +257,80 @@ struct AppListCell: View {
return attributedString
}

@ViewBuilder
var cellContextMenu: some View {
Button {
launch()
} label: {
Label(NSLocalizedString("Launch", comment: ""), systemImage: "command")
}

if isFilzaInstalled {
Button {
openInFilza()
} label: {
Label(NSLocalizedString("Show in Filza", comment: ""), systemImage: "scope")
}
}

if AppListModel.hasTrollStore && app.isAllowedToAttachOrDetach {
if app.isDetached {
Button {
do {
let injector = try Injector(bundleURL: app.url, teamID: app.teamID)
try injector.setDetached(false)
withAnimation {
app.reload()
AppListModel.shared.isRebuildNeeded = true
}
} catch { DDLogError("\(error.localizedDescription)") }
} label: {
Label(NSLocalizedString("Unlock Version", comment: ""), systemImage: "lock.open")
}
} else {
Button {
do {
let injector = try Injector(bundleURL: app.url, teamID: app.teamID)
try injector.setDetached(true)
withAnimation {
app.reload()
AppListModel.shared.isRebuildNeeded = true
}
} catch { DDLogError("\(error.localizedDescription)") }
} label: {
Label(NSLocalizedString("Lock Version", comment: ""), systemImage: "lock")
}
}
}
}

@ViewBuilder
var cellContextMenuWrapper: some View {
if #available(iOS 16.0, *) {
// iOS 16
cellContextMenu
} else {
if #available(iOS 15.0, *) { }
else {
// iOS 14
cellContextMenu
}
}
}

@ViewBuilder
var cellBackground: some View {
if #available(iOS 15.0, *) {
if #available(iOS 16.0, *) { }
else {
// iOS 15
Color.clear
.contextMenu { cellContextMenu }
.id(app.isDetached)
}
}
}

var body: some View {
HStack(spacing: 12) {
Image(uiImage: app.alternateIcon ?? app.icon ?? UIImage())
Expand Down Expand Up @@ -318,56 +391,12 @@ struct AppListCell: View {
}
}
}
.contextMenu {
Button {
launch()
} label: {
Label(NSLocalizedString("Launch", comment: ""), systemImage: "command")
}

if isFilzaInstalled {
Button {
openInFilza()
} label: {
Label(NSLocalizedString("Show in Filza", comment: ""), systemImage: "scope")
}
}

if AppListModel.hasTrollStore && app.isAllowedToAttachOrDetach {
if app.isDetached {
Button {
do {
let injector = try Injector(bundleURL: app.url, teamID: app.teamID)
try injector.setDetached(false)
withAnimation {
app.reload()
AppListModel.shared.isRebuildNeeded = true
}
} catch { DDLogError("\(error.localizedDescription)") }
} label: {
Label(NSLocalizedString("Unlock Version", comment: ""), systemImage: "lock.open")
}
} else {
Button {
do {
let injector = try Injector(bundleURL: app.url, teamID: app.teamID)
try injector.setDetached(true)
withAnimation {
app.reload()
AppListModel.shared.isRebuildNeeded = true
}
} catch { DDLogError("\(error.localizedDescription)") }
} label: {
Label(NSLocalizedString("Lock Version", comment: ""), systemImage: "lock")
}
}
}
}
.contextMenu { cellContextMenuWrapper }
.background(cellBackground)
}

private func launch() {
LSApplicationWorkspace.default()
.openApplication(withBundleID: app.id)
LSApplicationWorkspace.default().openApplication(withBundleID: app.id)
}

var isFilzaInstalled: Bool { AppListModel.shared.isFilzaInstalled }
Expand Down Expand Up @@ -476,11 +505,6 @@ struct AppListView: View {
.padding(.vertical, 4)
}
.disabled(vm.isRebuilding)
} footer: {
NavigationLink(isActive: $isErrorOccurred) {
FailureView(title: NSLocalizedString("Error", comment: ""),
message: errorMessage)
} label: { }
}
}

Expand Down Expand Up @@ -529,6 +553,12 @@ struct AppListView: View {
}
.listStyle(.insetGrouped)
.navigationTitle(NSLocalizedString("TrollFools", comment: ""))
.background(Group {
NavigationLink(isActive: $isErrorOccurred) {
FailureView(title: NSLocalizedString("Error", comment: ""),
message: errorMessage)
} label: { }
})
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Button {
Expand Down
11 changes: 6 additions & 5 deletions TrollFools/EjectListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -209,17 +209,18 @@ struct EjectListView: View {
Text(NSLocalizedString("Some plug-ins were not injected by TrollFools, please eject them with caution.", comment: ""))
.font(.footnote)
}

NavigationLink(isActive: $isErrorOccurred) {
FailureView(title: NSLocalizedString("Error", comment: ""),
message: errorMessage)
} label: { }
}
}
}
.listStyle(.insetGrouped)
.navigationTitle(NSLocalizedString("Plug-Ins", comment: ""))
.animation(.easeOut, value: vm.filter.isSearching)
.background(Group {
NavigationLink(isActive: $isErrorOccurred) {
FailureView(title: NSLocalizedString("Error", comment: ""),
message: errorMessage)
} label: { }
})
.onViewWillAppear { viewController in
viewControllerHost.viewController = viewController
}
Expand Down

0 comments on commit 5a23ef7

Please sign in to comment.