Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a shuffle feature #1853

Open
wants to merge 4 commits into
base: core-separation
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 src/Lively/Lively.Grpc.Client/IDesktopCoreClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public interface IDesktopCoreClient : IDisposable
void SendMessageWallpaper(IDisplayMonitor display, ILibraryModel obj, IpcMessage msg);
Task PreviewWallpaper(string livelyInfoPath);
Task TakeScreenshot(string monitorId, string savePath);
Task SetWallpaperLoop(bool state, int intervall);

event EventHandler WallpaperChanged;
event EventHandler<Exception> WallpaperError;
Expand Down
4 changes: 4 additions & 0 deletions src/Lively/Lively.Grpc.Client/UserSettingsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ private SettingsDataModel CreateGrpcSettings(ISettingsModel settings)
ApplicationThemeBackground = (Common.Proto.Settings.AppThemeBackground)settings.ApplicationThemeBackground,
ApplicationThemeBackgroundPath = settings.ApplicationThemeBackgroundPath,
ThemeBundleVersion = settings.ThemeBundleVersion,
DoRandomWallpaper = settings.DoRandomWallpaper,
TimeToChangeWallpaper = settings.TimeToChangeWallpaper,
};
}

Expand Down Expand Up @@ -330,6 +332,8 @@ private ISettingsModel CreateSettingsFromGrpc(SettingsDataModel settings)
ApplicationThemeBackground = (Lively.Common.AppThemeBackground)settings.ApplicationThemeBackground,
ApplicationThemeBackgroundPath = settings.ApplicationThemeBackgroundPath,
ThemeBundleVersion = settings.ThemeBundleVersion,
DoRandomWallpaper = settings.DoRandomWallpaper,
TimeToChangeWallpaper = settings.TimeToChangeWallpaper,
};
}

Expand Down
10 changes: 10 additions & 0 deletions src/Lively/Lively.Grpc.Client/WinDesktopCoreClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,16 @@ private async Task SubscribeWallpaperUpdatedStream(CancellationToken token)
}
}

public async Task SetWallpaperLoop(bool state, int intervall)
{
var request = new SetWallpaperLoopRequest
{
State = state,
Intervall = intervall,
};
_ = await client.SetWallpaperLoopAsync(request);
}

#region dispose

protected virtual void Dispose(bool disposing)
Expand Down
2 changes: 2 additions & 0 deletions src/Lively/Lively.Grpc.Common/Proto/settings.proto
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ message SettingsDataModel {
AppThemeBackground application_theme_background = 60;
string application_theme_background_path = 61;
int32 theme_bundle_version = 62;
bool do_random_wallpaper = 63;
int32 time_to_change_wallpaper = 64;
}

message AppRulesSettings {
Expand Down
6 changes: 6 additions & 0 deletions src/Lively/Lively.Grpc.Common/Proto/wallpaper.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ service DesktopService {
rpc SendMessageWallpaper(WallpaperMessageRequest) returns (google.protobuf.Empty);
rpc GetCoreStats (google.protobuf.Empty) returns (GetCoreStatsResponse);
rpc TakeScreenshot(WallpaperScreenshotRequest) returns (google.protobuf.Empty);
rpc SetWallpaperLoop (SetWallpaperLoopRequest) returns (google.protobuf.Empty);
}

message SetWallpaperRequest {
Expand Down Expand Up @@ -111,6 +112,11 @@ message WallpaperErrorResponse {
string error_msg = 2;
}

message SetWallpaperLoopRequest {
bool state = 1;
int32 intervall = 2;
}

enum ErrorCategory {
workerw = 0;
wallpaper_not_found = 1;
Expand Down
2 changes: 2 additions & 0 deletions src/Lively/Lively.Models/ISettingsModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,7 @@ public interface ISettingsModel
string ApplicationThemeBackgroundPath { get; set; }
AppThemeBackground ApplicationThemeBackground { get; set; }
int ThemeBundleVersion { get; set; }
bool DoRandomWallpaper { get; set; }
int TimeToChangeWallpaper { get; set; }
}
}
4 changes: 4 additions & 0 deletions src/Lively/Lively.Models/SettingsModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ public class SettingsModel : ISettingsModel
public string ApplicationThemeBackgroundPath { get; set; }
public AppThemeBackground ApplicationThemeBackground { get; set; }
public int ThemeBundleVersion { get; set; }
public bool DoRandomWallpaper { get; set; }
public int TimeToChangeWallpaper { get; set; }

public SettingsModel()
{
Expand Down Expand Up @@ -191,6 +193,8 @@ public SettingsModel()
IsUpdated = false;
ApplicationThemeBackgroundPath = null;
ApplicationThemeBackground = AppThemeBackground.default_mica;
DoRandomWallpaper = false;
TimeToChangeWallpaper = 20;

try
{
Expand Down
1 change: 1 addition & 0 deletions src/Lively/Lively.UI.WinUI/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ private IServiceProvider ConfigureServices()
.AddTransient<IApplicationsRulesFactory, ApplicationsRulesFactory>()
.AddTransient<IThemeFactory, ThemeFactory>()
.AddTransient<IDownloadHelper, SimpleDownloadHelper>()
.AddTransient<ShuffleViewModel>()
//https://docs.microsoft.com/en-us/dotnet/architecture/microservices/implement-resilient-applications/use-httpclientfactory-to-implement-resilient-http-requests
.AddHttpClient()
.BuildServiceProvider();
Expand Down
4 changes: 4 additions & 0 deletions src/Lively/Lively.UI.WinUI/Lively.UI.WinUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
<None Remove="Views\Pages\Gallery\RestoreWallpaperView.xaml" />
<None Remove="Views\Pages\Gallery\ShareWallpaperView.xaml" />
<None Remove="Views\Pages\HelpView.xaml" />
<None Remove="Views\Pages\ShuffleView.xaml" />
<None Remove="Views\Pages\LibraryAboutView.xaml" />
<None Remove="Views\Pages\LoginView.xaml" />
<None Remove="Views\Pages\ScreensaverLayoutView.xaml" />
Expand Down Expand Up @@ -145,6 +146,9 @@
<Page Update="Views\Pages\ControlPanel\ControlPanelView.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Update="Views\Pages\ShuffleView.xaml">
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
</Page>
</ItemGroup>
<ItemGroup>
<Page Update="Views\Pages\LibraryView.xaml">
Expand Down
9 changes: 9 additions & 0 deletions src/Lively/Lively.UI.WinUI/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -1220,4 +1220,13 @@ If still not working, close &amp; start Lively again/restart windows.
<data name="TitleDownload.Content" xml:space="preserve">
<value>Download</value>
</data>
<data name="EnableShuffle.Content" xml:space="preserve">
<value>Enable automatic wallpaper change</value>
</data>
<data name="Shuffle.Label" xml:space="preserve">
<value>Shuffle settings</value>
</data>
<data name="TimeShuffle.Header" xml:space="preserve">
<value>Time Intervall (in minutes)</value>
</data>
</root>
100 changes: 100 additions & 0 deletions src/Lively/Lively.UI.WinUI/ViewModels/ShuffleViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using Lively.Common.Helpers.MVVM;
using Lively.Grpc.Client;
using Lively.Models;
using Lively.UI.WinUI.Views.Pages;
using Microsoft.UI.Dispatching;
using NLog;
using Windows.Devices.Printers;
using Windows.System.Profile;

namespace Lively.UI.WinUI.ViewModels
{
public class ShuffleViewModel : ObservableObject
{

public event EventHandler OnRequestClose;
private readonly DispatcherQueue dispatcherQueue;

private readonly IDisplayManagerClient displayManager;
private readonly IDesktopCoreClient desktopCore;
private readonly IUserSettingsClient userSettings;

public ShuffleViewModel(IDesktopCoreClient desktopCore, IDisplayManagerClient displayManager, IUserSettingsClient userSettings)
{
this.userSettings = userSettings;
this.desktopCore = desktopCore;
EnableShuffle = userSettings.Settings.DoRandomWallpaper;
TimeToChangeWallpaper = userSettings.Settings.TimeToChangeWallpaper.ToString();
dispatcherQueue = DispatcherQueue.GetForCurrentThread() ?? DispatcherQueueController.CreateOnCurrentThread().DispatcherQueue;
}

private bool _enableShuffle;
public bool EnableShuffle
{
get { return _enableShuffle; }
set
{
_enableShuffle = value;
if (userSettings.Settings.DoRandomWallpaper != _enableShuffle)
{
userSettings.Settings.DoRandomWallpaper = _enableShuffle;
UpdateSettingsConfigFile();
}
OnPropertyChanged();
}
}

private string _timeToChangeWallpaper;
public string TimeToChangeWallpaper
{
get { return _timeToChangeWallpaper; }
set
{
_timeToChangeWallpaper = value;
if (userSettings.Settings.TimeToChangeWallpaper.ToString() != _timeToChangeWallpaper)
{
try
{
userSettings.Settings.TimeToChangeWallpaper = Int32.Parse(_timeToChangeWallpaper);
UpdateSettingsConfigFile();
}
catch { }
}
OnPropertyChanged();
}
}

private string _debugBoxText;
public string DebugBoxText
{
get { return _debugBoxText; }
set
{
_debugBoxText = value;
OnPropertyChanged();
}
}

public void UpdateSettingsConfigFile()
{
_ = dispatcherQueue.TryEnqueue(() =>
{
userSettings.Save<ISettingsModel>();
});
}

public void PageUnloaded()
{
desktopCore.SetWallpaperLoop(userSettings.Settings.DoRandomWallpaper, userSettings.Settings.TimeToChangeWallpaper);
}

}
}
11 changes: 11 additions & 0 deletions src/Lively/Lively.UI.WinUI/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,17 @@
</AppBarButton>
<AppBarSeparator />

<AppBarButton
Name="shuffleBtn"
MaxWidth="50"
LabelPosition="Collapsed"
Click="ToogleShuffleButton_Click">
<AppBarButton.Icon>
<FontIcon Glyph="&#xE8B1;" />
</AppBarButton.Icon>
</AppBarButton>
<AppBarSeparator />

<AppBarButton
Name="authorizedBtn"
MaxWidth="50"
Expand Down
14 changes: 14 additions & 0 deletions src/Lively/Lively.UI.WinUI/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,20 @@ private void ShowControlPanelDialog()
private void AppBarCoffeeBtn_Click(object sender, RoutedEventArgs e) =>
LinkHandler.OpenBrowser("https://rocksdanister.github.io/lively/coffee/");

private void ToogleShuffleButton_Click(object sender, RoutedEventArgs e)
{

_ = new ContentDialog()
{
Title = i18n.GetString("Shuffle/Label"),
Content = new ShuffleView(),
PrimaryButtonText = i18n.GetString("TextOK"),
DefaultButton = ContentDialogButton.Primary,
XamlRoot = this.Content.XamlRoot,
}.ShowAsyncQueue();

}

private void AppBarThemeButton_Click(object sender, RoutedEventArgs e) => dialogService.ShowThemeDialog();

private void AppBarHelpButton_Click(object sender, RoutedEventArgs e)
Expand Down
29 changes: 29 additions & 0 deletions src/Lively/Lively.UI.WinUI/Views/Pages/ShuffleView.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Page
x:Class="Lively.UI.WinUI.Views.Pages.ShuffleView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:WinUICommunity"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:Lively.UI.WinUI.Views.Pages"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
MinWidth="450"
mc:Ignorable="d">

<Grid>
<StackPanel Orientation="Vertical">
<CheckBox
x:Uid="EnableShuffle"
IsChecked="{Binding EnableShuffle, Mode=TwoWay}"
/>

<controls:SettingsCard x:Uid="TimeShuffle">
<controls:SettingsCard.HeaderIcon>
<FontIcon Glyph="&#xE916;" />
</controls:SettingsCard.HeaderIcon>

<NumberBox
Value="{Binding TimeToChangeWallpaper, Mode=TwoWay}" />
</controls:SettingsCard>
</StackPanel>
</Grid>
</Page>
29 changes: 29 additions & 0 deletions src/Lively/Lively.UI.WinUI/Views/Pages/ShuffleView.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Lively.Common;
using Lively.UI.WinUI.ViewModels;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Navigation;
using NLog;
using System;

namespace Lively.UI.WinUI.Views.Pages
{
public sealed partial class ShuffleView : Page
{
private ShuffleViewModel _viewModel;
public ShuffleView()
{
this.InitializeComponent();
this.Unloaded += ShuffleView_Unloaded;

_viewModel = App.Services.GetRequiredService<ShuffleViewModel>();
this.DataContext = _viewModel;
}

private void ShuffleView_Unloaded(object sender, RoutedEventArgs e)
{
_viewModel?.PageUnloaded();
}
}
}
1 change: 1 addition & 0 deletions src/Lively/Lively/Core/IDesktopCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public interface IDesktopCore : IDisposable
void SendMessageWallpaper(string info_path, IpcMessage msg);
void SendMessageWallpaper(IDisplayMonitor display, string info_path, IpcMessage msg);
void SetWallpaper(ILibraryModel wallpaper, IDisplayMonitor display);
void SetRandomWallpaper();

/// <summary>
/// Wallpaper set/removed.
Expand Down
Loading