Skip to content

Commit

Permalink
Merge pull request #63 from zxbmmmmmmmmm/startmenu-companions
Browse files Browse the repository at this point in the history
Startmenu companions
  • Loading branch information
zxbmmmmmmmmm authored Aug 4, 2024
2 parents 7948fc9 + adfec95 commit c69da11
Show file tree
Hide file tree
Showing 17 changed files with 612 additions and 60 deletions.
45 changes: 39 additions & 6 deletions FluentWeather.Tasks/NotifyTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public sealed class NotifyTask :IBackgroundTask
{
private IWeatherWarningProvider _warningProvider;
private IDailyForecastProvider _dailyForecastProvider;
private ICurrentWeatherProvider _currentWeatherProvider;
private IAirConditionProvider _airConditionProvider;

public async void Run(IBackgroundTaskInstance taskInstance)
{
Expand All @@ -31,12 +33,16 @@ public async void Run(IBackgroundTaskInstance taskInstance)
{
var provider = new QWeatherProvider(Settings.QWeatherToken, Settings.QWeatherDomain, null, Settings.QWeatherPublicId);
_warningProvider = provider;
_currentWeatherProvider = provider;
_dailyForecastProvider = provider;
_airConditionProvider = provider;
}
else
{
var provider = new OpenMeteoProvider.OpenMeteoProvider();
_dailyForecastProvider = provider;
_currentWeatherProvider = provider;
_airConditionProvider = provider;
}
var lat = Settings.Latitude;
var lon = Settings.Longitude;
Expand Down Expand Up @@ -99,25 +105,51 @@ private async Task PushDaily(double lon, double lat)
}


var data = await _dailyForecastProvider.GetDailyForecasts(lon, lat);
var daily = await _dailyForecastProvider.GetDailyForecasts(lon, lat);

if (isTileAvailable)
{
TileHelper.UpdateForecastTile(data);
TileHelper.UpdateForecastTile(daily);
LogManager.GetLogger(nameof(NotifyTask)).Info("Tile Updated");
}
if (DateTime.Now.Hour < 18)
{
if (!isPushTodayAvailable) return;
PushToday(data);
Settings.LastPushedTime = DateTime.Now.Date.DayOfYear;
PushToday(daily);
try
{
await PushCard(lon, lat, daily);
}
finally
{
Settings.LastPushedTime = DateTime.Now.Date.DayOfYear;

}
}
else
{
if (!isPushTomorrowAvailable) return;
PushTomorrow(data);
Settings.LastPushedTimeTomorrow = DateTime.Now.Date.DayOfYear;
PushTomorrow(daily);

try
{
await PushCard(lon, lat, daily);
}
finally
{
Settings.LastPushedTimeTomorrow = DateTime.Now.Date.DayOfYear;
}
}
}

private async Task PushCard(double lon,double lat,List<WeatherDailyBase> daily)
{
var air = await _airConditionProvider.GetAirCondition(lon, lat);
var info = new WeatherCardData { Daily = daily, Location = Settings.DefaultGeolocation, AirQuality = air };
var card = await StartMenuCompanionHelper.CreateCompanionCard(info);
await card.UpdateStartMenuCompanionAsync();
}

private void PushToday(List<WeatherDailyBase> data)
{
var trimmed = (data.Count >= 7) ? data.GetRange(0, 7) : data;
Expand All @@ -133,6 +165,7 @@ private void PushToday(List<WeatherDailyBase> data)
.AddAttributionText(ResourceLoader.GetForViewIndependentUse().GetString("ToadyWeather"))
.AddText($"{trimmed[0].Description} {ResourceLoader.GetForViewIndependentUse().GetString("HighestTemperature")}{(trimmed[0]).MaxTemperature}°,{ResourceLoader.GetForViewIndependentUse().GetString("LowestTemperature")}{(trimmed[0]).MinTemperature}°")
.AddVisualChild(largeGroup);

builder.Show(toast =>
{
toast.ExpirationTime = DateTime.Now.AddHours(12);
Expand Down
34 changes: 17 additions & 17 deletions FluentWeather.Uwp.QWeatherProvider/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -59,46 +59,46 @@
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace"/>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0"/>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string"/>
<xsd:attribute name="type" type="xsd:string"/>
<xsd:attribute name="mimetype" type="xsd:string"/>
<xsd:attribute ref="xml:space"/>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string"/>
<xsd:attribute name="name" type="xsd:string"/>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1"/>
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2"/>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1"/>
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3"/>
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4"/>
<xsd:attribute ref="xml:space"/>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1"/>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required"/>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
Expand Down
Loading

0 comments on commit c69da11

Please sign in to comment.