Skip to content

Commit 23f61d4

Browse files
committedOct 15, 2023
1 parent db7155b commit 23f61d4

File tree

10 files changed

+88
-135
lines changed

10 files changed

+88
-135
lines changed
 

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ ModelManifest.xml
248248
.DS_Store
249249
*.xcuserstate
250250
/Maui/SimpleWeather.Maui.AppWidget/DerivedData
251+
/Maui/WidgetCenterProxy
251252

252253
# SimpleWeather
253254
API_KEY.txt
@@ -275,4 +276,5 @@ API_KEY.txt
275276
/*.bat.old
276277
/*.bat.old.*
277278
/*.sh
279+
!/maui-preparebuild.sh
278280
listingData-*.csv

‎.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"cmake.configureOnOpen": false
3+
}

‎.vscode/tasks.json

+18-90
Original file line numberDiff line numberDiff line change
@@ -5,122 +5,40 @@
55
"label": "MauiBuildDebug",
66
"dependsOrder": "sequence",
77
"dependsOn": [
8-
"keyCheckShared",
9-
"keyCheckWApi",
10-
"editManifestInfoiOSDebug",
11-
"editManifestEntitlementsiOSDebug",
12-
"editManifestInfoMacDebug",
13-
"editManifestEntitlementsMacDebug",
14-
"dotnet: restore",
15-
"cleanDebug",
8+
"prepareMauiDebug",
9+
"restore",
1610
"maui: Build"
1711
]
1812
},
1913
{
2014
"label": "MauiBuildRelease",
2115
"dependsOrder": "sequence",
2216
"dependsOn": [
23-
"keyCheckShared",
24-
"keyCheckWApi",
25-
"editManifestInfoiOSRelease",
26-
"editManifestEntitlementsiOSRelease",
27-
"editManifestInfoMacRelease",
28-
"editManifestEntitlementsMacRelease",
17+
"cleanMauiAppWidgets",
18+
"prepareMauiRelease",
2919
"restore",
3020
"cleanRelease",
3121
"maui: Build"
3222
]
3323
},
3424
{
35-
"label": "keyCheckShared",
25+
"label": "prepareMauiDebug",
3626
"type": "shell",
37-
"command": "KeyCheck/bin/Release/net7.0/publish/KeyCheck SimpleWeather.Shared/Keys",
27+
"command": "bash maui-preparebuild.sh \"Debug\"",
3828
"group": "build",
3929
"options": {
4030
"cwd": "${workspaceFolder}"
4131
}
4232
},
4333
{
44-
"label": "keyCheckWApi",
34+
"label": "prepareMauiRelease",
4535
"type": "shell",
46-
"command": "KeyCheck/bin/Release/net7.0/publish/KeyCheck SimpleWeather.Weather-API/Keys",
36+
"command": "bash maui-preparebuild.sh \"Release\"",
4737
"group": "build",
4838
"options": {
4939
"cwd": "${workspaceFolder}"
5040
}
5141
},
52-
{
53-
"label": "editManifestInfoiOSDebug",
54-
"type": "shell",
55-
"command": "../../EditManifest/bin/Release/net7.0/publish/EditManifest Platforms/iOS/Info.plist \"Debug\"",
56-
"group": "build",
57-
"options": {
58-
"cwd": "${workspaceFolder}/Maui/SimpleWeather.Maui/"
59-
}
60-
},
61-
{
62-
"label": "editManifestInfoMacDebug",
63-
"type": "shell",
64-
"command": "../../EditManifest/bin/Release/net7.0/publish/EditManifest Platforms/MacCatalyst/Info.plist \"Debug\"",
65-
"group": "build",
66-
"options": {
67-
"cwd": "${workspaceFolder}/Maui/SimpleWeather.Maui/"
68-
}
69-
},
70-
{
71-
"label": "editManifestEntitlementsiOSDebug",
72-
"type": "shell",
73-
"command": "../../EditManifest/bin/Release/net7.0/publish/EditManifest Platforms/iOS/Entitlements.plist \"Debug\"",
74-
"group": "build",
75-
"options": {
76-
"cwd": "${workspaceFolder}/Maui/SimpleWeather.Maui/"
77-
}
78-
},
79-
{
80-
"label": "editManifestEntitlementsMacDebug",
81-
"type": "shell",
82-
"command": "../../EditManifest/bin/Release/net7.0/publish/EditManifest Platforms/MacCatalyst/Entitlements.plist \"Debug\"",
83-
"group": "build",
84-
"options": {
85-
"cwd": "${workspaceFolder}/Maui/SimpleWeather.Maui/"
86-
}
87-
},
88-
{
89-
"label": "editManifestInfoiOSRelease",
90-
"type": "shell",
91-
"command": "../../EditManifest/bin/Release/net7.0/publish/EditManifest Platforms/iOS/Info.plist \"Release\"",
92-
"group": "build",
93-
"options": {
94-
"cwd": "${workspaceFolder}/Maui/SimpleWeather.Maui/"
95-
}
96-
},
97-
{
98-
"label": "editManifestInfoMacRelease",
99-
"type": "shell",
100-
"command": "../../EditManifest/bin/Release/net7.0/publish/EditManifest Platforms/MacCatalyst/Info.plist \"Release\"",
101-
"group": "build",
102-
"options": {
103-
"cwd": "${workspaceFolder}/Maui/SimpleWeather.Maui/"
104-
}
105-
},
106-
{
107-
"label": "editManifestEntitlementsiOSRelease",
108-
"type": "shell",
109-
"command": "../../EditManifest/bin/Release/net7.0/publish/EditManifest Platforms/iOS/Entitlements.plist \"Release\"",
110-
"group": "build",
111-
"options": {
112-
"cwd": "${workspaceFolder}/Maui/SimpleWeather.Maui/"
113-
}
114-
},
115-
{
116-
"label": "editManifestEntitlementsMacRelease",
117-
"type": "shell",
118-
"command": "../../EditManifest/bin/Release/net7.0/publish/EditManifest Platforms/MacCatalyst/Entitlements.plist \"Release\"",
119-
"group": "build",
120-
"options": {
121-
"cwd": "${workspaceFolder}/Maui/SimpleWeather.Maui/"
122-
}
123-
},
12442
{
12543
"label": "cleanDebug",
12644
"type": "shell",
@@ -150,6 +68,16 @@
15068
"options": {
15169
"cwd": "${workspaceFolder}/Maui/SimpleWeather.Maui/"
15270
}
71+
},
72+
{
73+
"label": "cleanMauiAppWidgets",
74+
"type": "shell",
75+
"command": "xcodebuild clean; rm -rf DerivedData",
76+
"problemMatcher": [ "$msCompile" ],
77+
"group": "build",
78+
"options": {
79+
"cwd": "${workspaceFolder}/Maui/SimpleWeather.Maui.AppWidget/"
80+
}
15381
}
15482
]
15583
}

‎Maui/SimpleWeather.Maui.AppWidget/SimpleWeather.xcodeproj/xcuserdata/dave.b.antoine.xcuserdatad/xcschemes/xcschememanagement.plist

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
<key>widgetExtension.xcscheme_^#shared#^_</key>
1313
<dict>
1414
<key>orderHint</key>
15-
<integer>1</integer>
15+
<integer>0</integer>
1616
</dict>
1717
<key>widgetintentExt.xcscheme_^#shared#^_</key>
1818
<dict>
1919
<key>orderHint</key>
20-
<integer>2</integer>
20+
<integer>1</integer>
2121
</dict>
2222
</dict>
2323
<key>SuppressBuildableAutocreation</key>

‎Maui/SimpleWeather.Maui/BackgroundTasks/UpdaterTaskUtils.cs

+20-14
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,36 @@ public static void StartTasks()
1212
{
1313
var settingsMgr = Ioc.Default.GetService<SettingsManager>();
1414
// Queue tasks if dependent features are enabled
15-
if (IsTaskFeaturesEnabled())
15+
Task.Run(async () =>
1616
{
17+
if (await IsTaskFeaturesEnabled())
18+
{
1719
#if __IOS__
18-
WidgetUpdaterTask.ScheduleTask();
19-
WeatherUpdaterTask.ScheduleTask();
20+
WidgetUpdaterTask.ScheduleTask();
21+
WeatherUpdaterTask.ScheduleTask();
2022

21-
if (settingsMgr.DailyNotificationEnabled)
22-
{
23-
DailyNotificationTask.ScheduleTask();
24-
}
23+
if (settingsMgr.DailyNotificationEnabled)
24+
{
25+
DailyNotificationTask.ScheduleTask();
26+
}
2527
#endif
26-
}
28+
}
29+
});
2730
}
2831

2932
public static void CancelTasks()
3033
{
3134
// Cancel tasks if dependent features are disabled
32-
if (!IsTaskFeaturesEnabled())
35+
Task.Run(async () =>
3336
{
37+
if (!await IsTaskFeaturesEnabled())
38+
{
3439
#if __IOS__
35-
WidgetUpdaterTask.CancelPendingTasks();
36-
WeatherUpdaterTask.CancelPendingTasks();
40+
WidgetUpdaterTask.CancelPendingTasks();
41+
WeatherUpdaterTask.CancelPendingTasks();
3742
#endif
38-
}
43+
}
44+
});
3945
}
4046

4147
public static void UpdateTasks()
@@ -72,12 +78,12 @@ public static void RescheduleDailyNotificationTask()
7278
#endif
7379
}
7480

75-
private static bool IsTaskFeaturesEnabled()
81+
private static async Task<bool> IsTaskFeaturesEnabled()
7682
{
7783
var settingsMgr = Ioc.Default.GetService<SettingsManager>();
7884
return
7985
#if __IOS__
80-
WeatherWidgetUpdater.WidgetsExist() ||
86+
await WeatherWidgetUpdater.WidgetsExist() ||
8187
#endif
8288
settingsMgr.ShowAlerts ||
8389
settingsMgr.DailyNotificationEnabled ||

‎Maui/SimpleWeather.Maui/BackgroundTasks/WeatherUpdaterTask.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public async Task Run()
9696

9797
// Update widgets
9898
await WeatherWidgetUpdater.UpdateWidgetData();
99+
WeatherWidgetUpdater.ReloadWidgets();
99100

100101
if (SettingsManager.PoPChanceNotificationEnabled)
101102
{
@@ -178,7 +179,7 @@ private async Task PreloadWeather()
178179

179180
foreach (var location in locations)
180181
{
181-
if (WeatherWidgetUpdater.WidgetsExist())
182+
if (await WeatherWidgetUpdater.WidgetsExist())
182183
{
183184
try
184185
{

‎Maui/SimpleWeather.Maui/BackgroundTasks/WidgetUpdaterTask.cs

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public async Task Run()
5555

5656
// Update widgets
5757
await WeatherWidgetUpdater.UpdateWidgetData();
58+
WeatherWidgetUpdater.ReloadWidgets();
5859

5960
if (SettingsManager.PoPChanceNotificationEnabled)
6061
{

‎Maui/SimpleWeather.Maui/MaciOS/Widget/WeatherWidgetUpdater.cs

+16-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using SimpleWeather.Common.WeatherData;
44
using SimpleWeather.Utils;
55
using System.Text;
6+
using WidgetKitProxy;
67

78
namespace SimpleWeather.Maui.Widget
89
{
@@ -14,6 +15,12 @@ public static class WeatherWidgetUpdater
1415
private const string GROUP_IDENTIFIER = "group.com.thewizrd.simpleweather";
1516
#endif
1617

18+
private static Lazy<WidgetCenterProxy> widgetCenterProxyLazy = new(() => {
19+
return new WidgetCenterProxy();
20+
});
21+
22+
private static WidgetCenterProxy WidgetCenter => widgetCenterProxyLazy.Value;
23+
1724
public static async Task UpdateWidgetData()
1825
{
1926
var settingsMgr = DI.Utils.SettingsManager;
@@ -88,15 +95,20 @@ public static Task<Dictionary<string, WeatherData>> GetWidgetData()
8895
});
8996
}
9097

91-
public static bool WidgetsExist()
98+
public static Task<bool> WidgetsExist()
9299
{
93-
// TODO: Implement
94-
return false;
100+
var tcs = new TaskCompletionSource<bool>();
101+
102+
WidgetCenter.GetCurrentConfigurationsWithCompletion((widgets) => {
103+
tcs.SetResult(widgets.Count > 0);
104+
});
105+
106+
return tcs.Task;
95107
}
96108

97109
public static void ReloadWidgets()
98110
{
99-
// TODO: implement
111+
WidgetCenter.ReloadAllTimeLines();
100112
}
101113
}
102114
}

‎Maui/SimpleWeather.Maui/SimpleWeather.Maui.csproj

+5-24
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
44
<TargetFrameworks>net7.0-ios;net7.0-maccatalyst</TargetFrameworks>
@@ -110,10 +110,12 @@
110110
<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">
111111
<PackageReference Include="Maui.RevenueCat.iOS" Version="4.9.0.2" />
112112
<PackageReference Include="Maui.RevenueCat.iOS.Extensions" Version="4.9.0.4" />
113+
<PackageReference Include="com.hcsaba.WidgetCenterBinder.Maui" Version="1.0.1-alpha" />
113114
</ItemGroup>
114115
<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">
115116
<PackageReference Include="Maui.RevenueCat.MacCatalyst" Version="4.9.0.2" />
116117
<PackageReference Include="Maui.RevenueCat.MacCatalyst.Extensions" Version="4.9.0.4" />
118+
<PackageReference Include="com.hcsaba.WidgetCenterBinder.Maui" Version="1.0.1-alpha" />
117119
</ItemGroup>
118120
<ItemGroup Condition="$(TargetFramework.Contains('windows'))">
119121
<PackageReference Include="WinUIEx" Version="2.1.0" />
@@ -281,29 +283,8 @@
281283
<CustomCommands>
282284
<Command>
283285
<type>BeforeBuild</type>
284-
<command>${SolutionDir}/KeyCheck/bin/Release/net7.0/publish/KeyCheck ${SolutionDir}/SimpleWeather.Shared/Keys</command>
285-
</Command>
286-
<Command>
287-
<type>BeforeBuild</type>
288-
<command>${SolutionDir}/KeyCheck/bin/Release/net7.0/publish/KeyCheck ${SolutionDir}/SimpleWeather.Weather-API/Keys</command>
289-
</Command>
290-
<!-- iOS -->
291-
<Command>
292-
<type>BeforeBuild</type>
293-
<command>${SolutionDir}/EditManifest/bin/Release/net7.0/publish/EditManifest ${ProjectDir}/Platforms/iOS/Info.plist "${ProjectConfig}"</command>
294-
</Command>
295-
<Command>
296-
<type>BeforeBuild</type>
297-
<command>${SolutionDir}/EditManifest/bin/Release/net7.0/publish/EditManifest ${ProjectDir}/Platforms/iOS/Entitlements.plist "${ProjectConfig}"</command>
298-
</Command>
299-
<!-- MacCatalyst -->
300-
<Command>
301-
<type>BeforeBuild</type>
302-
<command>${SolutionDir}/EditManifest/bin/Release/net7.0/publish/EditManifest ${ProjectDir}/Platforms/MacCatalyst/Info.plist "${ProjectConfig}"</command>
303-
</Command>
304-
<Command>
305-
<type>BeforeBuild</type>
306-
<command>${SolutionDir}/EditManifest/bin/Release/net7.0/publish/EditManifest ${ProjectDir}/Platforms/MacCatalyst/Entitlements.plist "${ProjectConfig}"</command>
286+
<command>bash ${SolutionDir}/maui-preparebuild.sh "${ProjectConfig}"</command>
287+
<workingdir>${SolutionDir}</workingdir>
307288
</Command>
308289
</CustomCommands>
309290
</CustomCommands>

‎maui-preparebuild.sh

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
config=$1
4+
5+
KeyCheck/bin/Release/net7.0/publish/KeyCheck SimpleWeather.Shared/Keys
6+
KeyCheck/bin/Release/net7.0/publish/KeyCheck SimpleWeather.Weather-API/Keys
7+
8+
cd Maui/SimpleWeather.Maui.AppWidget
9+
10+
xcodebuild build -configuration $config -scheme widgetExtension -sdk iphonesimulator
11+
xcodebuild build -configuration $config -scheme widgetExtension -sdk iphoneos
12+
xcodebuild build -configuration $config -scheme widgetExtension -sdk macosx -destination 'platform=macOS,variant=Mac Catalyst' SUPPORTS_MACCATALYST=YES SKIP_INSTALL=NO
13+
14+
cd ../SimpleWeather.Maui
15+
16+
../../EditManifest/bin/Release/net7.0/publish/EditManifest Platforms/iOS/Info.plist "$config"
17+
../../EditManifest/bin/Release/net7.0/publish/EditManifest Platforms/iOS/Entitlements.plist "$config"
18+
../../EditManifest/bin/Release/net7.0/publish/EditManifest Platforms/MacCatalyst/Info.plist "$config"
19+
../../EditManifest/bin/Release/net7.0/publish/EditManifest Platforms/MacCatalyst/Entitlements.plist "$config"

0 commit comments

Comments
 (0)
Please sign in to comment.