mirror of
https://github.com/StikDebug/StikDebug.git
synced 2026-10-16 04:20:30 +00:00
Quality of life enhancements
This commit is contained in:
parent
3aa9b4603e
commit
47dfbbed6c
11 changed files with 443 additions and 91 deletions
95
DebugWidget/DebugWidget.swift
Normal file
95
DebugWidget/DebugWidget.swift
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
//
|
||||
// DebugWidget.swift
|
||||
// DebugWidget
|
||||
//
|
||||
// Created by Stephen on 5/30/25.
|
||||
//
|
||||
|
||||
import WidgetKit
|
||||
import SwiftUI
|
||||
import UIKit
|
||||
|
||||
// MARK: - Timeline Entry
|
||||
struct AppsEntry: TimelineEntry {
|
||||
let date: Date
|
||||
let bundleIDs: [String]
|
||||
}
|
||||
|
||||
// MARK: - Provider
|
||||
struct AppsProvider: TimelineProvider {
|
||||
private let sharedDefaults = UserDefaults(suiteName: "group.com.stik.sj")
|
||||
|
||||
func placeholder(in context: Context) -> AppsEntry {
|
||||
AppsEntry(date: .now, bundleIDs: [])
|
||||
}
|
||||
|
||||
func getSnapshot(in context: Context, completion: @escaping (AppsEntry) -> Void) {
|
||||
completion(makeEntry())
|
||||
}
|
||||
|
||||
func getTimeline(in context: Context, completion: @escaping (Timeline<AppsEntry>) -> Void) {
|
||||
let entry = makeEntry()
|
||||
completion(Timeline(entries: [entry], policy: .never))
|
||||
}
|
||||
|
||||
private func makeEntry() -> AppsEntry {
|
||||
let favs = sharedDefaults?.stringArray(forKey: "favoriteApps") ?? []
|
||||
let bundleIDs = Array(favs.prefix(4))
|
||||
return AppsEntry(date: .now, bundleIDs: bundleIDs)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Widget View
|
||||
struct AppsWidgetEntryView: View {
|
||||
let entry: AppsEntry
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 8) {
|
||||
ForEach(0..<4, id: \.self) { idx in
|
||||
if idx < entry.bundleIDs.count {
|
||||
IconCell(bundleID: entry.bundleIDs[idx])
|
||||
} else {
|
||||
PlaceholderCell()
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(8)
|
||||
.containerBackground(Color(UIColor.systemBackground), for: .widget)
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private func IconCell(bundleID: String) -> some View {
|
||||
if let img = loadIcon(for: bundleID) {
|
||||
Link(destination: URL(string: "stikjit://enable-jit?bundle-id=\(bundleID)")!) {
|
||||
Image(uiImage: img)
|
||||
.resizable()
|
||||
.aspectRatio(1, contentMode: .fit)
|
||||
.cornerRadius(12)
|
||||
}
|
||||
} else {
|
||||
PlaceholderCell()
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private func PlaceholderCell() -> some View {
|
||||
ZStack {
|
||||
RoundedRectangle(cornerRadius: 12)
|
||||
.fill(Color(UIColor.systemGray5))
|
||||
Image(systemName: "plus")
|
||||
.font(.system(size: 24, weight: .medium))
|
||||
.foregroundColor(.gray)
|
||||
}
|
||||
.aspectRatio(1, contentMode: .fit)
|
||||
}
|
||||
|
||||
private func loadIcon(for bundleID: String) -> UIImage? {
|
||||
guard let container = FileManager.default.containerURL(
|
||||
forSecurityApplicationGroupIdentifier: "group.com.stik.sj")
|
||||
else { return nil }
|
||||
let url = container
|
||||
.appendingPathComponent("icons", isDirectory: true)
|
||||
.appendingPathComponent("\(bundleID).png")
|
||||
return UIImage(contentsOfFile: url.path)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue