Skip to content

Commit

Permalink
#1247 (Mac Catalyst edition)
Browse files Browse the repository at this point in the history
- Added widget on Mac.
- Updated to support latest layout APIs.
  • Loading branch information
Dejal committed Nov 14, 2023
1 parent 4838b66 commit 69b36e6
Show file tree
Hide file tree
Showing 6 changed files with 343 additions and 25 deletions.
2 changes: 1 addition & 1 deletion clients/ios/Classes/StoryPagesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ class StoryPagesViewController: StoryPagesObjCViewController {

/// Reload the widget timeline.
@objc func reloadWidget() {
WidgetCenter.shared.reloadTimelines(ofKind: "Latest")
WidgetCenter.shared.reloadAllTimelines()
}
}
239 changes: 219 additions & 20 deletions clients/ios/NewsBlur.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
version = "2.0">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "17654E312B02C08700F61B2B"
BuildableName = "NewsBlur Alpha Widget.appex"
BlueprintName = "NewsBlur Alpha Widget"
ReferencedContainer = "container:NewsBlur.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "175790592930605500490924"
BuildableName = "NB Alpha.app"
BlueprintName = "NewsBlur Alpha"
ReferencedContainer = "container:NewsBlur.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">
<EnvironmentVariables>
<EnvironmentVariable
key = "_XCWidgetKind"
value = ""
isEnabled = "YES">
</EnvironmentVariable>
<EnvironmentVariable
key = "_XCWidgetDefaultView"
value = "timeline"
isEnabled = "YES">
</EnvironmentVariable>
<EnvironmentVariable
key = "_XCWidgetFamily"
value = "systemMedium"
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES"
askForAppToLaunch = "Yes"
launchAutomaticallySubstyle = "2">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "17654E312B02C08700F61B2B"
BuildableName = "NewsBlur Alpha Widget.appex"
BlueprintName = "NewsBlur Alpha Widget"
ReferencedContainer = "container:NewsBlur.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
File renamed without changes.
File renamed without changes.
26 changes: 22 additions & 4 deletions clients/ios/Widget Extension/WidgetExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ struct SimpleEntry: TimelineEntry {
struct WidgetEntryView : View {
var entry: Provider.Entry

@Environment(\.widgetRenderingMode) var renderingMode
@Environment(\.widgetContentMargins) var margins
@Environment(\.colorScheme) var colorScheme
@Environment(\.widgetFamily) private var family

Expand All @@ -94,14 +96,19 @@ struct WidgetEntryView : View {

var body: some View {
ZStack {
Color("WidgetBackground")
.ignoresSafeArea()
// switch renderingMode {
// case .accented:
// case .fullColor:
// case .vibrant:
// break
// }

if let error = entry.cache.error {
Link(destination: URL(string: "newsblurwidget://?error=\(error)")!) {
Text(message(for: error))
.font(.headline)
.foregroundColor(.secondary)
.foregroundStyle(.secondary)
.containerBackground(.fill, for: .widget)
}
} else {
VStack(alignment: .leading, spacing: 0, content: {
Expand All @@ -112,9 +119,19 @@ struct WidgetEntryView : View {
Divider()
}
})
.widgetURL(URL(string: "newsblurwidget://open"))
.padding(.top, 5)
.padding(.bottom, 5)
.containerBackground(for: .widget) {
Color("WidgetBackground")
}
.widgetURL(URL(string: "newsblurwidget://open"))
}
}
// .environment(\.colorScheme, colorScheme)
.containerBackground(for: .widget) {
Color("WidgetBackground")
// .ignoresSafeArea()
}
}

func message(for error: WidgetCacheError) -> String {
Expand Down Expand Up @@ -142,6 +159,7 @@ struct WidgetExtension: Widget {
.configurationDisplayName("NewsBlur")
.description("The latest stories from NewsBlur.")
.supportedFamilies([.systemMedium, .systemLarge])
.contentMarginsDisabled()
}
}

Expand Down

0 comments on commit 69b36e6

Please sign in to comment.