[Workspaces] Handle admin windows repositioning. (#34965)

This commit is contained in:
Seraphima Zykova
2024-09-25 12:13:38 +03:00
committed by GitHub
parent 499dc9bb7a
commit 1e18e83af6
65 changed files with 2531 additions and 891 deletions

View File

@@ -7,9 +7,6 @@ using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.IO.Abstractions;
using ManagedCommon;
using WorkspacesLauncherUI.Data;
using WorkspacesLauncherUI.Models;
@@ -20,8 +17,6 @@ namespace WorkspacesLauncherUI.ViewModels
{
public ObservableCollection<AppLaunching> AppsListed { get; set; } = new ObservableCollection<AppLaunching>();
private IFileSystemWatcher _watcher;
private System.Timers.Timer selfDestroyTimer;
private StatusWindow _snapshotWindow;
private int launcherProcessID;
private bool _exiting;
@@ -36,60 +31,43 @@ namespace WorkspacesLauncherUI.ViewModels
public MainViewModel()
{
_exiting = false;
LoadAppLaunchInfos();
string fileName = Path.GetFileName(AppLaunchData.File);
_watcher = Microsoft.PowerToys.Settings.UI.Library.Utilities.Helper.GetFileWatcher("Workspaces", fileName, () => AppLaunchInfoStateChanged());
// receive IPC Message
App.IPCMessageReceivedCallback = (string msg) =>
{
try
{
AppLaunchData parser = new AppLaunchData();
AppLaunchData.AppLaunchDataWrapper appLaunchData = parser.Deserialize(msg);
HandleAppLaunchingState(appLaunchData);
}
catch (Exception ex)
{
Logger.LogError(ex.Message);
}
};
}
private void AppLaunchInfoStateChanged()
{
LoadAppLaunchInfos();
}
private void LoadAppLaunchInfos()
private void HandleAppLaunchingState(AppLaunchData.AppLaunchDataWrapper appLaunchData)
{
if (_exiting)
{
return;
}
AppLaunchData parser = new AppLaunchData();
if (!File.Exists(AppLaunchData.File))
{
Logger.LogWarning($"AppLaunchInfosData storage file not found: {AppLaunchData.File}");
return;
}
AppLaunchData.AppLaunchDataWrapper appLaunchData = parser.Read(AppLaunchData.File);
launcherProcessID = appLaunchData.LauncherProcessID;
List<AppLaunching> appLaunchingList = new List<AppLaunching>();
bool allLaunched = true;
foreach (var app in appLaunchData.AppLaunchInfos.AppLaunchInfoList)
{
appLaunchingList.Add(new AppLaunching()
{
Name = app.Name,
AppPath = app.Path,
Application = app.Application,
LaunchState = app.State,
});
if (app.State != "launched" && app.State != "failed")
{
allLaunched = false;
}
}
AppsListed = new ObservableCollection<AppLaunching>(appLaunchingList);
OnPropertyChanged(new PropertyChangedEventArgs(nameof(AppsListed)));
if (allLaunched)
{
selfDestroyTimer = new System.Timers.Timer();
selfDestroyTimer.Interval = 1000;
selfDestroyTimer.Elapsed += SelfDestroy;
selfDestroyTimer.Start();
}
}
private void SelfDestroy(object source, System.Timers.ElapsedEventArgs e)
@@ -113,7 +91,6 @@ namespace WorkspacesLauncherUI.ViewModels
internal void CancelLaunch()
{
_exiting = true;
_watcher.Dispose();
Process proc = Process.GetProcessById(launcherProcessID);
proc.Kill();
}