2024-11-12 01:16:33 +05:30
|
|
|
//
|
|
|
|
|
// View+AltWidget.swift
|
|
|
|
|
// AltStore
|
|
|
|
|
//
|
|
|
|
|
// Created by Riley Testut on 8/18/23.
|
|
|
|
|
// Copyright © 2023 Riley Testut. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import SwiftUI
|
2026-05-09 23:45:42 +04:00
|
|
|
import WidgetKit
|
2024-11-12 01:16:33 +05:30
|
|
|
|
|
|
|
|
extension View
|
|
|
|
|
{
|
|
|
|
|
@ViewBuilder
|
|
|
|
|
func widgetBackground(_ backgroundView: some View) -> some View
|
|
|
|
|
{
|
|
|
|
|
if #available(iOSApplicationExtension 17, *)
|
|
|
|
|
{
|
|
|
|
|
containerBackground(for: .widget) {
|
|
|
|
|
backgroundView
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
background(backgroundView)
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-08-18 19:24:31 -05:00
|
|
|
|
|
|
|
|
@ViewBuilder
|
|
|
|
|
func invalidatableContentIfAvailable() -> some View
|
|
|
|
|
{
|
|
|
|
|
if #available(iOSApplicationExtension 17, *)
|
|
|
|
|
{
|
|
|
|
|
self.invalidatableContent()
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ViewBuilder
|
|
|
|
|
func activatesRefreshAllAppsIntent() -> some View
|
|
|
|
|
{
|
|
|
|
|
if #available(iOSApplicationExtension 17, *)
|
|
|
|
|
{
|
|
|
|
|
Button(intent: RefreshAllAppsWidgetIntent()) {
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
.buttonStyle(.plain)
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-01-09 05:07:13 +05:30
|
|
|
|
|
|
|
|
@ViewBuilder
|
2025-01-11 04:10:02 +05:30
|
|
|
func pageUpButton(_ widgetID: Int?, _ widgetKind: String) -> some View {
|
2025-01-09 05:07:13 +05:30
|
|
|
if #available(iOSApplicationExtension 17, *) {
|
2025-01-11 04:10:02 +05:30
|
|
|
Button(intent: PaginationIntent(widgetID, .up, widgetKind)){
|
2025-01-09 05:07:13 +05:30
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
.buttonStyle(.plain)
|
|
|
|
|
} else {
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ViewBuilder
|
2025-01-11 04:10:02 +05:30
|
|
|
func pageDownButton(_ widgetID: Int?, _ widgetKind: String) -> some View {
|
2025-01-09 05:07:13 +05:30
|
|
|
if #available(iOSApplicationExtension 17, *) {
|
2025-01-11 04:10:02 +05:30
|
|
|
Button(intent: PaginationIntent(widgetID, .down, widgetKind)){
|
2025-01-09 05:07:13 +05:30
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
.buttonStyle(.plain)
|
|
|
|
|
} else {
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-09 23:45:42 +04:00
|
|
|
/// Opts this view into the widget accent group on iOS 16+, which lets the
|
|
|
|
|
/// system tint it with the user's chosen colour in tinted (accented) mode.
|
|
|
|
|
/// No-op on older OS versions where the API does not exist.
|
|
|
|
|
@ViewBuilder
|
|
|
|
|
func widgetAccentableIfAvailable() -> some View
|
|
|
|
|
{
|
|
|
|
|
if #available(iOSApplicationExtension 16, *)
|
|
|
|
|
{
|
|
|
|
|
self.widgetAccentable()
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Applies `luminanceToAlpha()` only when the widget is rendering in
|
|
|
|
|
/// accented (tinted) mode on iOS 16+. This converts the view's pixel
|
|
|
|
|
/// brightness into opacity so the system can overlay the user's chosen
|
|
|
|
|
/// tint colour correctly — without it, images appear as white rectangles
|
|
|
|
|
/// in tinted mode. No-op in fullColor/dark/light mode and on older OS.
|
|
|
|
|
@ViewBuilder
|
|
|
|
|
func luminanceToAlphaInAccentedMode() -> some View
|
|
|
|
|
{
|
|
|
|
|
if #available(iOSApplicationExtension 16, *)
|
|
|
|
|
{
|
|
|
|
|
LuminanceToAlphaWrapper(content: self)
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Helper view that reads widgetRenderingMode (iOS 16+) and conditionally
|
|
|
|
|
/// applies luminanceToAlpha(). Kept separate so the environment read is
|
|
|
|
|
/// cleanly scoped behind the @available gate.
|
|
|
|
|
@available(iOSApplicationExtension 16, *)
|
|
|
|
|
private struct LuminanceToAlphaWrapper<Content: View>: View
|
|
|
|
|
{
|
|
|
|
|
let content: Content
|
|
|
|
|
@Environment(\.widgetRenderingMode) private var renderingMode
|
|
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
|
if renderingMode == .accented
|
|
|
|
|
{
|
|
|
|
|
content.luminanceToAlpha()
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
content
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-12 01:16:33 +05:30
|
|
|
}
|