Skip to content

Commit 6e6de25

Browse files
committed
UWP Apps selection
1 parent 3355e2b commit 6e6de25

20 files changed

+1016
-143
lines changed

Source/HDRProfile/App.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@
176176
<DataTemplate DataType="{x:Type local:ApplicationAdder}">
177177
<local:ApplicationAdderView></local:ApplicationAdderView>
178178
</DataTemplate>
179+
<DataTemplate DataType="{x:Type local:UWPApplicationDialog}">
180+
<local:UWPApplicationDialogView></local:UWPApplicationDialogView>
181+
</DataTemplate>
179182
</Application.Resources>
180183

181184
</Application>

Source/HDRProfile/ApplicationAdder.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public class ApplicationAdder : DialogViewModelBase
2121
public ApplicationItem ApplicationItem { get => applicationItem; private set { applicationItem = value; OnPropertyChanged(); } }
2222

2323
public RelayCommand GetFileCommand { get; private set; }
24+
public RelayCommand GetUWPAppCommand { get; private set; }
25+
2426
public RelayCommand<object> OKClickCommand { get; private set; }
2527

2628
public event EventHandler OKClicked;
@@ -34,6 +36,7 @@ public ApplicationAdder()
3436
private void CreateRelayCommands()
3537
{
3638
GetFileCommand = new RelayCommand(GetFile);
39+
GetUWPAppCommand = new RelayCommand(GetUWPAplication);
3740
OKClickCommand = new RelayCommand<object>(CreateApplicationItem);
3841
}
3942

@@ -74,5 +77,20 @@ public void CreateApplicationItem(object parameter)
7477
OKClicked?.Invoke(this, EventArgs.Empty);
7578
CloseDialog(parameter as Window);
7679
}
80+
81+
private void GetUWPAplication()
82+
{
83+
UIServices.SetBusyState();
84+
UWPApplicationDialog uwpDialog = new UWPApplicationDialog();
85+
uwpDialog.OKClicked += (o, e) =>
86+
{
87+
ApplicationItem = uwpDialog.ApplicationItem;
88+
DisplayName = ApplicationItem.DisplayName;
89+
FilePath = ApplicationItem.ApplicationFilePath;
90+
};
91+
if (DialogService != null)
92+
DialogService.ShowDialogModal(uwpDialog);
93+
}
94+
7795
}
7896
}

Source/HDRProfile/ApplicationAdderView.xaml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,17 @@
1717
<Label Content="{x:Static local:Locale_Texts.FilePath}" HorizontalAlignment="Left" Margin="10,41,0,0" VerticalAlignment="Top" Width="111"/>
1818
<TextBox Height="23" Margin="126,13,10,0" TextWrapping="Wrap" Text="{Binding DisplayName, Mode=TwoWay }" VerticalAlignment="Top"/>
1919
<TextBlock Text="{Binding FilePath}" Margin="126,41,10,0" VerticalAlignment="Top" Height="26" />
20-
<Button Content="{x:Static local:Locale_Texts.OK}" IsEnabled="{Binding CanCreate}" Command="{Binding OKClickCommand}" CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=Window}}" VerticalAlignment="Top" HorizontalAlignment="Right" Width="Auto" Height="Auto" Grid.Row="1" Margin="5"/>
21-
<Button Content="{Binding Source={x:Static local:Locale_Texts.ChooseApplication}, StringFormat={}{0}...}" Command="{Binding GetFileCommand}" VerticalAlignment="Top" Grid.Row="1" HorizontalAlignment="Left" Width="Auto" Height="Auto" Margin="5">
2220

23-
</Button>
21+
<Grid Grid.Row="1" >
22+
<Grid.ColumnDefinitions>
23+
<ColumnDefinition Width="Auto" />
24+
<ColumnDefinition Width=" Auto"/>
25+
<ColumnDefinition/>
2426

27+
</Grid.ColumnDefinitions>
28+
<Button Grid.Column="2" Content="{x:Static local:Locale_Texts.OK}" IsEnabled="{Binding CanCreate}" Command="{Binding OKClickCommand}" CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=Window}}" VerticalAlignment="Top" HorizontalAlignment="Right" Width="Auto" Height="Auto" Margin="5"/>
29+
<Button Grid.Column="0" Content="{Binding Source={x:Static local:Locale_Texts.ChooseApplication}, StringFormat={}{0}...}" Command="{Binding GetFileCommand}" VerticalAlignment="Top" HorizontalAlignment="Left" Width="Auto" Height="Auto" Margin="5"/>
30+
<Button Grid.Column="1" Content="{Binding Source={x:Static local:Locale_Texts.ChooseUWPApplication}, StringFormat={}{0}...}" Command="{Binding GetUWPAppCommand}" Height="Auto" Margin="5" VerticalAlignment="Bottom" HorizontalAlignment="Left"/>
31+
</Grid>
2532
</Grid>
2633
</UserControl>
-1 KB
Binary file not shown.

Source/HDRProfile/HDRProfile.csproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@
126126
<Reference Include="System.IdentityModel" />
127127
<Reference Include="System.IO.Compression" />
128128
<Reference Include="System.Management" />
129+
<Reference Include="System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
130+
<HintPath>..\packages\Microsoft.PowerShell.5.ReferenceAssemblies.1.1.0\lib\net4\System.Management.Automation.dll</HintPath>
131+
</Reference>
129132
<Reference Include="System.Runtime.Serialization" />
130133
<Reference Include="System.Runtime.Serialization.Primitives, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
131134
<HintPath>..\packages\System.Runtime.Serialization.Primitives.4.3.0\lib\net46\System.Runtime.Serialization.Primitives.dll</HintPath>
@@ -155,6 +158,10 @@
155158
<Generator>MSBuild:Compile</Generator>
156159
<SubType>Designer</SubType>
157160
</ApplicationDefinition>
161+
<Compile Include="UWPApplicationDialogView.xaml.cs">
162+
<DependentUpon>UWPApplicationDialogView.xaml</DependentUpon>
163+
</Compile>
164+
<Compile Include="UWPApplicationDialog.cs" />
158165
<Compile Include="ApplicationState.cs" />
159166
<Compile Include="HDRController.cs" />
160167
<Compile Include="Monitor.cs" />
@@ -175,6 +182,13 @@
175182
<Compile Include="NightLightManager.cs" />
176183
<Compile Include="Tools.cs" />
177184
<Compile Include="TrayMenuHelper.cs" />
185+
<Compile Include="UWP\AppxManifest.cs" />
186+
<Compile Include="UWP\UWPAppsManager.cs" />
187+
<Compile Include="UWP\UWPApp.cs" />
188+
<Page Include="UWPApplicationDialogView.xaml">
189+
<Generator>MSBuild:Compile</Generator>
190+
<SubType>Designer</SubType>
191+
</Page>
178192
<Page Include="MonitorManagerView.xaml">
179193
<SubType>Designer</SubType>
180194
<Generator>MSBuild:Compile</Generator>

Source/HDRProfile/HDRProfileHandler.cs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class HDRProfileHandler : BaseViewModel
3434
private HDRProfileSettings _settings;
3535
private MonitorManager _monitorManager;
3636

37-
Dictionary<ApplicationItem, ApplicationState> _lastRestartAppStates = new Dictionary<ApplicationItem, ApplicationState>();
37+
Dictionary<ApplicationItem, ApplicationState> _lastAppStates = new Dictionary<ApplicationItem, ApplicationState>();
3838

3939
private string SettingsPath => $"{System.AppDomain.CurrentDomain.BaseDirectory}HDRProfile_Settings.xml";
4040

@@ -160,7 +160,7 @@ private void MonitorManager_HDRIsActiveChanged(object sender, EventArgs e)
160160
private void MonitorManager_AutoHDRChanged(object sender, EventArgs e)
161161
{
162162
SaveSettings();
163-
SetHDRBasedOnCurrentApplication();
163+
UpdateHDRModeBasedOnCurrentApplication();
164164
}
165165

166166
private void TrayMenuHelper_OpenViewRequested(object sender, EventArgs e)
@@ -242,7 +242,7 @@ private void Settings_PropertyChanged(object sender, PropertyChangedEventArgs e)
242242
Logs.AddException(ex);
243243
}
244244
if (e.PropertyName.Equals(nameof(Settings.HDRMode)))
245-
SetHDRBasedOnCurrentApplication();
245+
UpdateHDRModeBasedOnCurrentApplication();
246246
Logs.LoggingEnabled = Settings.Logging;
247247
SaveSettings();
248248
}
@@ -316,7 +316,7 @@ public void Start()
316316
MonitorManager.StartMonitoring();
317317
Logs.Add($"HDR Monitoring started", false);
318318
Started = true;
319-
SetHDRBasedOnCurrentApplication();
319+
UpdateHDRModeBasedOnCurrentApplication();
320320

321321
}
322322
}
@@ -394,6 +394,7 @@ private void ApplicationItem_PropertyChanged(object sender, PropertyChangedEvent
394394
private void AddAplication()
395395
{
396396
ApplicationAdder adder = new ApplicationAdder();
397+
adder.DialogService = DialogService;
397398
adder.OKClicked += (o, e) =>
398399
{
399400
if (!Settings.ApplicationItems.Any(pi => pi.ApplicationFilePath == adder.ApplicationItem.ApplicationFilePath))
@@ -413,11 +414,11 @@ private void RemoveApplication(ApplicationItem process)
413414
private void ProcessWatcher_RunningOrFocusedChanged(object sender, EventArgs e)
414415
{
415416
CurrentApplication = ProcessWatcher.CurrentRunningApplicationItem;
416-
SetHDRBasedOnCurrentApplication();
417+
UpdateHDRModeBasedOnCurrentApplication();
417418

418419
}
419420

420-
private void SetHDRBasedOnCurrentApplication()
421+
private void UpdateHDRModeBasedOnCurrentApplication()
421422
{
422423
lock (_accessLock)
423424
{
@@ -457,7 +458,8 @@ private void SetHDRBasedOnCurrentApplication()
457458
MonitorManager.DeactivateHDR(monitor);
458459
}
459460
}
460-
UpdateRestartAppStates((IDictionary<ApplicationItem, ApplicationState>)ProcessWatcher.Applications, activateHDR);
461+
var currentApplications = ProcessWatcher.Applications;
462+
UpdateRestartAppStates((IDictionary<ApplicationItem, ApplicationState>)currentApplications, activateHDR);
461463

462464
if (MonitorManager.GlobalHDRIsActive)
463465
Logs.Add($"HDR is active", false);
@@ -472,24 +474,23 @@ private void SetHDRBasedOnCurrentApplication()
472474
}
473475
}
474476

475-
private void UpdateRestartAppStates(IDictionary<ApplicationItem, ApplicationState> applicationStates, bool restartIfNecessary)
477+
private void UpdateRestartAppStates(IDictionary<ApplicationItem, ApplicationState> applicationStates, bool restartApps)
476478
{
477-
Dictionary<ApplicationItem, ApplicationState> newLastStates = new Dictionary<ApplicationItem, ApplicationState>();
479+
Dictionary<ApplicationItem, ApplicationState> newLastAppStates = new Dictionary<ApplicationItem, ApplicationState>();
478480
foreach (var applicationState in applicationStates)
479481
{
480-
if (!applicationState.Key.RestartProcess)
481-
continue;
482-
newLastStates.Add(applicationState.Key, applicationState.Value);
483-
if (restartIfNecessary)
482+
newLastAppStates.Add(applicationState.Key, applicationState.Value);
483+
484+
if (restartApps)
484485
{
485-
if (!_lastRestartAppStates.ContainsKey(applicationState.Key) && applicationState.Value != ApplicationState.None)
486+
if (!_lastAppStates.ContainsKey(applicationState.Key) && applicationState.Value != ApplicationState.None)
486487
RestartProcess(applicationState.Key);
487-
else if (_lastRestartAppStates.ContainsKey(applicationState.Key) && applicationState.Value != ApplicationState.None && _lastRestartAppStates[applicationState.Key] == ApplicationState.None)
488+
else if (_lastAppStates.ContainsKey(applicationState.Key) && applicationState.Value != ApplicationState.None && _lastAppStates[applicationState.Key] == ApplicationState.None)
488489
RestartProcess(applicationState.Key);
489490
}
490491
}
491-
_lastRestartAppStates.Clear();
492-
_lastRestartAppStates = newLastStates;
492+
_lastAppStates.Clear();
493+
_lastAppStates = newLastAppStates;
493494
}
494495

495496
private void RestartProcess(ApplicationItem application)

Source/HDRProfile/Locale_Texts.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Source/HDRProfile/Locale_Texts.de.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@
147147
<data name="ChooseApplication" xml:space="preserve">
148148
<value>Anwendungen wählen</value>
149149
</data>
150+
<data name="ChooseUWPApplication" xml:space="preserve">
151+
<value>UWP App auswählen...</value>
152+
</data>
150153
<data name="CompatibilityModeToolTip" xml:space="preserve">
151154
<value>Startet die Anwendung neu, sobald sie erstmalig erkannt wurde, da für einige Anwendung HDR vor dem Start aktiv sein muss.</value>
152155
</data>

Source/HDRProfile/Locale_Texts.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@
147147
<data name="ChooseApplication" xml:space="preserve">
148148
<value>Choose application</value>
149149
</data>
150+
<data name="ChooseUWPApplication" xml:space="preserve">
151+
<value>Choose UWP app...</value>
152+
</data>
150153
<data name="CompatibilityModeToolTip" xml:space="preserve">
151154
<value>Restarts the application on first occurence, as the application may need HDR to be activated before launching it.</value>
152155
</data>

0 commit comments

Comments
 (0)