Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions ImmichFrame.Core/Interfaces/IServerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public interface IGeneralSettings
public string Style { get; }
public string? BaseFontSize { get; }
public bool ShowWeatherDescription { get; }
public int TemperatureDecimalDigits { get; }
Comment thread
nopoz marked this conversation as resolved.
public string? WeatherIconUrl { get; }
public bool ImageZoom { get; }
public bool ImagePan { get; }
Expand Down
12 changes: 10 additions & 2 deletions ImmichFrame.WebApi.Tests/Helpers/Config/ConfigLoaderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@

private void VerifyConfig(IServerSettings serverSettings, bool usePrefix, bool expectNullApiKeyFile)
{
VerifyProperties(serverSettings.GeneralSettings);
VerifyProperties(serverSettings.GeneralSettings, "", expectNullApiKeyFile);
VerifyAccounts(serverSettings.Accounts, usePrefix, expectNullApiKeyFile);
}

Expand All @@ -95,7 +95,7 @@
if (type.IsGenericType && typeof(IEnumerable).IsAssignableFrom(type))
{
type = type.GetGenericArguments()[0];
value = (value as IEnumerable).Cast<object>().FirstOrDefault();

Check warning on line 98 in ImmichFrame.WebApi.Tests/Helpers/Config/ConfigLoaderTest.cs

View workflow job for this annotation

GitHub Actions / test

Possible null reference argument for parameter 'source' in 'IEnumerable<object> Enumerable.Cast<object>(IEnumerable source)'.
}

//if it's nullable, unwrap
Expand All @@ -120,7 +120,15 @@
Assert.That(value, Is.EqualTo(true), prop.Name);
break;
case var t when t == typeof(int):
Assert.That(value, Is.EqualTo(7), prop.Name);
// V1 config doesn't support TemperatureDecimalDigits, so it defaults to 1
if (prop.Name.Equals("TemperatureDecimalDigits") && expectNullApiKeyFile)
{
Assert.That(value, Is.EqualTo(1), prop.Name);
}
else
{
Assert.That(value, Is.EqualTo(7), prop.Name);
}
break;
case var t when t == typeof(double):
Assert.That(value, Is.EqualTo(7.7d), prop.Name);
Expand Down Expand Up @@ -155,7 +163,7 @@
// Ensure the property has a public getter
if (prop.CanRead && prop.GetMethod?.IsPublic == true)
{
object value = prop.GetValue(obj);

Check warning on line 166 in ImmichFrame.WebApi.Tests/Helpers/Config/ConfigLoaderTest.cs

View workflow job for this annotation

GitHub Actions / test

Converting null literal or possible null value to non-nullable type.

if (ignoreNullValues && value == null)
{
Expand All @@ -164,14 +172,14 @@

if (!(value is string) && value is IEnumerable)
{
value = string.Join(",", (value as IEnumerable).Cast<object>().Select(x => x.ToString()));

Check warning on line 175 in ImmichFrame.WebApi.Tests/Helpers/Config/ConfigLoaderTest.cs

View workflow job for this annotation

GitHub Actions / test

Possible null reference argument for parameter 'source' in 'IEnumerable<object> Enumerable.Cast<object>(IEnumerable source)'.
}
else
{
value = value.ToString();

Check warning on line 179 in ImmichFrame.WebApi.Tests/Helpers/Config/ConfigLoaderTest.cs

View workflow job for this annotation

GitHub Actions / test

Converting null literal or possible null value to non-nullable type.

Check warning on line 179 in ImmichFrame.WebApi.Tests/Helpers/Config/ConfigLoaderTest.cs

View workflow job for this annotation

GitHub Actions / test

Dereference of a possibly null reference.
}

dictionary.Add(prop.Name, value);

Check warning on line 182 in ImmichFrame.WebApi.Tests/Helpers/Config/ConfigLoaderTest.cs

View workflow job for this annotation

GitHub Actions / test

Possible null reference argument for parameter 'value' in 'void Dictionary<string, object>.Add(string key, object value)'.
}
}

Expand Down
1 change: 1 addition & 0 deletions ImmichFrame.WebApi.Tests/Resources/TestV2.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"Style": "Style_TEST",
"BaseFontSize": "BaseFontSize_TEST",
"ShowWeatherDescription": true,
"TemperatureDecimalDigits": 7,
"WeatherIconUrl": "WeatherIconUrl_TEST",
"ImageZoom": true,
"ImagePan": true,
Expand Down
1 change: 1 addition & 0 deletions ImmichFrame.WebApi.Tests/Resources/TestV2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ General:
Style: Style_TEST
BaseFontSize: BaseFontSize_TEST
ShowWeatherDescription: true
TemperatureDecimalDigits: 7
WeatherIconUrl: WeatherIconUrl_TEST
ImageZoom: true
ImagePan: true
Expand Down
11 changes: 10 additions & 1 deletion ImmichFrame.WebApi/Helpers/Config/ServerSettingsV1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,22 @@ class GeneralSettingsV1Adapter(ServerSettingsV1 _delegate) : IGeneralSettings
public string Style => _delegate.Style;
public string? BaseFontSize => _delegate.BaseFontSize;
public bool ShowWeatherDescription => _delegate.ShowWeatherDescription;
public int TemperatureDecimalDigits => 1;
public string? WeatherIconUrl => _delegate.WeatherIconUrl;
public bool ImageZoom => _delegate.ImageZoom;
public bool ImagePan => _delegate.ImagePan;
public bool ImageFill => _delegate.ImageFill;
public string Layout => _delegate.Layout;
public string Language => _delegate.Language;

public void Validate() { }
public void Validate()
{
if (TemperatureDecimalDigits < 0 || TemperatureDecimalDigits > 2)
{
throw new ArgumentOutOfRangeException(nameof(TemperatureDecimalDigits),
TemperatureDecimalDigits,
"TemperatureDecimalDigits must be between 0 and 2.");
}
}
}
}
2 changes: 2 additions & 0 deletions ImmichFrame.WebApi/Models/ClientSettingsDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@
public string? ImageLocationFormat { get; set; }
public string? PrimaryColor { get; set; }
public string? SecondaryColor { get; set; }
public string Style { get; set; }

Check warning on line 24 in ImmichFrame.WebApi/Models/ClientSettingsDto.cs

View workflow job for this annotation

GitHub Actions / test

Non-nullable property 'Style' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public string? BaseFontSize { get; set; }
public bool ShowWeatherDescription { get; set; }
public int TemperatureDecimalDigits { get; set; }
public string? WeatherIconUrl { get; set; }
public bool ImageZoom { get; set; }
public bool ImagePan { get; set; }
public bool ImageFill { get; set; }
public string Layout { get; set; }

Check warning on line 32 in ImmichFrame.WebApi/Models/ClientSettingsDto.cs

View workflow job for this annotation

GitHub Actions / test

Non-nullable property 'Layout' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public string Language { get; set; }

Check warning on line 33 in ImmichFrame.WebApi/Models/ClientSettingsDto.cs

View workflow job for this annotation

GitHub Actions / test

Non-nullable property 'Language' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

public static ClientSettingsDto FromGeneralSettings(IGeneralSettings generalSettings)
{
Expand All @@ -54,6 +55,7 @@
dto.Style = generalSettings.Style;
dto.BaseFontSize = generalSettings.BaseFontSize;
dto.ShowWeatherDescription = generalSettings.ShowWeatherDescription;
dto.TemperatureDecimalDigits = generalSettings.TemperatureDecimalDigits;
dto.WeatherIconUrl = generalSettings.WeatherIconUrl;
dto.ImageZoom = generalSettings.ImageZoom;
dto.ImagePan = generalSettings.ImagePan;
Expand Down
11 changes: 10 additions & 1 deletion ImmichFrame.WebApi/Models/ServerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

[YamlMember(Alias = "Accounts")]
[JsonPropertyName("Accounts")]
public IEnumerable<ServerAccountSettings> AccountsImpl { get; set; }

Check warning on line 16 in ImmichFrame.WebApi/Models/ServerSettings.cs

View workflow job for this annotation

GitHub Actions / test

Non-nullable property 'AccountsImpl' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

//Covariance not allowed on interface impls
[JsonIgnore]
Expand Down Expand Up @@ -57,6 +57,7 @@
public string Style { get; set; } = "none";
public string? BaseFontSize { get; set; }
public bool ShowWeatherDescription { get; set; } = true;
public int TemperatureDecimalDigits { get; set; } = 1;
public string? WeatherIconUrl { get; set; } = "https://openweathermap.org/img/wn/{IconId}.png";
public bool ImageZoom { get; set; } = true;
public bool ImagePan { get; set; } = false;
Expand All @@ -71,7 +72,15 @@
public string? Webhook { get; set; }
public string? AuthenticationSecret { get; set; }

public void Validate() { }
public void Validate()
{
if (TemperatureDecimalDigits < 0 || TemperatureDecimalDigits > 2)
{
throw new ArgumentOutOfRangeException(nameof(TemperatureDecimalDigits),
TemperatureDecimalDigits,
"TemperatureDecimalDigits must be between 0 and 2.");
}
}
}

public class ServerAccountSettings : IAccountSettings, IConfigSettable
Expand Down
2 changes: 1 addition & 1 deletion immichFrame.Web/src/lib/components/elements/clock.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
<img src="{ $configStore.weatherIconUrl.replace('{IconId}', encodeURIComponent(weather.iconId)) }" class="icon-weather" alt="{weather.description}">
{/if}
<div class="weather-location">{weather.location},</div>
<div class="weather-temperature">{weather.temperature?.toFixed(1)}</div>
<div class="weather-temperature">{(weather.temperature ?? 0).toFixed($configStore.temperatureDecimalDigits ?? 1)}</div>
<div class="weather-unit">{weather.unit}</div>
</div>
{#if $configStore.showWeatherDescription}
Expand Down
1 change: 1 addition & 0 deletions immichFrame.Web/src/lib/immichFrameApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ export type ClientSettingsDto = {
style?: string | null;
baseFontSize?: string | null;
showWeatherDescription?: boolean;
temperatureDecimalDigits?: number;
weatherIconUrl?: string | null;
imageZoom?: boolean;
imagePan?: boolean;
Expand Down
Loading