Skip to content

Commit a5164b8

Browse files
committed
feat: export plugin
Signed-off-by: Lessica <82flex@gmail.com>
1 parent 7fb7d05 commit a5164b8

File tree

7 files changed

+76
-18
lines changed

7 files changed

+76
-18
lines changed

TrollFools/EjectListView.swift

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ struct EjectListView: View {
1313
@StateObject var searchViewModel = AppListSearchModel()
1414
@StateObject var ejectList: EjectListModel
1515

16+
@State var quickLookExport: URL?
17+
@State var isDeletingAll = false
1618
@State var isErrorOccurred: Bool = false
1719
@State var lastError: Error?
1820

19-
@State var isDeletingAll = false
2021
@StateObject var viewControllerHost = ViewControllerHost()
2122

2223
@AppStorage var useWeakReference: Bool
@@ -32,6 +33,7 @@ struct EjectListView: View {
3233

3334
var body: some View {
3435
refreshableListView
36+
.quickLookPreview($quickLookExport)
3537
}
3638

3739
var refreshableListView: some View {
@@ -103,17 +105,10 @@ struct EjectListView: View {
103105
var ejectListView: some View {
104106
List {
105107
Section {
106-
ForEach(ejectList.filteredPlugIns) { plugin in
107-
if #available(iOS 16, *) {
108-
PlugInCell(plugIn: plugin)
109-
.environmentObject(ejectList)
110-
} else {
111-
PlugInCell(plugIn: plugin)
112-
.environmentObject(ejectList)
113-
.padding(.vertical, 4)
114-
}
108+
ForEach(ejectList.filteredPlugIns) {
109+
deletablePlugInCell($0)
115110
}
116-
.onDelete(perform: delete)
111+
.onDelete(perform: deletePlugIns)
117112
} header: {
118113
paddedHeaderFooterText(ejectList.filteredPlugIns.isEmpty
119114
? NSLocalizedString("No Injected Plug-Ins", comment: "")
@@ -178,7 +173,20 @@ struct EjectListView: View {
178173
}
179174
}
180175

181-
private func delete(at offsets: IndexSet) {
176+
private func deletablePlugInCell(_ plugin: InjectedPlugIn) -> some View {
177+
Group {
178+
if #available(iOS 16, *) {
179+
PlugInCell(plugin, quickLookExport: $quickLookExport)
180+
.environmentObject(ejectList)
181+
} else {
182+
PlugInCell(plugin, quickLookExport: $quickLookExport)
183+
.environmentObject(ejectList)
184+
.padding(.vertical, 4)
185+
}
186+
}
187+
}
188+
189+
private func deletePlugIns(at offsets: IndexSet) {
182190
do {
183191
let plugInsToRemove = offsets.map { ejectList.filteredPlugIns[$0] }
184192
let plugInURLsToRemove = plugInsToRemove.map { $0.url }
@@ -200,6 +208,25 @@ struct EjectListView: View {
200208
}
201209
}
202210

211+
private func deletePlugIn(_ plugin: InjectedPlugIn) {
212+
do {
213+
let injector = try InjectorV3(ejectList.app.url)
214+
injector.useWeakReference = useWeakReference
215+
injector.preferMainExecutable = preferMainExecutable
216+
injector.injectStrategy = injectStrategy
217+
218+
try injector.eject([plugin.url])
219+
220+
ejectList.app.reload()
221+
ejectList.reload()
222+
} catch {
223+
DDLogError("\(error)", ddlog: InjectorV3.main.logger)
224+
225+
lastError = error
226+
isErrorOccurred = true
227+
}
228+
}
229+
203230
private func deleteAll() {
204231
do {
205232
let injector = try InjectorV3(ejectList.app.url)
@@ -219,8 +246,8 @@ struct EjectListView: View {
219246
DispatchQueue.main.async {
220247
ejectList.app.reload()
221248
ejectList.reload()
222-
isDeletingAll = false
223249

250+
isDeletingAll = false
224251
view?.isUserInteractionEnabled = true
225252
}
226253
}

TrollFools/InjectedPlugIn.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
import Foundation
99

1010
struct InjectedPlugIn: Identifiable, Hashable {
11-
let id = UUID()
11+
let id: String
1212
let url: URL
1313
let createdAt: Date
1414

1515
init(url: URL) {
16+
self.id = url.absoluteString
1617
self.url = url
1718
let attributes = try? FileManager.default.attributesOfItem(atPath: url.path)
1819
self.createdAt = attributes?[.creationDate] as? Date ?? Date()

TrollFools/PlugInCell.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Created by 82Flex on 2024/10/30.
66
//
77

8+
import QuickLook
89
import SwiftUI
910

1011
private let gDateFormatter: DateFormatter = {
@@ -17,8 +18,15 @@ private let gDateFormatter: DateFormatter = {
1718
struct PlugInCell: View {
1819
@EnvironmentObject var ejectList: EjectListModel
1920

21+
@Binding var quickLookExport: URL?
22+
2023
let plugIn: InjectedPlugIn
2124

25+
init(_ plugIn: InjectedPlugIn, quickLookExport: Binding<URL?>) {
26+
self.plugIn = plugIn
27+
_quickLookExport = quickLookExport
28+
}
29+
2230
@available(iOS 15, *)
2331
var highlightedName: AttributedString {
2432
let name = plugIn.url.lastPathComponent
@@ -65,6 +73,12 @@ struct PlugInCell: View {
6573
}
6674
}
6775
.contextMenu {
76+
Button {
77+
exportPlugIn()
78+
} label: {
79+
Label(NSLocalizedString("Export", comment: ""), systemImage: "square.and.arrow.up")
80+
}
81+
6882
Button {
6983
openInFilza()
7084
} label: {
@@ -78,6 +92,10 @@ struct PlugInCell: View {
7892
}
7993
}
8094

95+
private func exportPlugIn() {
96+
quickLookExport = plugIn.url
97+
}
98+
8199
var isFilzaInstalled: Bool { ejectList.app.appList?.isFilzaInstalled ?? false }
82100

83101
private func openInFilza() {

TrollFools/en.lproj/Localizable.strings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
/* No comment provided by engineer. */
5353
"Error" = "Error";
5454

55+
/* No comment provided by engineer. */
56+
"Export" = "Export";
57+
5558
/* No comment provided by engineer. */
5659
"Failed" = "Failed";
5760

TrollFools/it.lproj/Localizable.strings

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
/* No comment provided by engineer. */
5353
"Error" = "Errore";
5454

55+
/* TODO */
56+
"Export" = "Export";
57+
5558
/* No comment provided by engineer. */
5659
"Failed" = "Fallito";
5760

@@ -190,7 +193,7 @@
190193
/* No comment provided by engineer. */
191194
"TrollRecorder" = "TrollRecorder";
192195

193-
/* TODO */
196+
/* No comment provided by engineer. */
194197
"TrollStore" = "TrollStore";
195198

196199
/* No comment provided by engineer. */

TrollFools/vi.lproj/Localizable.strings

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
/* No comment provided by engineer. */
5353
"Error" = "Lỗi";
5454

55+
/* TODO */
56+
"Export" = "Export";
57+
5558
/* No comment provided by engineer. */
5659
"Failed" = "Thất bại";
5760

@@ -154,7 +157,7 @@
154157
/* TODO */
155158
"Record your phone calls like never before." = "Record your phone calls like never before.";
156159

157-
/* TODO */
160+
/* No comment provided by engineer. */
158161
"Reveil" = "Reveil";
159162

160163
/* No comment provided by engineer. */
@@ -187,10 +190,10 @@
187190
/* No comment provided by engineer. */
188191
"TrollFools" = "TrollFools";
189192

190-
/* TODO */
193+
/* No comment provided by engineer. */
191194
"TrollRecorder" = "TrollRecorder";
192195

193-
/* TODO */
196+
/* No comment provided by engineer. */
194197
"TrollStore" = "TrollStore";
195198

196199
/* No comment provided by engineer. */

TrollFools/zh-Hans.lproj/Localizable.strings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
/* No comment provided by engineer. */
5353
"Error" = "错误";
5454

55+
/* No comment provided by engineer. */
56+
"Export" = "导出";
57+
5558
/* No comment provided by engineer. */
5659
"Failed" = "失败";
5760

0 commit comments

Comments
 (0)