Skip to content

Commit

Permalink
Windows10で名前の設定すると落ちる問題修正
Browse files Browse the repository at this point in the history
  • Loading branch information
Freeesia committed Mar 16, 2024
1 parent 8b3123f commit be70e52
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 11 deletions.
12 changes: 9 additions & 3 deletions VdLabel/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ partial class MainViewModel : ObservableObject
{
private readonly IConfigStore configStore;
private readonly IContentDialogService dialogService;
private readonly IVirtualDesktopCompat virtualDesktopCompat;
[ObservableProperty]
private bool isBusy;

Expand All @@ -28,10 +29,11 @@ partial class MainViewModel : ObservableObject

public IReadOnlyList<OverlayPosition> Positions { get; } = Enum.GetValues<OverlayPosition>();

public MainViewModel(IConfigStore configStore, IContentDialogService dialogService)
public MainViewModel(IConfigStore configStore, IContentDialogService dialogService, IVirtualDesktopCompat virtualDesktopCompat)
{
this.configStore = configStore;
this.dialogService = dialogService;
this.virtualDesktopCompat = virtualDesktopCompat;
this.isStartup = GetIsStartup();
Load();
}
Expand All @@ -45,7 +47,7 @@ private async void Load()
this.DesktopConfigs.Clear();
foreach (var desktopConfig in this.Config.DesktopConfigs)
{
this.DesktopConfigs.Add(new DesktopConfigViewModel(desktopConfig));
this.DesktopConfigs.Add(new DesktopConfigViewModel(desktopConfig, this.virtualDesktopCompat));
}
this.SelectedDesktopConfig = this.DesktopConfigs.FirstOrDefault();
}
Expand Down Expand Up @@ -101,8 +103,10 @@ private static bool GetIsStartup()
}
}

partial class DesktopConfigViewModel(DesktopConfig desktopConfig) : ObservableObject
partial class DesktopConfigViewModel(DesktopConfig desktopConfig, IVirtualDesktopCompat virtualDesktopCompat) : ObservableObject
{
private readonly IVirtualDesktopCompat virtualDesktopCompat = virtualDesktopCompat;

public DesktopConfig DesktopConfig { get; } = desktopConfig;

public Guid Id => this.DesktopConfig.Id;
Expand All @@ -129,6 +133,8 @@ public string? Name
}
}

public bool ShowChangeNameWarning => !this.virtualDesktopCompat.IsSupportedChangeName;

public string? ImagePath
{
get => this.DesktopConfig.ImagePath;
Expand Down
15 changes: 12 additions & 3 deletions VdLabel/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Label
Expand All @@ -180,18 +181,26 @@
IsReadOnly="{Binding IsDefault}"
PlaceholderText="{Binding Id, Mode=OneWay}"
Text="{Binding Name, UpdateSourceTrigger=PropertyChanged}" />
<CheckBox
<ui:InfoBar
Title="注意"
Grid.Row="2"
Grid.Column="1"
IsClosable="False"
IsOpen="{Binding ShowChangeNameWarning}"
Message="現在のWindowsバージョンでは仮想デスクトップの名前同期はサポートされません"
Severity="Warning" />
<CheckBox
Grid.Row="3"
Grid.Column="1"
Margin="4"
Content="画像が設定されているときに名前を表示するかどうか"
IsChecked="{Binding IsVisibleName}" />
<Label
Grid.Row="3"
Grid.Row="4"
Grid.Column="0"
Content="切り替え通知画像" />
<DockPanel
Grid.Row="3"
Grid.Row="4"
Grid.Column="1"
Margin="4">
<Button
Expand Down
1 change: 1 addition & 0 deletions VdLabel/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

var builder = KamishibaiApplication<App, MainWindow>.CreateBuilder();
builder.Services.AddHostedService<VirtualDesktopService>()
.AddSingleton<IVirtualDesktopCompat, VirtualDesktopCompat>()
.AddSingleton<IConfigStore, ConfigStore>()
.AddSingleton<IContentDialogService, ContentDialogService>()
.AddPresentation<MainWindow, MainViewModel>()
Expand Down
27 changes: 22 additions & 5 deletions VdLabel/VirtualDesktopService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@

namespace VdLabel;

class VirtualDesktopService(App app, IWindowService windowService, IConfigStore configStore) : IHostedService
class VirtualDesktopService(App app, IWindowService windowService, IConfigStore configStore, IVirtualDesktopCompat virtualDesktopCompat) : IHostedService
{
private readonly App app = app;
private readonly IWindowService windowService = windowService;
private readonly IConfigStore configStore = configStore;
private readonly IVirtualDesktopCompat virtualDesktopCompat = virtualDesktopCompat;
private OpenWindowOptions options = new() { WindowStartupLocation = WindowStartupLocation.CenterScreen };
private readonly ConcurrentDictionary<Guid, (IWindow window, OverlayViewModel vm)> windows = [];

Expand All @@ -39,15 +40,16 @@ public async Task StartAsync(CancellationToken cancellationToken)
c = defaultConfig with { Id = desktop.Id };
config.DesktopConfigs.Add(c);
}
if (!string.IsNullOrEmpty(c.Name))
var name = c.Name;
if (!string.IsNullOrEmpty(name) && this.virtualDesktopCompat.IsSupportedChangeName)
{
desktop.Name = c.Name;
desktop.Name = name;
}
else if (!string.IsNullOrEmpty(desktop.Name))
{
c.Name = desktop.Name;
name = desktop.Name;
}
var name = desktop.Name;
c.Name = name;
if (string.IsNullOrEmpty(name))
{
name = $"Desktop {i + 1}";
Expand Down Expand Up @@ -153,3 +155,18 @@ public Task StopAsync(CancellationToken cancellationToken)
[UnsafeAccessor(UnsafeAccessorKind.Field, Name = "_window")]
static extern ref Window GetWindow(WindowHandle window);
}

class VirtualDesktopCompat : IVirtualDesktopCompat
{
public bool IsSupportedChangeName { get; }

public VirtualDesktopCompat()
{
this.IsSupportedChangeName = false;
//this.IsSupportedChangeName = OperatingSystem.IsWindowsVersionAtLeast(10, 0, 20348, 0);
}
}
interface IVirtualDesktopCompat
{
bool IsSupportedChangeName { get; }
}

0 comments on commit be70e52

Please sign in to comment.