Skip to content

Commit

Permalink
Update location at launch and on refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
t1m0thyj committed Apr 27, 2024
1 parent 6a50bef commit 58ec388
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/AppContext.cs
Expand Up @@ -31,7 +31,7 @@ public AppContext(string[] args) : base(new HiddenForm())
ThemeManager.Initialize();
ScriptManager.Initialize();

scheduler.Run();
scheduler.RunAndUpdateLocation();
LaunchSequence.NextStep();
UpdateChecker.Initialize();
}
Expand Down
24 changes: 19 additions & 5 deletions src/EventScheduler.cs
Expand Up @@ -51,11 +51,11 @@ public EventScheduler()
SystemEvents.TimeChanged += OnTimeChanged;
}

public void Run(bool forceImageUpdate = false, DisplayEvent overrideEvent = null)
public bool Run(bool forceImageUpdate = false, DisplayEvent overrideEvent = null)
{
if (!LaunchSequence.IsLocationReady() || !LaunchSequence.IsThemeReady())
{
return;
return false;
}
else if (displayEvents == null || forceImageUpdate)
{
Expand Down Expand Up @@ -129,6 +129,17 @@ public void Run(bool forceImageUpdate = false, DisplayEvent overrideEvent = null
}

StartTimer(nextUpdateTime.Value);
return true;
}

public async void RunAndUpdateLocation(bool forceImageUpdate = false)
{
bool result = Run(forceImageUpdate);

if (result && JsonConfig.settings.locationMode == 1 && await UwpLocation.UpdateGeoposition())
{
Run(); // Update wallpaper again if location has changed
}
}

private bool UpdateDisplayList()
Expand Down Expand Up @@ -217,12 +228,15 @@ private void HandleTimerEvent(bool updateLocation)
return;
}

if (updateLocation && JsonConfig.settings.locationMode == 1)
if (updateLocation)
{
RunAndUpdateLocation();
}
else
{
Task.Run(UwpLocation.UpdateGeoposition);
Run();
}

Run();
UpdateChecker.TryCheckAuto();
}

Expand Down
2 changes: 1 addition & 1 deletion src/TrayMenu.cs
Expand Up @@ -137,7 +137,7 @@ private void OnLanguageItemClick(object sender, EventArgs e)

private void OnRefreshItemClick(object sender, EventArgs e)
{
AppContext.scheduler.Run(true);
AppContext.scheduler.RunAndUpdateLocation(true);
}

private void OnFullScreenItemClick(object sender, EventArgs e)
Expand Down

0 comments on commit 58ec388

Please sign in to comment.