Skip to content

Commit c774822

Browse files
committed
common refactor
Signed-off-by: Lessica <[email protected]>
1 parent c711543 commit c774822

File tree

2 files changed

+117
-114
lines changed

2 files changed

+117
-114
lines changed

TrollFools/AppListCell.swift

Lines changed: 75 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -33,81 +33,6 @@ struct AppListCell: View {
3333
return attributedString
3434
}
3535

36-
@ViewBuilder
37-
var cellContextMenu: some View {
38-
Button {
39-
launch()
40-
} label: {
41-
Label(NSLocalizedString("Launch", comment: ""), systemImage: "command")
42-
}
43-
44-
if AppListModel.hasTrollStore && app.isAllowedToAttachOrDetach {
45-
if app.isDetached {
46-
Button {
47-
do {
48-
try InjectorV3(app.url).setMetadataDetached(false)
49-
app.reload()
50-
appList.isRebuildNeeded = true
51-
} catch { DDLogError("\(error)", ddlog: InjectorV3.main.logger) }
52-
} label: {
53-
Label(NSLocalizedString("Unlock Version", comment: ""), systemImage: "lock.open")
54-
}
55-
} else {
56-
Button {
57-
do {
58-
try InjectorV3(app.url).setMetadataDetached(true)
59-
app.reload()
60-
appList.isRebuildNeeded = true
61-
} catch { DDLogError("\(error)", ddlog: InjectorV3.main.logger) }
62-
} label: {
63-
Label(NSLocalizedString("Lock Version", comment: ""), systemImage: "lock")
64-
}
65-
}
66-
}
67-
68-
Button {
69-
openInFilza()
70-
} label: {
71-
if isFilzaInstalled {
72-
Label(NSLocalizedString("Show in Filza", comment: ""), systemImage: "scope")
73-
} else {
74-
Label(NSLocalizedString("Filza (URL Scheme) Not Installed", comment: ""), systemImage: "xmark.octagon")
75-
}
76-
}
77-
.disabled(!isFilzaInstalled)
78-
}
79-
80-
@ViewBuilder
81-
var cellContextMenuWrapper: some View {
82-
if #available(iOS 16, *) {
83-
// iOS 16
84-
cellContextMenu
85-
} else {
86-
if #available(iOS 15, *) { }
87-
else {
88-
// iOS 14
89-
cellContextMenu
90-
}
91-
}
92-
}
93-
94-
@ViewBuilder
95-
var cellBackground: some View {
96-
if #available(iOS 15, *) {
97-
if #available(iOS 16, *) { }
98-
else {
99-
// iOS 15
100-
Color.clear
101-
.contextMenu {
102-
if !appList.isSelectorMode {
103-
cellContextMenu
104-
}
105-
}
106-
.id(app.isDetached)
107-
}
108-
}
109-
}
110-
11136
var body: some View {
11237
HStack(spacing: 12) {
11338
if #available(iOS 15, *) {
@@ -188,6 +113,81 @@ struct AppListCell: View {
188113
.background(cellBackground)
189114
}
190115

116+
@ViewBuilder
117+
var cellContextMenu: some View {
118+
Button {
119+
launch()
120+
} label: {
121+
Label(NSLocalizedString("Launch", comment: ""), systemImage: "command")
122+
}
123+
124+
if AppListModel.hasTrollStore && app.isAllowedToAttachOrDetach {
125+
if app.isDetached {
126+
Button {
127+
do {
128+
try InjectorV3(app.url).setMetadataDetached(false)
129+
app.reload()
130+
appList.isRebuildNeeded = true
131+
} catch { DDLogError("\(error)", ddlog: InjectorV3.main.logger) }
132+
} label: {
133+
Label(NSLocalizedString("Unlock Version", comment: ""), systemImage: "lock.open")
134+
}
135+
} else {
136+
Button {
137+
do {
138+
try InjectorV3(app.url).setMetadataDetached(true)
139+
app.reload()
140+
appList.isRebuildNeeded = true
141+
} catch { DDLogError("\(error)", ddlog: InjectorV3.main.logger) }
142+
} label: {
143+
Label(NSLocalizedString("Lock Version", comment: ""), systemImage: "lock")
144+
}
145+
}
146+
}
147+
148+
Button {
149+
openInFilza()
150+
} label: {
151+
if isFilzaInstalled {
152+
Label(NSLocalizedString("Show in Filza", comment: ""), systemImage: "scope")
153+
} else {
154+
Label(NSLocalizedString("Filza (URL Scheme) Not Installed", comment: ""), systemImage: "xmark.octagon")
155+
}
156+
}
157+
.disabled(!isFilzaInstalled)
158+
}
159+
160+
@ViewBuilder
161+
var cellContextMenuWrapper: some View {
162+
if #available(iOS 16, *) {
163+
// iOS 16
164+
cellContextMenu
165+
} else {
166+
if #available(iOS 15, *) { }
167+
else {
168+
// iOS 14
169+
cellContextMenu
170+
}
171+
}
172+
}
173+
174+
@ViewBuilder
175+
var cellBackground: some View {
176+
if #available(iOS 15, *) {
177+
if #available(iOS 16, *) { }
178+
else {
179+
// iOS 15
180+
Color.clear
181+
.contextMenu {
182+
if !appList.isSelectorMode {
183+
cellContextMenu
184+
}
185+
}
186+
.id(app.isDetached)
187+
}
188+
}
189+
}
190+
191191
private func launch() {
192192
LSApplicationWorkspace.default().openApplication(withBundleID: app.id)
193193
}

TrollFools/EjectListView.swift

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -35,45 +35,7 @@ struct EjectListView: View {
3535

3636
var body: some View {
3737
refreshableListView
38-
.toolbar {
39-
ToolbarItem(placement: .topBarTrailing) {
40-
if #available(iOS 16.4, *) {
41-
ShareLink(
42-
item: CompressedFileRepresentation(
43-
name: "\(ejectList.app.name)_\(ejectList.app.id)_\(UUID().uuidString.components(separatedBy: "-").last ?? "").zip",
44-
urls: ejectList.injectedPlugIns.map(\.url)
45-
),
46-
preview: SharePreview(
47-
String(format: NSLocalizedString("%ld Plug-Ins of “%@”", comment: ""), ejectList.injectedPlugIns.count, ejectList.app.name)
48-
)
49-
) {
50-
if isExportingAll {
51-
ProgressView()
52-
.progressViewStyle(CircularProgressViewStyle())
53-
.transition(.opacity)
54-
} else {
55-
Label(NSLocalizedString("Export All", comment: ""), systemImage: "square.and.arrow.up")
56-
.transition(.opacity)
57-
}
58-
}
59-
.disabled(ejectList.injectedPlugIns.isEmpty)
60-
} else {
61-
Button {
62-
exportAll()
63-
} label: {
64-
if isExportingAll {
65-
ProgressView()
66-
.progressViewStyle(CircularProgressViewStyle())
67-
.transition(.opacity)
68-
} else {
69-
Label(NSLocalizedString("Export All", comment: ""), systemImage: "square.and.arrow.up")
70-
.transition(.opacity)
71-
}
72-
}
73-
.disabled(ejectList.injectedPlugIns.isEmpty)
74-
}
75-
}
76-
}
38+
.toolbar { toolbarContent }
7739
.animation(.easeOut, value: isExportingAll)
7840
.quickLookPreview($quickLookExport)
7941
}
@@ -215,6 +177,47 @@ struct EjectListView: View {
215177
}
216178
}
217179

180+
@ToolbarContentBuilder
181+
var toolbarContent: some ToolbarContent {
182+
ToolbarItem(placement: .topBarTrailing) {
183+
if #available(iOS 16.4, *) {
184+
ShareLink(
185+
item: CompressedFileRepresentation(
186+
name: "\(ejectList.app.name)_\(ejectList.app.id)_\(UUID().uuidString.components(separatedBy: "-").last ?? "").zip",
187+
urls: ejectList.injectedPlugIns.map(\.url)
188+
),
189+
preview: SharePreview(
190+
String(format: NSLocalizedString("%ld Plug-Ins of “%@”", comment: ""), ejectList.injectedPlugIns.count, ejectList.app.name)
191+
)
192+
) {
193+
if isExportingAll {
194+
ProgressView()
195+
.progressViewStyle(CircularProgressViewStyle())
196+
.transition(.opacity)
197+
} else {
198+
Label(NSLocalizedString("Export All", comment: ""), systemImage: "square.and.arrow.up")
199+
.transition(.opacity)
200+
}
201+
}
202+
.disabled(ejectList.injectedPlugIns.isEmpty)
203+
} else {
204+
Button {
205+
exportAll()
206+
} label: {
207+
if isExportingAll {
208+
ProgressView()
209+
.progressViewStyle(CircularProgressViewStyle())
210+
.transition(.opacity)
211+
} else {
212+
Label(NSLocalizedString("Export All", comment: ""), systemImage: "square.and.arrow.up")
213+
.transition(.opacity)
214+
}
215+
}
216+
.disabled(ejectList.injectedPlugIns.isEmpty)
217+
}
218+
}
219+
}
220+
218221
private func deletablePlugInCell(_ plugin: InjectedPlugIn) -> some View {
219222
Group {
220223
if #available(iOS 16, *) {

0 commit comments

Comments
 (0)