Skip to content

Commit 674e7c0

Browse files
committed
feat: load persisted plugins
Signed-off-by: 82Flex <[email protected]>
1 parent 56fd94c commit 674e7c0

File tree

7 files changed

+37
-9
lines changed

7 files changed

+37
-9
lines changed

TrollFools/EjectListModel.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ final class EjectListModel: ObservableObject {
1515
@Published var filter = FilterOptions()
1616
@Published var filteredPlugIns: [InjectedPlugIn] = []
1717

18+
@Published var isOkToEnableAll = false
19+
@Published var isOkToDisableAll = false
20+
1821
private var cancellables = Set<AnyCancellable>()
1922

2023
init(_ app: App) {
@@ -30,8 +33,18 @@ final class EjectListModel: ObservableObject {
3033
}
3134

3235
func reload() {
33-
self.injectedPlugIns = InjectorV3.main.injectedAssetURLsInBundle(app.url)
36+
var plugIns = [InjectedPlugIn]()
37+
plugIns += InjectorV3.main.injectedAssetURLsInBundle(app.url)
3438
.map { InjectedPlugIn(url: $0, isEnabled: true) }
39+
40+
let enabledNames = plugIns.map { $0.url.lastPathComponent }
41+
plugIns += InjectorV3.main.persistedAssetURLs(id: app.id)
42+
.filter { !enabledNames.contains($0.lastPathComponent) }
43+
.map { InjectedPlugIn(url: $0, isEnabled: false) }
44+
45+
injectedPlugIns = plugIns
46+
.sorted { $0.url.lastPathComponent.localizedStandardCompare($1.url.lastPathComponent) == .orderedAscending }
47+
3548
performFilter()
3649
}
3750

@@ -45,5 +58,7 @@ final class EjectListModel: ObservableObject {
4558
}
4659

4760
self.filteredPlugIns = filteredPlugIns
61+
self.isOkToEnableAll = filteredPlugIns.contains { !$0.isEnabled }
62+
self.isOkToDisableAll = filteredPlugIns.contains { $0.isEnabled }
4863
}
4964
}

TrollFools/EjectListView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ struct EjectListView: View {
126126
if !ejectList.filter.isSearching && !ejectList.filteredPlugIns.isEmpty {
127127
Section {
128128
enableAllButton
129-
.disabled(isEnablingAll)
129+
.disabled(isEnablingAll || !ejectList.isOkToEnableAll)
130130
.foregroundColor(isEnablingAll ? .secondary : .accentColor)
131131

132132
disableAllButton
133-
.disabled(isDisablingAll)
133+
.disabled(isDisablingAll || !ejectList.isOkToDisableAll)
134134
.foregroundColor(isDisablingAll ? .secondary : .accentColor)
135135
}
136136

TrollFools/IndexableScroller.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct IndexableScroller: View {
3131
.updating($dragLocation) { value, state, _ in
3232
state = value.location
3333
}
34-
.onEnded { value in
34+
.onEnded { _ in
3535
currentIndex = nil
3636
}
3737
)

TrollFools/InjectorV3+Bundle.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ extension InjectorV3 {
102102
.sorted(by: { $0.lastPathComponent.localizedStandardCompare($1.lastPathComponent) == .orderedAscending })
103103
}
104104

105-
func injectedBundleURLsInBundle(_ target: URL) -> [URL] {
105+
fileprivate func injectedBundleURLsInBundle(_ target: URL) -> [URL] {
106106
precondition(checkIsBundle(target), "Not a bundle: \(target.path)")
107107

108108
guard let bundleContentURLs = try? FileManager.default.contentsOfDirectory(at: target, includingPropertiesForKeys: [.isDirectoryKey]) else {
@@ -125,7 +125,7 @@ extension InjectorV3 {
125125
return bundleURLs
126126
}
127127

128-
func injectedDylibAndFrameworkURLsInBundle(_ target: URL) -> [URL] {
128+
fileprivate func injectedDylibAndFrameworkURLsInBundle(_ target: URL) -> [URL] {
129129
precondition(checkIsBundle(target), "Not a bundle: \(target.path)")
130130

131131
let frameworksURL = target.appendingPathComponent("Frameworks")

TrollFools/InjectorV3+Persistent.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ extension InjectorV3 {
1212
for filteredURL in filteredURLs(assetURLs) {
1313
let destURL = persistentPlugInsDirectoryURL.appendingPathComponent(filteredURL.lastPathComponent)
1414
try cmdCopy(from: filteredURL, to: destURL, overwrite: true)
15+
try cmdChangeOwner(destURL, owner: 501, groupOwner: 501, recursively: checkIsDirectory(destURL))
1516
}
1617
}
1718

@@ -34,6 +35,16 @@ extension InjectorV3 {
3435
}
3536
}
3637

38+
func persistedAssetURLs(id: String) -> [URL] {
39+
let base = Self.persistentPlugInsRootURL.appendingPathComponent(id, isDirectory: true)
40+
guard let contents = try? FileManager.default.contentsOfDirectory(atPath: base.path) else {
41+
return []
42+
}
43+
return contents
44+
.sorted { $0.localizedStandardCompare($1) == .orderedAscending }
45+
.map { base.appendingPathComponent($0) }
46+
}
47+
3748
fileprivate func filteredURLs(_ assetURLs: [URL]) -> [URL] {
3849
assetURLs.filter {
3950
$0.pathExtension.lowercased() == "bundle" ||

TrollFools/InjectorV3.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ final class InjectorV3 {
119119

120120
// MARK: - Persistent
121121

122-
fileprivate static let persistentPlugInsRootURL: URL = {
122+
static let persistentPlugInsRootURL: URL = {
123123
let url = URL(fileURLWithPath: "/var/mobile/Library/TrollFools/PersistentPlugins")
124124
try? FileManager.default.createDirectory(at: url, withIntermediateDirectories: true)
125125
return url

TrollFools/PlugInCell.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ struct PlugInCell: View {
2020
@Environment(\.verticalSizeClass) var verticalSizeClass
2121

2222
@Binding var quickLookExport: URL?
23-
@State var isEnabled: Bool = true
23+
@State var isEnabled: Bool = false
2424

2525
let plugIn: InjectedPlugIn
2626

2727
init(_ plugIn: InjectedPlugIn, quickLookExport: Binding<URL?>) {
2828
self.plugIn = plugIn
2929
_quickLookExport = quickLookExport
30-
isEnabled = plugIn.isEnabled
3130
}
3231

3332
@available(iOS 15, *)
@@ -82,6 +81,9 @@ struct PlugInCell: View {
8281
}
8382
}
8483
}
84+
.onAppear {
85+
isEnabled = plugIn.isEnabled
86+
}
8587
.contextMenu {
8688
if #available(iOS 16.4, *) {
8789
ShareLink(item: plugIn.url) {

0 commit comments

Comments
 (0)