mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 19:57:57 +01:00
Add tmp progress ring to show applying changes progress
Ignore not needed json fields
This commit is contained in:
@@ -66,6 +66,7 @@
|
|||||||
<KeyboardAccelerator Key="N" Modifiers="Control" />
|
<KeyboardAccelerator Key="N" Modifiers="Control" />
|
||||||
</Button.KeyboardAccelerators>
|
</Button.KeyboardAccelerators>
|
||||||
</Button>
|
</Button>
|
||||||
|
<ProgressRing IsActive="{x:Bind ViewModel.ApplyingChanges, Mode=TwoWay}" />
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid Grid.Row="1" ColumnSpacing="32">
|
<Grid Grid.Row="1" ColumnSpacing="32">
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using System;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using EnvironmentVariables.Helpers;
|
using EnvironmentVariables.Helpers;
|
||||||
|
using EnvironmentVariables.ViewModels;
|
||||||
using ManagedCommon;
|
using ManagedCommon;
|
||||||
|
|
||||||
namespace EnvironmentVariables.Models
|
namespace EnvironmentVariables.Models
|
||||||
@@ -18,16 +19,19 @@ namespace EnvironmentVariables.Models
|
|||||||
public ProfileVariablesSet()
|
public ProfileVariablesSet()
|
||||||
: base()
|
: base()
|
||||||
{
|
{
|
||||||
|
Type = VariablesSetType.Profile;
|
||||||
|
IconPath = ProfileIconPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProfileVariablesSet(Guid id, string name)
|
public ProfileVariablesSet(Guid id, string name)
|
||||||
: base(id, name, VariablesSetType.Profile)
|
: base(id, name, VariablesSetType.Profile)
|
||||||
{
|
{
|
||||||
|
IconPath = ProfileIconPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Apply()
|
public Task Apply()
|
||||||
{
|
{
|
||||||
Task.Run(() =>
|
return Task.Run(() =>
|
||||||
{
|
{
|
||||||
foreach (var variable in Variables)
|
foreach (var variable in Variables)
|
||||||
{
|
{
|
||||||
@@ -51,13 +55,17 @@ namespace EnvironmentVariables.Models
|
|||||||
Logger.LogError("Failed to set profile variable.");
|
Logger.LogError("Failed to set profile variable.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// viewModel.ApplyingChanges = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UnApply()
|
public Task UnApply()
|
||||||
{
|
{
|
||||||
Task.Run(() =>
|
return Task.Run(() =>
|
||||||
{
|
{
|
||||||
|
var viewModel = App.GetService<MainViewModel>();
|
||||||
|
viewModel.ApplyingChanges = true;
|
||||||
foreach (var variable in Variables)
|
foreach (var variable in Variables)
|
||||||
{
|
{
|
||||||
// Unset the variable
|
// Unset the variable
|
||||||
@@ -87,6 +95,8 @@ namespace EnvironmentVariables.Models
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
viewModel.ApplyingChanges = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using EnvironmentVariables.Helpers;
|
using EnvironmentVariables.Helpers;
|
||||||
|
|
||||||
@@ -17,8 +18,16 @@ namespace EnvironmentVariables.Models
|
|||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private string _values;
|
private string _values;
|
||||||
|
|
||||||
public bool Editable { get; private set; }
|
[JsonIgnore]
|
||||||
|
public bool Editable
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return ParentType != VariablesSetType.System || App.GetService<IElevationHelper>().IsElevated;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
public VariablesSetType ParentType { get; set; }
|
public VariablesSetType ParentType { get; set; }
|
||||||
|
|
||||||
public List<string> ValuesList { get; set; }
|
public List<string> ValuesList { get; set; }
|
||||||
@@ -32,7 +41,6 @@ namespace EnvironmentVariables.Models
|
|||||||
Name = name;
|
Name = name;
|
||||||
Values = values;
|
Values = values;
|
||||||
ParentType = parentType;
|
ParentType = parentType;
|
||||||
Editable = ParentType == VariablesSetType.User || (ParentType == VariablesSetType.System && App.GetService<IElevationHelper>().IsElevated);
|
|
||||||
|
|
||||||
var splitValues = Values.Split(';');
|
var splitValues = Values.Split(';');
|
||||||
if (splitValues.Length > 0)
|
if (splitValues.Length > 0)
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
|
||||||
namespace EnvironmentVariables.Models
|
namespace EnvironmentVariables.Models
|
||||||
@@ -16,16 +16,18 @@ namespace EnvironmentVariables.Models
|
|||||||
|
|
||||||
private static readonly string UserIconPath = "/Assets/EnvironmentVariables/UserIcon.png";
|
private static readonly string UserIconPath = "/Assets/EnvironmentVariables/UserIcon.png";
|
||||||
private static readonly string SystemIconPath = "/Assets/EnvironmentVariables/SystemIcon.png";
|
private static readonly string SystemIconPath = "/Assets/EnvironmentVariables/SystemIcon.png";
|
||||||
private static readonly string ProfileIconPath = "/Assets/EnvironmentVariables/ProfileIcon.png";
|
protected static readonly string ProfileIconPath = "/Assets/EnvironmentVariables/ProfileIcon.png";
|
||||||
|
|
||||||
public Guid Id { get; }
|
public Guid Id { get; }
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private string _name;
|
private string _name;
|
||||||
|
|
||||||
public VariablesSetType Type { get; }
|
[JsonIgnore]
|
||||||
|
public VariablesSetType Type { get; set; }
|
||||||
|
|
||||||
public string IconPath { get; }
|
[JsonIgnore]
|
||||||
|
public string IconPath { get; set; }
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private ObservableCollection<Variable> _variables;
|
private ObservableCollection<Variable> _variables;
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ using CommunityToolkit.Mvvm.Input;
|
|||||||
using EnvironmentVariables.Helpers;
|
using EnvironmentVariables.Helpers;
|
||||||
using EnvironmentVariables.Models;
|
using EnvironmentVariables.Models;
|
||||||
using ManagedCommon;
|
using ManagedCommon;
|
||||||
|
using Microsoft.UI.Dispatching;
|
||||||
|
|
||||||
namespace EnvironmentVariables.ViewModels
|
namespace EnvironmentVariables.ViewModels
|
||||||
{
|
{
|
||||||
@@ -20,6 +21,8 @@ namespace EnvironmentVariables.ViewModels
|
|||||||
{
|
{
|
||||||
private readonly IEnvironmentVariablesService _environmentVariablesService;
|
private readonly IEnvironmentVariablesService _environmentVariablesService;
|
||||||
|
|
||||||
|
private readonly DispatcherQueue _dispatcherQueue = DispatcherQueue.GetForCurrentThread();
|
||||||
|
|
||||||
public DefaultVariablesSet UserDefaultSet { get; private set; } = new DefaultVariablesSet(VariablesSet.UserGuid, ResourceLoaderInstance.ResourceLoader.GetString("User"), VariablesSetType.User);
|
public DefaultVariablesSet UserDefaultSet { get; private set; } = new DefaultVariablesSet(VariablesSet.UserGuid, ResourceLoaderInstance.ResourceLoader.GetString("User"), VariablesSetType.User);
|
||||||
|
|
||||||
public DefaultVariablesSet SystemDefaultSet { get; private set; } = new DefaultVariablesSet(VariablesSet.SystemGuid, ResourceLoaderInstance.ResourceLoader.GetString("System"), VariablesSetType.System);
|
public DefaultVariablesSet SystemDefaultSet { get; private set; } = new DefaultVariablesSet(VariablesSet.SystemGuid, ResourceLoaderInstance.ResourceLoader.GetString("System"), VariablesSetType.System);
|
||||||
@@ -35,6 +38,9 @@ namespace EnvironmentVariables.ViewModels
|
|||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private bool _isElevated;
|
private bool _isElevated;
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
private bool _applyingChanges;
|
||||||
|
|
||||||
public ProfileVariablesSet AppliedProfile { get; set; }
|
public ProfileVariablesSet AppliedProfile { get; set; }
|
||||||
|
|
||||||
public MainViewModel(IEnvironmentVariablesService environmentVariablesService)
|
public MainViewModel(IEnvironmentVariablesService environmentVariablesService)
|
||||||
@@ -71,6 +77,11 @@ namespace EnvironmentVariables.ViewModels
|
|||||||
foreach (var profile in profiles)
|
foreach (var profile in profiles)
|
||||||
{
|
{
|
||||||
profile.PropertyChanged += Profile_PropertyChanged;
|
profile.PropertyChanged += Profile_PropertyChanged;
|
||||||
|
|
||||||
|
foreach (var variable in profile.Variables)
|
||||||
|
{
|
||||||
|
variable.ParentType = VariablesSetType.Profile;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var applied = profiles.Where(x => x.IsEnabled).ToList();
|
var applied = profiles.Where(x => x.IsEnabled).ToList();
|
||||||
@@ -157,7 +168,15 @@ namespace EnvironmentVariables.ViewModels
|
|||||||
|
|
||||||
private void SetAppliedProfile(ProfileVariablesSet profile)
|
private void SetAppliedProfile(ProfileVariablesSet profile)
|
||||||
{
|
{
|
||||||
profile.Apply();
|
ApplyingChanges = true;
|
||||||
|
var task = profile.Apply();
|
||||||
|
task.ContinueWith((a) =>
|
||||||
|
{
|
||||||
|
_dispatcherQueue.TryEnqueue(() =>
|
||||||
|
{
|
||||||
|
ApplyingChanges = false;
|
||||||
|
});
|
||||||
|
});
|
||||||
AppliedProfile = profile;
|
AppliedProfile = profile;
|
||||||
PopulateAppliedVariables();
|
PopulateAppliedVariables();
|
||||||
}
|
}
|
||||||
@@ -168,7 +187,15 @@ namespace EnvironmentVariables.ViewModels
|
|||||||
{
|
{
|
||||||
var appliedProfile = AppliedProfile;
|
var appliedProfile = AppliedProfile;
|
||||||
appliedProfile.PropertyChanged -= Profile_PropertyChanged;
|
appliedProfile.PropertyChanged -= Profile_PropertyChanged;
|
||||||
AppliedProfile.UnApply();
|
ApplyingChanges = true;
|
||||||
|
var task = AppliedProfile.UnApply();
|
||||||
|
task.ContinueWith((a) =>
|
||||||
|
{
|
||||||
|
_dispatcherQueue.TryEnqueue(() =>
|
||||||
|
{
|
||||||
|
ApplyingChanges = false;
|
||||||
|
});
|
||||||
|
});
|
||||||
AppliedProfile.IsEnabled = false;
|
AppliedProfile.IsEnabled = false;
|
||||||
AppliedProfile = null;
|
AppliedProfile = null;
|
||||||
appliedProfile.PropertyChanged += Profile_PropertyChanged;
|
appliedProfile.PropertyChanged += Profile_PropertyChanged;
|
||||||
|
|||||||
Reference in New Issue
Block a user