2023-10-23 17:43:16 -06:00
|
|
|
import WidgetKit
|
|
|
|
import SwiftUI
|
|
|
|
import Intents
|
|
|
|
|
|
|
|
// Defines the view / layout of the widget
|
|
|
|
struct WonderousWidgetView : View {
|
|
|
|
@Environment(\.widgetFamily) var family: WidgetFamily
|
2023-11-02 09:58:07 -06:00
|
|
|
var entry: WonderousTimelineProvider.Entry
|
2023-10-23 17:43:16 -06:00
|
|
|
var body: some View {
|
|
|
|
let showTitle = family == .systemLarge
|
|
|
|
let showIcon = family != .systemSmall
|
|
|
|
let showTitleAndDesc = family != .systemSmall
|
|
|
|
|
|
|
|
let progress = Double(entry.discoveredCount) / 24.0
|
2023-10-25 16:33:57 -06:00
|
|
|
let iconImage = flutterAssetBundle.appending(
|
|
|
|
path: "/assets/images/widget/wonderous-icon.png"
|
|
|
|
).path()
|
|
|
|
let title = entry.title.isEmpty ? "Wonderous" : entry.title;
|
|
|
|
let subTitle = entry.subTitle.isEmpty ? "Search for hidden artifacts" : entry.subTitle;
|
2023-10-23 17:43:16 -06:00
|
|
|
let content = VStack{
|
|
|
|
HStack {
|
|
|
|
if(showTitle) {
|
|
|
|
Text("Collection")
|
|
|
|
.font(.system(size: 15))
|
2023-10-23 21:40:55 -06:00
|
|
|
.foregroundColor(.offWhite)
|
2023-10-23 17:43:16 -06:00
|
|
|
}
|
|
|
|
Spacer();
|
|
|
|
if(showIcon) {
|
|
|
|
Image(uiImage: UIImage(contentsOfFile: iconImage)!)
|
|
|
|
.resizable()
|
|
|
|
.scaledToFit()
|
|
|
|
.frame(height: 24)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Spacer();
|
|
|
|
HStack {
|
|
|
|
if(showTitleAndDesc) {
|
|
|
|
VStack(alignment: .leading){
|
|
|
|
Text(title)
|
|
|
|
.font(.system(size: 22))
|
|
|
|
.foregroundColor(.white);
|
|
|
|
Text(subTitle)
|
|
|
|
.font(.system(size: 15))
|
2023-10-23 21:40:55 -06:00
|
|
|
.foregroundColor(.mediumGrey);
|
2023-10-23 17:43:16 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Spacer();
|
|
|
|
ZStack{
|
|
|
|
ProgressView(value: progress)
|
|
|
|
.progressViewStyle(GaugeProgressStyle())
|
|
|
|
.frame(width: 48, height: 48)
|
|
|
|
Text("\(Int(progress * 100))%").font(.system(size: 13)).foregroundColor(.white)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-23 21:40:55 -06:00
|
|
|
return ZStack{
|
|
|
|
BgImage(entry: entry).opacity(0.8)
|
2023-10-23 17:43:16 -06:00
|
|
|
LinearGradient(
|
|
|
|
gradient: Gradient(colors: [.black.opacity(0), .black]),
|
|
|
|
startPoint: .center,
|
|
|
|
endPoint: .bottom)
|
|
|
|
content.padding(16)
|
2023-11-07 11:12:05 -07:00
|
|
|
}
|
|
|
|
.widgetBackground(Color.darkGrey)
|
2023-11-07 17:38:09 -07:00
|
|
|
.widgetURL(URL(string: "wonderous:///home/collection"))
|
2023-10-23 17:43:16 -06:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2023-10-23 18:06:39 -06:00
|
|
|
|
|
|
|
// Todo: Refactor to getFlutterAsset(String path), include /assets, or maybe just getFlutterImage(String path), include assets/images
|
|
|
|
// Returns a file path to the location of the flutter assetBundle
|
|
|
|
var flutterAssetBundle: URL {
|
|
|
|
let bundle = Bundle.main
|
|
|
|
if bundle.bundleURL.pathExtension == "appex" {
|
|
|
|
// Peel off two directory levels - MY_APP.app/PlugIns/MY_APP_EXTENSION.appex
|
|
|
|
var url = bundle.bundleURL.deletingLastPathComponent().deletingLastPathComponent()
|
|
|
|
url.append(component: "Frameworks/App.framework/flutter_assets")
|
|
|
|
return url
|
|
|
|
}
|
|
|
|
return bundle.bundleURL
|
|
|
|
}
|