/
githubmirror
/
PowerToys
Обзор
Документация
Войти
/
githubmirror
/
PowerToys
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/modules/Workspaces/WorkspacesLauncherUI/ViewModels/MainViewModel.cs
96 строк
3 KB
Kai Tao
Cmdpal extension: Powertoys extension for cmdpal (#44006)
23 дек 2025, 16:07
Не верифицирован
23 дек 2025, 16:07
d87dde1
Код
Авторство
О чём код?
// Copyright (c) Microsoft Corporation // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using ManagedCommon; using WorkspacesCsharpLibrary; using WorkspacesLauncherUI.Data; using WorkspacesLauncherUI.Models; namespace WorkspacesLauncherUI.ViewModels { public class MainViewModel : INotifyPropertyChanged, IDisposable { public ObservableCollection<AppLaunching> AppsListed { get; set; } = new ObservableCollection<AppLaunching>(); private StatusWindow _snapshotWindow; private int launcherProcessID; private PwaHelper _pwaHelper; public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged(PropertyChangedEventArgs e) { PropertyChanged?.Invoke(this, e); } public MainViewModel() { _pwaHelper = new PwaHelper(); // 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 HandleAppLaunchingState(AppLaunchData.AppLaunchDataWrapper appLaunchData) { launcherProcessID = appLaunchData.LauncherProcessID; List<AppLaunching> appLaunchingList = new List<AppLaunching>(); foreach (var app in appLaunchData.AppLaunchInfos.AppLaunchInfoList) { appLaunchingList.Add(new AppLaunching() { Name = app.Application.Application, AppPath = app.Application.ApplicationPath, PackagedName = app.Application.PackageFullName, Aumid = app.Application.AppUserModelId, PwaAppId = app.Application.PwaAppId, LaunchState = app.State, }); } AppsListed = new ObservableCollection<AppLaunching>(appLaunchingList); OnPropertyChanged(new PropertyChangedEventArgs(nameof(AppsListed))); } private void SelfDestroy(object source, System.Timers.ElapsedEventArgs e) { _snapshotWindow.Dispatcher.Invoke(() => { _snapshotWindow.Close(); }); } public void Dispose() { GC.SuppressFinalize(this); } internal void SetSnapshotWindow(StatusWindow snapshotWindow) { _snapshotWindow = snapshotWindow; } internal void CancelLaunch() { App.SendIPCMessage("cancel"); } } }