Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: introduces some iOS widgets! #515

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions BeeKit/Managers/CurrentUserManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import KeychainSwift
import OSLog
import SwiftyJSON

import WidgetKit

@NSModelActor(disableGenerateInit: true)
public actor CurrentUserManager {
let logger = Logger(subsystem: "com.beeminder.beeminder", category: "CurrentUserManager")
Expand Down Expand Up @@ -168,12 +170,14 @@ public actor CurrentUserManager {

await Task { @MainActor in
NotificationCenter.default.post(name: CurrentUserManager.NotificationName.signedIn, object: self)
WidgetCenter.shared.reloadAllTimelines()
}.value
}

func handleFailedSignin(_ responseError: Error, errorMessage : String?) async throws {
await Task { @MainActor in
NotificationCenter.default.post(name: CurrentUserManager.NotificationName.failedSignIn, object: self, userInfo: ["error" : responseError])
WidgetCenter.shared.reloadAllTimelines()
}.value
try await self.signOut()
}
Expand All @@ -190,6 +194,8 @@ public actor CurrentUserManager {

await Task { @MainActor in
NotificationCenter.default.post(name: CurrentUserManager.NotificationName.signedOut, object: self)

WidgetCenter.shared.reloadAllTimelines()
}.value
}
}
9 changes: 7 additions & 2 deletions BeeKit/Managers/GoalManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import CoreDataEvolution
import SwiftyJSON
import OSLog
import OrderedCollections

import WidgetKit

@NSModelActor(disableGenerateInit: true)
public actor GoalManager {
Expand All @@ -26,7 +26,11 @@ public actor GoalManager {
private let requestManager: RequestManager
private nonisolated let currentUserManager: CurrentUserManager

public var goalsFetchedAt : Date? = nil
public var goalsFetchedAt : Date? = nil {
didSet {
WidgetCenter.shared.reloadAllTimelines()
}
}

private var queuedGoalsBackgroundTaskRunning : Bool = false

Expand Down Expand Up @@ -135,6 +139,7 @@ public actor GoalManager {
await Task { @MainActor in
modelContainer.viewContext.refreshAllObjects()
NotificationCenter.default.post(name: GoalManager.NotificationName.goalsUpdated, object: self)
WidgetCenter.shared.reloadAllTimelines()
}.value
}

Expand Down
270 changes: 268 additions & 2 deletions BeeSwift.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1610"
version = "2.0">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9B5860FC2CE4963E00079A1C"
BuildableName = "BeeminderWidgetExtension.appex"
BlueprintName = "BeeminderWidgetExtension"
ReferencedContainer = "container:BeeSwift.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = ""
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
launchStyle = "0"
askForAppToLaunch = "Yes"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES"
launchAutomaticallySubstyle = "2">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES"
askForAppToLaunch = "Yes"
launchAutomaticallySubstyle = "2">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9B5860FC2CE4963E00079A1C"
BuildableName = "BeeminderWidgetExtension.appex"
BlueprintName = "BeeminderWidgetExtension"
ReferencedContainer = "container:BeeSwift.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
8 changes: 8 additions & 0 deletions BeeSwift/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import UIKit
import IQKeyboardManagerSwift
import AlamofireNetworkActivityIndicator

import WidgetKit

import BeeKit

@UIApplicationMain
Expand Down Expand Up @@ -65,12 +67,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
logger.notice("applicationDidEnterBackground")
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

WidgetCenter.shared.reloadAllTimelines()
}

func applicationWillEnterForeground(_ application: UIApplication) {
logger.notice("applicationWillEnterForeground")
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
NotificationCenter.default.post(name: UIApplication.willEnterForegroundNotification, object: nil)

WidgetCenter.shared.reloadAllTimelines()
}

func applicationDidBecomeActive(_ application: UIApplication) {
Expand Down Expand Up @@ -155,6 +161,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
}
do {
try await ServiceLocator.goalManager.refreshGoals()

WidgetCenter.shared.reloadAllTimelines()
} catch {
logger.error("Error refreshing goals: \(error)")
}
Expand Down
Empty file modified BeeSwift/BackgroundUpdates.swift
100644 → 100755
Empty file.
6 changes: 3 additions & 3 deletions BeeSwift/Gallery/GalleryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import HealthKit
import SafariServices
import OSLog
import CoreData
import WidgetKit

import BeeKit

Expand Down Expand Up @@ -444,15 +445,14 @@ class GalleryViewController: UIViewController, UICollectionViewDelegateFlowLayou
}

@objc func openGoalFromNotification(_ notification: Notification) {
guard let notif = notification as NSNotification? else { return }
var matchingGoal: Goal?

if let identifier = notif.userInfo?["identifier"] as? String {
if let identifier = notification.userInfo?["identifier"] as? String {
if let url = URL(string: identifier), let objectID = viewContext.persistentStoreCoordinator?.managedObjectID(forURIRepresentation: url) {
matchingGoal = viewContext.object(with: objectID) as? Goal
}
}
else if let slug = notif.userInfo?["slug"] as? String {
else if let slug = notification.userInfo?["slug"] as? String {
matchingGoal = self.filteredGoals.filter({ (goal) -> Bool in
return goal.slug == slug
}).last
Expand Down
7 changes: 0 additions & 7 deletions BeeSwift/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,6 @@
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>apb.local</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
<key>imac.local</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "tinted"
}
],
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions BeeminderWidget/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Loading