Skip to content

Commit

Permalink
Fixed LivelyProperties not saving when changed from control panel..
Browse files Browse the repository at this point in the history
- Improved LivelyProperties control visuals.
- Fixed selected screen wallpaper LivelyProperties not saving if customise menu is opened while wallpaper is not running.
- Fixed selected library item not updating when switching between SelectionMode None and Single.
  • Loading branch information
rocksdanister committed Apr 24, 2024
1 parent e476b13 commit 2f8d94b
Show file tree
Hide file tree
Showing 9 changed files with 236 additions and 178 deletions.
13 changes: 12 additions & 1 deletion src/Lively/Lively.Grpc.Client/UserSettingsClient.cs
Expand Up @@ -182,6 +182,7 @@ private SettingsDataModel CreateGrpcSettings(SettingsModel settings)
DisplayName = settings.SelectedDisplay.DisplayName,
HMonitor = settings.SelectedDisplay.HMonitor.ToInt32(),
IsPrimary = settings.SelectedDisplay.IsPrimary,
Index = settings.SelectedDisplay.Index,
WorkingArea = new Rectangle()
{
X = settings.SelectedDisplay.WorkingArea.X,
Expand Down Expand Up @@ -270,7 +271,17 @@ private SettingsModel CreateSettingsFromGrpc(SettingsDataModel settings)
DeviceName = settings.SelectedDisplay.DeviceName,
HMonitor = new IntPtr(settings.SelectedDisplay.HMonitor),
IsPrimary = settings.SelectedDisplay.IsPrimary,
Index = settings.SelectedDisplay.Index,
Index = settings.SelectedDisplay.Index,
Bounds = new System.Drawing.Rectangle(
settings.SelectedDisplay.Bounds.X,
settings.SelectedDisplay.Bounds.Y,
settings.SelectedDisplay.Bounds.Width,
settings.SelectedDisplay.Bounds.Height),
WorkingArea = new System.Drawing.Rectangle(
settings.SelectedDisplay.WorkingArea.X,
settings.SelectedDisplay.WorkingArea.Y,
settings.SelectedDisplay.WorkingArea.Width,
settings.SelectedDisplay.WorkingArea.Height),
},
WallpaperArrangement = (WallpaperArrangement)((int)settings.WallpaperArrangement),
AppVersion = settings.AppVersion,
Expand Down
@@ -0,0 +1,26 @@
using Microsoft.UI.Xaml.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lively.UI.WinUI.Helpers.Converters
{
public class StringTruncateConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value is string str && parameter is int maxLength && str.Length > maxLength)
{
return string.Concat(str.AsSpan(0, maxLength), "...");
}
return value;
}

public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
}
2 changes: 1 addition & 1 deletion src/Lively/Lively.UI.WinUI/Services/DialogService.cs
Expand Up @@ -265,7 +265,7 @@ public async Task ShowControlPanelDialogAsync()
DefaultButton = ContentDialogButton.Primary,
XamlRoot = App.Services.GetRequiredService<MainWindow>().Content.XamlRoot,
}.ShowAsyncQueue();
vm.OnWindowClosing(this, new RoutedEventArgs());
vm.OnWindowClosing(this, EventArgs.Empty);
}

public async Task ShowHelpDialogAsync()
Expand Down
235 changes: 123 additions & 112 deletions src/Lively/Lively.UI.WinUI/UserControls/FolderDropdown.xaml
Expand Up @@ -14,117 +14,128 @@
</UserControl.Resources>

<Grid>
<StackPanel Orientation="Horizontal" Spacing="5">
<!-- Using ListView, ComboBox has issue: SelectionChanged is firing when closing it if an item above the selecteditem is deleted. -->
<DropDownButton
Width="200"
Padding="5"
HorizontalContentAlignment="Left">
<DropDownButton.Content>
<Grid>
<StackPanel
Orientation="Horizontal"
Spacing="5"
Visibility="{x:Bind SelectedFile, Mode=OneWay, Converter={StaticResource NullVisibilityConverter}}">
<Border
Width="40"
Height="25"
Background="{ThemeResource SystemAltLowColor}"
BorderBrush="{ThemeResource SystemChromeHighColor}"
BorderThickness="1"
CornerRadius="5">
<Image Source="{x:Bind SelectedFile.ImagePath, Mode=OneWay}" Stretch="UniformToFill" />
</Border>
<TextBlock
VerticalAlignment="Center"
Text="{x:Bind SelectedFile.FileName, Mode=OneWay}"
TextTrimming="CharacterEllipsis"
TextWrapping="NoWrap" />
</StackPanel>
<StackPanel
Orientation="Horizontal"
Spacing="5"
Visibility="{x:Bind SelectedFile, Mode=OneWay, Converter={StaticResource NullVisibilityConverter}, ConverterParameter=Reverse}">
<FontIcon Glyph="&#xE783;" />
<TextBlock>...</TextBlock>
</StackPanel>
</Grid>
</DropDownButton.Content>
<DropDownButton.Flyout>
<Flyout Opened="Flyout_Opened" Placement="Bottom">
<Flyout.FlyoutPresenterStyle>
<Style TargetType="FlyoutPresenter">
<Setter Property="MinWidth" Value="200" />
<Setter Property="CornerRadius" Value="5" />
</Style>
</Flyout.FlyoutPresenterStyle>
<ListView
x:Name="listView"
Height="350"
Margin="-15"
x:Load="False"
ItemsSource="{x:Bind Files, Mode=OneWay}"
SelectedItem="{x:Bind SelectedFile, Mode=TwoWay}">
<ListView.ItemTemplate>
<DataTemplate>
<Grid Padding="0,10,0,10" ToolTipService.ToolTip="{Binding FileName, Mode=OneWay}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="200" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<!-- File preview -->
<Border
Grid.Column="0"
Width="75"
Height="50"
Margin="0,0,5,0"
Background="{ThemeResource SystemAltLowColor}"
BorderBrush="{ThemeResource SystemChromeHighColor}"
BorderThickness="1"
CornerRadius="5">
<Image Source="{Binding ImagePath, Mode=OneWay}" Stretch="UniformToFill" />
</Border>
<!-- File title -->
<TextBlock
Grid.Column="1"
Margin="0,0,5,0"
VerticalAlignment="Center"
Text="{Binding FileName, Mode=OneWay}"
TextTrimming="CharacterEllipsis"
TextWrapping="NoWrap" />
<!-- File delete -->
<Button
Grid.Column="2"
Margin="0,0,5,0"
VerticalAlignment="Stretch"
Background="#258B0000"
Click="Delete_Button_Click">
<Button.Resources>
<ResourceDictionary>
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Dark">
<SolidColorBrush x:Key="ButtonBackgroundPointerOver" Color="#55ff0000" />
</ResourceDictionary>
<ResourceDictionary x:Key="Light">
<SolidColorBrush x:Key="ButtonBackgroundPointerOver" Color="#55ff0000" />
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
</ResourceDictionary>
</Button.Resources>
<FontIcon FontSize="14" Glyph="&#xE74D;" />
</Button>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Flyout>
</DropDownButton.Flyout>
</DropDownButton>
<!-- Add file -->
<Button VerticalAlignment="Stretch" Command="{x:Bind OpenFileCommand}">
<FontIcon FontSize="14" Glyph="&#xE8E5;" />
</Button>
</StackPanel>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<!-- Using ListView, ComboBox has issue: SelectionChanged is firing when closing it if an item above the selecteditem is deleted. -->
<DropDownButton
Grid.Column="0"
Margin="0,0,5,0"
Padding="5"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Left">
<DropDownButton.Content>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="150" />
</Grid.ColumnDefinitions>
<Border
Grid.Column="0"
Width="40"
Height="25"
Margin="0,0,5,0"
Background="{ThemeResource SystemAltLowColor}"
BorderBrush="{ThemeResource SystemChromeHighColor}"
BorderThickness="1"
CornerRadius="5"
Visibility="{x:Bind SelectedFile, Mode=OneWay, Converter={StaticResource NullVisibilityConverter}}">
<Image Source="{x:Bind SelectedFile.ImagePath, Mode=OneWay}" Stretch="UniformToFill" />
</Border>
<TextBlock
Grid.Column="1"
VerticalAlignment="Center"
Text="{x:Bind SelectedFile.FileName, Mode=OneWay}"
TextTrimming="CharacterEllipsis"
TextWrapping="NoWrap"
ToolTipService.ToolTip="{x:Bind SelectedFile.FileName, Mode=OneWay}"
Visibility="{x:Bind SelectedFile, Mode=OneWay, Converter={StaticResource NullVisibilityConverter}}" />
<TextBlock
Grid.Column="1"
VerticalAlignment="Center"
Text="( ̄o ̄) . z Z"
Visibility="{x:Bind SelectedFile, Mode=OneWay, Converter={StaticResource NullVisibilityConverter}, ConverterParameter=Reverse}" />
</Grid>
</DropDownButton.Content>
<DropDownButton.Flyout>
<Flyout Opened="Flyout_Opened" Placement="Bottom">
<Flyout.FlyoutPresenterStyle>
<Style TargetType="FlyoutPresenter">
<Setter Property="MinWidth" Value="200" />
<Setter Property="CornerRadius" Value="5" />
</Style>
</Flyout.FlyoutPresenterStyle>
<ListView
x:Name="listView"
Height="350"
Margin="-15"
x:Load="False"
ItemsSource="{x:Bind Files, Mode=OneWay}"
SelectedItem="{x:Bind SelectedFile, Mode=TwoWay}">
<ListView.ItemTemplate>
<DataTemplate>
<Grid Padding="0,10,0,10" ToolTipService.ToolTip="{Binding FileName, Mode=OneWay}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="200" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<!-- File preview -->
<Border
Grid.Column="0"
Width="75"
Height="50"
Margin="0,0,5,0"
Background="{ThemeResource SystemAltLowColor}"
BorderBrush="{ThemeResource SystemChromeHighColor}"
BorderThickness="1"
CornerRadius="5">
<Image Source="{Binding ImagePath, Mode=OneWay}" Stretch="UniformToFill" />
</Border>
<!-- File title -->
<TextBlock
Grid.Column="1"
Margin="0,0,5,0"
VerticalAlignment="Center"
Text="{Binding FileName, Mode=OneWay}"
TextTrimming="CharacterEllipsis"
TextWrapping="NoWrap" />
<!-- File delete -->
<Button
Grid.Column="2"
Margin="0,0,5,0"
VerticalAlignment="Stretch"
Background="#258B0000"
Click="Delete_Button_Click">
<Button.Resources>
<ResourceDictionary>
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Dark">
<SolidColorBrush x:Key="ButtonBackgroundPointerOver" Color="#55ff0000" />
</ResourceDictionary>
<ResourceDictionary x:Key="Light">
<SolidColorBrush x:Key="ButtonBackgroundPointerOver" Color="#55ff0000" />
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
</ResourceDictionary>
</Button.Resources>
<FontIcon FontSize="14" Glyph="&#xE74D;" />
</Button>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Flyout>
</DropDownButton.Flyout>
</DropDownButton>
<!-- Add file -->
<Button
Grid.Column="1"
VerticalAlignment="Stretch"
Command="{x:Bind OpenFileCommand}">
<FontIcon FontSize="14" Glyph="&#xE8E5;" />
</Button>
</Grid>
</UserControl>
27 changes: 21 additions & 6 deletions src/Lively/Lively.UI.WinUI/ViewModels/ControlPanelViewModel.cs
Expand Up @@ -11,7 +11,6 @@
using Lively.Grpc.Client;
using Lively.Models;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.UI.Xaml;

namespace Lively.UI.WinUI.ViewModels
{
Expand All @@ -29,6 +28,8 @@ public class NavigatePageEventArgs : EventArgs
private readonly IDisplayManagerClient displayManager;
private readonly LibraryViewModel libraryVm;

private CustomiseWallpaperViewModel customiseWallpaperViewModel;

public ControlPanelViewModel(IUserSettingsClient userSettings,
IDesktopCoreClient desktopCore,
IDisplayManagerClient displayManager,
Expand Down Expand Up @@ -107,6 +108,7 @@ public bool IsRememberSelectedScreen
{
libraryVm.LibrarySelectionMode = "Single";
//Updating library selected item.
libraryVm.SelectedItem = null;
libraryVm.UpdateSelectedWallpaper();
}
else
Expand Down Expand Up @@ -218,9 +220,9 @@ private void CustomiseWallpaper(ScreenLayoutModel selection)

if (obj != null)
{
var viewModel = App.Services.GetRequiredService<CustomiseWallpaperViewModel>();
viewModel.Load(obj);
NavigatePage?.Invoke(this, new NavigatePageEventArgs() { Tag = "customiseWallpaper", Arg = viewModel });
customiseWallpaperViewModel = App.Services.GetRequiredService<CustomiseWallpaperViewModel>();
customiseWallpaperViewModel.Load(obj);
NavigatePage?.Invoke(this, new NavigatePageEventArgs() { Tag = "customiseWallpaper", Arg = customiseWallpaperViewModel });
}
}
}
Expand All @@ -230,8 +232,21 @@ private void CustomiseWallpaper(ScreenLayoutModel selection)
public RelayCommand NavigateBackWallpaperCommand =>
new RelayCommand(() => NavigatePage?.Invoke(this, new NavigatePageEventArgs() { Tag = "wallpaper", Arg = null }));

public void OnWindowClosing(object sender, RoutedEventArgs e)
=> desktopCore.WallpaperChanged -= SetupDesktop_WallpaperChanged;
// Page.Unloaded event is unreliable, if the issue is fixed just call this directly.
public void CustomiseWallpaperPageOnClosed()
{
if (customiseWallpaperViewModel == null)
return;

customiseWallpaperViewModel.OnClose();
customiseWallpaperViewModel = null;
}

public void OnWindowClosing(object sender, object e)
{
desktopCore.WallpaperChanged -= SetupDesktop_WallpaperChanged;
CustomiseWallpaperPageOnClosed();
}

private void UpdateLayout()
{
Expand Down

0 comments on commit 2f8d94b

Please sign in to comment.