Skip to content
This repository has been archived by the owner on Jan 14, 2024. It is now read-only.

Commit

Permalink
Merge pull request #36 from conath/dev-fix-widgets
Browse files Browse the repository at this point in the history
Update Widget extension to improve reliability
  • Loading branch information
conath authored Nov 28, 2020
2 parents 1222852 + 5e6420f commit b46c514
Show file tree
Hide file tree
Showing 8 changed files with 216 additions and 35 deletions.
16 changes: 12 additions & 4 deletions TheatricalMovieTrailers.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@
8334EF7A252E697300A1EB87 /* ExternalMovieMetaView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExternalMovieMetaView.swift; sourceTree = "<group>"; };
833CB264253A147500E1D15C /* UIApplication+version+build.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIApplication+version+build.swift"; sourceTree = "<group>"; };
834ADB3C25398496002D9F1E /* CoverFlowRotatingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoverFlowRotatingView.swift; sourceTree = "<group>"; };
834FF5BB2572A42500A4AF39 /* TheatricalMovieTrailers.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = TheatricalMovieTrailers.entitlements; sourceTree = "<group>"; };
834FF5BC2572A43F00A4AF39 /* TrailersWidgetExtension.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = TrailersWidgetExtension.entitlements; sourceTree = "<group>"; };
834FFDC3254085ED007E63C2 /* AVPlayerViewController+enterFullScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AVPlayerViewController+enterFullScreen.swift"; sourceTree = "<group>"; };
837DB13F2548CE200071CB2E /* ShareSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareSheet.swift; sourceTree = "<group>"; };
837DB1422548D5E30071CB2E /* AppStoreReviewsManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppStoreReviewsManager.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -167,6 +169,7 @@
8316E0D724A64AD300467F14 = {
isa = PBXGroup;
children = (
834FF5BC2572A43F00A4AF39 /* TrailersWidgetExtension.entitlements */,
8316E0E224A64AD300467F14 /* TheatricalMovieTrailers */,
831F1B6B25499412008D24D4 /* TrailersWidget */,
831F1B6625499412008D24D4 /* Frameworks */,
Expand All @@ -186,6 +189,7 @@
8316E0E224A64AD300467F14 /* TheatricalMovieTrailers */ = {
isa = PBXGroup;
children = (
834FF5BB2572A42500A4AF39 /* TheatricalMovieTrailers.entitlements */,
8316E0F124A64AD400467F14 /* Info.plist */,
8316E0E324A64AD300467F14 /* AppDelegate.swift */,
8316E0E524A64AD300467F14 /* SceneDelegate.swift */,
Expand Down Expand Up @@ -598,9 +602,10 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = TheatricalMovieTrailers/TheatricalMovieTrailers.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 31;
CURRENT_PROJECT_VERSION = 32;
DEVELOPMENT_ASSET_PATHS = "\"TheatricalMovieTrailers/Preview Content\"";
DEVELOPMENT_TEAM = U96PJYMZWW;
ENABLE_PREVIEWS = YES;
Expand All @@ -624,9 +629,10 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = TheatricalMovieTrailers/TheatricalMovieTrailers.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 31;
CURRENT_PROJECT_VERSION = 32;
DEVELOPMENT_ASSET_PATHS = "\"TheatricalMovieTrailers/Preview Content\"";
DEVELOPMENT_TEAM = U96PJYMZWW;
ENABLE_PREVIEWS = YES;
Expand All @@ -649,9 +655,10 @@
buildSettings = {
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground;
CODE_SIGN_ENTITLEMENTS = TrailersWidgetExtension.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 31;
CURRENT_PROJECT_VERSION = 32;
DEVELOPMENT_TEAM = U96PJYMZWW;
INFOPLIST_FILE = TrailersWidget/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 14.1;
Expand All @@ -673,9 +680,10 @@
buildSettings = {
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground;
CODE_SIGN_ENTITLEMENTS = TrailersWidgetExtension.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 31;
CURRENT_PROJECT_VERSION = 32;
DEVELOPMENT_TEAM = U96PJYMZWW;
INFOPLIST_FILE = TrailersWidget/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 14.1;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1220"
wasCreatedForAppExtension = "YES"
version = "2.0">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "831F1B6425499412008D24D4"
BuildableName = "TrailersWidgetExtension.appex"
BlueprintName = "TrailersWidgetExtension"
ReferencedContainer = "container:TheatricalMovieTrailers.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "8316E0DF24A64AD300467F14"
BuildableName = "TheatricalMovieTrailers.app"
BlueprintName = "TheatricalMovieTrailers"
ReferencedContainer = "container:TheatricalMovieTrailers.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</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">
<RemoteRunnable
runnableDebuggingMode = "2"
BundleIdentifier = "com.apple.springboard">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "831F1B6425499412008D24D4"
BuildableName = "TrailersWidgetExtension.appex"
BlueprintName = "TrailersWidgetExtension"
ReferencedContainer = "container:TheatricalMovieTrailers.xcodeproj">
</BuildableReference>
</RemoteRunnable>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "8316E0DF24A64AD300467F14"
BuildableName = "TheatricalMovieTrailers.app"
BlueprintName = "TheatricalMovieTrailers"
ReferencedContainer = "container:TheatricalMovieTrailers.xcodeproj">
</BuildableReference>
</MacroExpansion>
<EnvironmentVariables>
<EnvironmentVariable
key = "_XCWidgetKind"
value = "DetailedTrailersWidget"
isEnabled = "YES">
</EnvironmentVariable>
<EnvironmentVariable
key = "_XCWidgetDefaultView"
value = "timeline"
isEnabled = "YES">
</EnvironmentVariable>
<EnvironmentVariable
key = "_XCWidgetFamily"
value = "large"
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES"
launchAutomaticallySubstyle = "2">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "8316E0DF24A64AD300467F14"
BuildableName = "TheatricalMovieTrailers.app"
BlueprintName = "TheatricalMovieTrailers"
ReferencedContainer = "container:TheatricalMovieTrailers.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
7 changes: 4 additions & 3 deletions TheatricalMovieTrailers/Model/MovieInfoDataStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ class MovieInfoDataStore: ObservableObject {
// MARK: File URLs
private var localStorageDirectory: URL {
let fileManager = FileManager.default
guard let url = fileManager.urls(for: .cachesDirectory, in: .userDomainMask).first else {
fatalError("Couldn't get local storage directory (.cachesDirectory)")
guard let sharedContainerURL = fileManager.containerURL(
forSecurityApplicationGroupIdentifier: "group.cafe.chrisp.tmt") else {
fatalError("Couldn't get App Group shared container.")
}
return url
return sharedContainerURL
}
private var localCurrentTrailersURL: URL {
return localStorageDirectory.appendingPathComponent("currentTrailers.xml")
Expand Down
74 changes: 50 additions & 24 deletions TheatricalMovieTrailers/Model/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,60 +22,86 @@ class Settings: ObservableObject {

static let instance = Settings()

static var userDefaults: UserDefaults {
return UserDefaults(suiteName: "cafe.chrisp.tmt.settings")!
}

// Present since the beginning
@Published var prefersDarkAppearance = true {
didSet {
let newValue = prefersDarkAppearance ? ValueAlwaysDark : ValueAutomaticDark
let defaults = UserDefaults()
let defaults = Self.userDefaults
defaults.setValue(newValue, forKey: .autoDark)
defaults.synchronize()
}
}
// Added in Build 27
@Published var loadHighDefinition = true {
didSet {
let defaults = UserDefaults()
let defaults = Self.userDefaults
defaults.setValue(loadHighDefinition, forKey: .loadHighDefinition)
defaults.synchronize()
}
}
/// Added in Build 30
/// App Store Reviews Manager metadata
let firstLaunchedDate: Date
private(set) var firstLaunchedDate: Date
var lastReviewRequestAppVersion: String? = nil {
didSet {
let defaults = UserDefaults()
let defaults = Self.userDefaults
defaults.setValue(lastReviewRequestAppVersion, forKey: .lastReviewRequestAppVersion)
defaults.synchronize()
}
}

private init() {
let defaults = UserDefaults()
// check for version upgrade
let defaults = Self.userDefaults
/// Check for version upgrade
let lastBuild = defaults.string(forKey: .lastBuildNumber)
if lastBuild == nil {
defaults.setValue(UIApplication.build, forKey: .lastBuildNumber)
// set default values
prefersDarkAppearance = true
firstLaunchedDate = Date()
defaults.setValue(Date(), forKey: .firstLaunchedDate)
} else if let prevBuild = lastBuild, prevBuild != UIApplication.build {
if Int(prevBuild)! < 30 {
firstLaunchedDate = Date()
let oldDefaults = UserDefaults()
/// If last build is 31, that used non-specific UserDefaults suite. Must migrate!
let oldBuild = oldDefaults.string(forKey: .lastBuildNumber)
if let old = oldBuild, let oldNumber = Int(old) {
if oldNumber < 30 {
firstLaunchedDate = Date()
defaults.setValue(firstLaunchedDate, forKey: .firstLaunchedDate)
} else {
firstLaunchedDate = oldDefaults.value(forKey: .firstLaunchedDate) as! Date
}
}
if oldDefaults.string(forKey: .lastBuildNumber) == "31" {
/// Migrate settings to new defaults suite
let isAutoDark = oldDefaults.integer(forKey: .autoDark) == ValueAutomaticDark
if isAutoDark {
prefersDarkAppearance = false
}
firstLaunchedDate = oldDefaults.value(forKey: .firstLaunchedDate) as! Date
lastReviewRequestAppVersion = oldDefaults.string(forKey: .lastReviewRequestAppVersion)
defaults.setValue(firstLaunchedDate, forKey: .firstLaunchedDate)
defaults.setValue(isAutoDark, forKey: .autoDark)
defaults.setValue(lastReviewRequestAppVersion, forKey: .lastReviewRequestAppVersion)
defaults.setValue(UIApplication.build, forKey: .lastBuildNumber)
} else {
firstLaunchedDate = defaults.value(forKey: .firstLaunchedDate) as! Date
}
} else {
// load settings
let isAutoDark = defaults.integer(forKey: .autoDark) == ValueAutomaticDark
if isAutoDark {
prefersDarkAppearance = false
/// New install
defaults.setValue(UIApplication.build, forKey: .lastBuildNumber)
/// Set default values
prefersDarkAppearance = true
firstLaunchedDate = Date()
defaults.setValue(Date(), forKey: .firstLaunchedDate)
}
/// App Store Reviews Manager metadata
firstLaunchedDate = defaults.value(forKey: .firstLaunchedDate) as! Date
lastReviewRequestAppVersion = defaults.string(forKey: .lastReviewRequestAppVersion)
} else if let prevBuild = lastBuild, prevBuild != UIApplication.build {
/// Version upgrade happened
/// There are no changes yet in the new settings.
defaults.setValue(UIApplication.build, forKey: .lastBuildNumber)
}
/// Load settings
let isAutoDark = defaults.integer(forKey: .autoDark) == ValueAutomaticDark
if isAutoDark {
prefersDarkAppearance = false
}
/// App Store Reviews Manager metadata
firstLaunchedDate = defaults.value(forKey: .firstLaunchedDate) as! Date
lastReviewRequestAppVersion = defaults.string(forKey: .lastReviewRequestAppVersion)
}
}
5 changes: 4 additions & 1 deletion TheatricalMovieTrailers/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
assertionFailure("Malformed id URL parameter: expected integer")
return
}
viewParameters.showTrailerID = id
/// App needs a bit to catch up
DispatchQueue.main.async { [self] in
viewParameters.showTrailerID = id
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions TheatricalMovieTrailers/TheatricalMovieTrailers.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.application-groups</key>
<array>
<string>group.cafe.chrisp.tmt</string>
</array>
</dict>
</plist>
6 changes: 3 additions & 3 deletions TrailersWidget/TrailersWidget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ class Provider: IntentTimelineProvider {
images[info.id] = dataStore.idsAndImages[info.id]
}

var entries: [TrailerEntry] = []
// Generate a timeline consisting of three entries a day apart, starting from the current date.
let currentDate = Date()
var entries: [TrailerEntry] = []
let morning = Calendar.current.date(bySettingHour: 8, minute: 0, second: 0, of: Date())!
for offset in 0 ..< 3 {
let entryDate = Calendar.current.date(byAdding: .day, value: offset, to: currentDate)!
let entryDate = Calendar.current.date(byAdding: .day, value: offset, to: morning)!
let entry = TrailerEntry(date: entryDate, configuration: configuration, info: info[offset], image: images[info[offset].id, default: nil], dataStore: dataStore)
entries.append(entry)
}
Expand Down
10 changes: 10 additions & 0 deletions TrailersWidgetExtension.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.application-groups</key>
<array>
<string>group.cafe.chrisp.tmt</string>
</array>
</dict>
</plist>

0 comments on commit b46c514

Please sign in to comment.