[AltWidget] Supports refreshing apps directly from home screen

This commit is contained in:
Riley Testut
2023-08-18 19:24:31 -05:00
committed by Magesh K
parent 693969dc28
commit 641c716d57
5 changed files with 90 additions and 3 deletions

View File

@@ -69,12 +69,21 @@ struct RefreshAllAppsIntent: AppIntent, CustomIntentMigratedAppIntent, Predictab
}
}
let presentsNotifications: Bool
private let operationActor = OperationActor()
init(presentsNotifications: Bool)
{
self.presentsNotifications = presentsNotifications
self.progress.completedUnitCount = 0
self.progress.totalUnitCount = 1
}
init()
{
self.progress.completedUnitCount = 0
self.progress.totalUnitCount = 1
self.init(presentsNotifications: false)
}
func perform() async throws -> some IntentResult & ProvidesDialog
@@ -99,6 +108,7 @@ struct RefreshAllAppsIntent: AppIntent, CustomIntentMigratedAppIntent, Predictab
for try await _ in taskGroup.prefix(1)
{
// We only care about the first child task to complete.
taskGroup.cancelAll()
break
}
}
@@ -148,7 +158,7 @@ private extension RefreshAllAppsIntent
let installedApps = await context.perform { InstalledApp.fetchAppsForRefreshingAll(in: context) }
try await withCheckedThrowingContinuation { continuation in
let operation = AppManager.shared.backgroundRefresh(installedApps, presentsNotifications: false) { (result) in
let operation = AppManager.shared.backgroundRefresh(installedApps, presentsNotifications: self.presentsNotifications) { (result) in
do
{
let results = try result.get()

View File

@@ -0,0 +1,38 @@
//
// RefreshAllAppsWidgetIntent.swift
// AltStore
//
// Created by Riley Testut on 8/18/23.
// Copyright © 2023 Riley Testut. All rights reserved.
//
import AppIntents
@available(iOS 17, *)
struct RefreshAllAppsWidgetIntent: AppIntent, ProgressReportingIntent
{
static var title: LocalizedStringResource { "Refresh Apps via Widget" }
static var isDiscoverable: Bool { false } // Don't show in Shortcuts or Spotlight.
#if !WIDGET_EXTENSION
private let intent = RefreshAllAppsIntent(presentsNotifications: true)
#endif
func perform() async throws -> some IntentResult & ProvidesDialog
{
#if WIDGET_EXTENSION
return .result(dialog: "")
#else
return try await self.intent.perform()
#endif
}
}
// To ensure this intent is handled by the app itself (and not widget extension)
// we need to conform to either `ForegroundContinuableIntent` or `AudioPlaybackIntent`.
// https://mastodon.social/@mgorbach/110812347476671807
//
// Unfortunately `ForegroundContinuableIntent` is marked as unavailable in app extensions,
// so we conform to AudioPlaybackIntent instead despite not playing audio ¯\_()_/¯
@available(iOS 17, *)
extension RefreshAllAppsWidgetIntent: AudioPlaybackIntent {}