2020-04-11 06:22:07 +08:00
|
|
|
|
// 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.
|
|
|
|
|
|
2022-04-20 04:00:28 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Diagnostics;
|
2021-02-26 19:21:58 +08:00
|
|
|
|
using System.Globalization;
|
2022-04-20 04:00:28 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using interop;
|
|
|
|
|
using ManagedCommon;
|
2020-10-30 05:24:16 +08:00
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Helpers;
|
2021-02-26 19:21:58 +08:00
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Library;
|
2022-04-20 04:00:28 +08:00
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Library.Telemetry.Events;
|
2022-07-05 20:25:25 +08:00
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
2023-01-31 07:00:11 +08:00
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Views;
|
2022-04-20 04:00:28 +08:00
|
|
|
|
using Microsoft.PowerToys.Telemetry;
|
|
|
|
|
using Microsoft.UI.Xaml;
|
|
|
|
|
using Windows.UI.Popups;
|
|
|
|
|
using WinRT.Interop;
|
2020-03-07 09:46:51 +08:00
|
|
|
|
|
2020-03-12 01:43:32 +08:00
|
|
|
|
namespace Microsoft.PowerToys.Settings.UI
|
2020-03-07 09:46:51 +08:00
|
|
|
|
{
|
2022-04-20 04:00:28 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Provides application-specific behavior to supplement the default Application class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class App : Application
|
2020-03-07 09:46:51 +08:00
|
|
|
|
{
|
2022-04-20 04:00:28 +08:00
|
|
|
|
private enum Arguments
|
|
|
|
|
{
|
|
|
|
|
PTPipeName = 1,
|
|
|
|
|
SettingsPipeName,
|
|
|
|
|
PTPid,
|
|
|
|
|
Theme, // used in the old settings
|
|
|
|
|
ElevatedStatus,
|
|
|
|
|
IsUserAdmin,
|
|
|
|
|
ShowOobeWindow,
|
|
|
|
|
ShowScoobeWindow,
|
2023-01-31 07:00:11 +08:00
|
|
|
|
ShowFlyout,
|
2023-02-03 23:10:14 +08:00
|
|
|
|
ContainsSettingsWindow,
|
|
|
|
|
ContainsFlyoutPosition,
|
2022-04-20 04:00:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Quantity of arguments
|
2023-02-03 23:10:14 +08:00
|
|
|
|
private const int RequiredArgumentsQty = 12;
|
2022-04-20 04:00:28 +08:00
|
|
|
|
|
|
|
|
|
// Create an instance of the IPC wrapper.
|
|
|
|
|
private static TwoWayPipeMessageIPCManaged ipcmanager;
|
|
|
|
|
|
|
|
|
|
public static bool IsElevated { get; set; }
|
|
|
|
|
|
|
|
|
|
public static bool IsUserAnAdmin { get; set; }
|
|
|
|
|
|
|
|
|
|
public static int PowerToysPID { get; set; }
|
|
|
|
|
|
|
|
|
|
public bool ShowOobe { get; set; }
|
|
|
|
|
|
2023-01-31 07:00:11 +08:00
|
|
|
|
public bool ShowFlyout { get; set; }
|
|
|
|
|
|
2022-04-20 04:00:28 +08:00
|
|
|
|
public bool ShowScoobe { get; set; }
|
|
|
|
|
|
|
|
|
|
public Type StartupPage { get; set; } = typeof(Views.GeneralPage);
|
|
|
|
|
|
|
|
|
|
public static Action<string> IPCMessageReceivedCallback { get; set; }
|
|
|
|
|
|
2022-07-05 20:25:25 +08:00
|
|
|
|
private static bool loggedImmersiveDarkException;
|
|
|
|
|
|
2022-04-20 04:00:28 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="App"/> class.
|
|
|
|
|
/// Initializes the singleton application object. This is the first line of authored code
|
|
|
|
|
/// executed, and as such is the logical equivalent of main() or WinMain().
|
|
|
|
|
/// </summary>
|
2020-03-07 09:46:51 +08:00
|
|
|
|
public App()
|
|
|
|
|
{
|
2023-03-21 17:27:29 +08:00
|
|
|
|
Logger.InitializeLogger("\\Settings\\Logs");
|
|
|
|
|
|
2022-04-20 04:00:28 +08:00
|
|
|
|
this.InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-31 07:00:11 +08:00
|
|
|
|
public static void OpenSettingsWindow(Type type = null, bool ensurePageIsSelected = false)
|
2022-04-20 04:00:28 +08:00
|
|
|
|
{
|
|
|
|
|
if (settingsWindow == null)
|
|
|
|
|
{
|
2022-07-01 17:52:48 +08:00
|
|
|
|
settingsWindow = new MainWindow(IsDarkTheme());
|
2023-01-31 07:00:11 +08:00
|
|
|
|
type = typeof(GeneralPage);
|
2022-04-20 04:00:28 +08:00
|
|
|
|
}
|
2020-05-10 05:10:57 +08:00
|
|
|
|
|
2022-04-20 04:00:28 +08:00
|
|
|
|
settingsWindow.Activate();
|
2023-01-31 07:00:11 +08:00
|
|
|
|
if (type != null)
|
|
|
|
|
{
|
|
|
|
|
settingsWindow.NavigateToSection(type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ensurePageIsSelected)
|
|
|
|
|
{
|
|
|
|
|
settingsWindow.EnsurePageIsSelected();
|
|
|
|
|
}
|
2022-04-20 04:00:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Invoked when the application is launched normally by the end user. Other entry points
|
|
|
|
|
/// will be used such as when the application is launched to open a specific file.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="args">Details about the launch request and process.</param>
|
|
|
|
|
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
var cmdArgs = Environment.GetCommandLineArgs();
|
2023-01-31 07:00:11 +08:00
|
|
|
|
|
2022-07-01 17:52:48 +08:00
|
|
|
|
var isDark = IsDarkTheme();
|
2022-04-20 04:00:28 +08:00
|
|
|
|
|
|
|
|
|
if (cmdArgs != null && cmdArgs.Length >= RequiredArgumentsQty)
|
|
|
|
|
{
|
|
|
|
|
// Skip the first argument which is prepended when launched by explorer
|
|
|
|
|
if (cmdArgs[0].EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase) && cmdArgs[1].EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase) && (cmdArgs.Length >= RequiredArgumentsQty + 1))
|
|
|
|
|
{
|
|
|
|
|
cmdArgs = cmdArgs.Skip(1).ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_ = int.TryParse(cmdArgs[(int)Arguments.PTPid], out int powerToysPID);
|
|
|
|
|
PowerToysPID = powerToysPID;
|
|
|
|
|
|
|
|
|
|
IsElevated = cmdArgs[(int)Arguments.ElevatedStatus] == "true";
|
|
|
|
|
IsUserAnAdmin = cmdArgs[(int)Arguments.IsUserAdmin] == "true";
|
|
|
|
|
ShowOobe = cmdArgs[(int)Arguments.ShowOobeWindow] == "true";
|
|
|
|
|
ShowScoobe = cmdArgs[(int)Arguments.ShowScoobeWindow] == "true";
|
2023-01-31 07:00:11 +08:00
|
|
|
|
ShowFlyout = cmdArgs[(int)Arguments.ShowFlyout] == "true";
|
2023-02-03 23:10:14 +08:00
|
|
|
|
bool containsSettingsWindow = cmdArgs[(int)Arguments.ContainsSettingsWindow] == "true";
|
|
|
|
|
bool containsFlyoutPosition = cmdArgs[(int)Arguments.ContainsFlyoutPosition] == "true";
|
2022-04-20 04:00:28 +08:00
|
|
|
|
|
2023-02-03 23:10:14 +08:00
|
|
|
|
// To keep track of variable arguments
|
|
|
|
|
int currentArgumentIndex = RequiredArgumentsQty;
|
|
|
|
|
|
|
|
|
|
if (containsSettingsWindow)
|
2022-04-20 04:00:28 +08:00
|
|
|
|
{
|
|
|
|
|
// open specific window
|
2023-02-03 23:10:14 +08:00
|
|
|
|
switch (cmdArgs[currentArgumentIndex])
|
2022-04-20 04:00:28 +08:00
|
|
|
|
{
|
|
|
|
|
case "Overview": StartupPage = typeof(Views.GeneralPage); break;
|
|
|
|
|
case "AlwaysOnTop": StartupPage = typeof(Views.AlwaysOnTopPage); break;
|
|
|
|
|
case "Awake": StartupPage = typeof(Views.AwakePage); break;
|
|
|
|
|
case "ColorPicker": StartupPage = typeof(Views.ColorPickerPage); break;
|
|
|
|
|
case "FancyZones": StartupPage = typeof(Views.FancyZonesPage); break;
|
[New PowerToy] File Locksmith (#20930)
* Imported offline solution
* Make solution compile
* Add Windows sample, doesn't work?
* Added new project to implement the dll
* Remove unneeded header
* Implemented IUnknown part of ExplorerCommand
* Implemented IExplorerCommand methods
* Implemented ClassFactory
* Implemented DLL register/unregister
* Implemented other DLL exports, not working?
* Implemented IShellExtInit inferface
* Implemented IContextMenu, it works!
* Implement command data fetching
* Make sample project compile on VS 2022
* Add plan
* Implement Lib as separate project
* Implemented IPC, not tested
* Console UI project skeleton
* Implemented basic console UI
* Implemented piping, there are bugs
* Prototype works
* Remove old project
* Added GUI project skeleton
* Mitigate issue with WinUI3
* Added a control for displaying results
* Add button
* Implement core functions in lib project
* Call new library function from console main
* Implement showing results
* Improve UI
* Implemented subdirectory search
* Remove useless code
* Set window size
* UI adjustments
* Implement killing process
* Rename variable
* Add lib project to main solution
* Add Ext and GUI projects to solution
* Tweak packages for GUI project
* Add a settings page
* Add a few resource strings
* Add one more resources string
* VS keeps trying to correct this
* Add references to File Locksmith in /,github
* Implement some parts of FileLocksmithModule
* Change output directory
* Change target name and add to runner
* Add logger
* Started implementing settings backend
* Fix log folder
* Settings work
* Add some basic tracing
* Attempt at adding resources
* Remove junk files
* Added missing defines
* Replaced some constants with resources
Something's not working
* Move resources to the Ext project
* Remove experiment
* Add binaries for signing
* Improve tracing
* Remove old Settings calls
* Show something when there are no results
* Change window title
* Move computation to another thread, improve UX
* Increase font size for default text
* Remove entries for killed processes
* Show user name
* Remove nonrecursive implementation
* Implement back end for getting file names
* Show list of files, UI tweaks
* Remove useless includes
* Implement back end for getting full process path
* Dark title bar on dark themes
* Using Expander, other UI adjustments
* Show "No results" after killing all processes
* Show progress ring
* Update configuration mapping
* Revert "Update configuration mapping"
This reverts commit d8e13206f3c7de3c6dbf880299bfff3bf9f27a37.
* Fixed solution configuration, ARM64 should build
* Backend for refreshing
* Variable window size
* Add refresh button
* New WinUI3 C# project for FL
* Started porting functionality
* Add Interop project
* Move IPC to Ext project
* Ported native functions to Interop
* Ported finding processes
* Ported most of Main Window functionality
* Display paths of files
* Implement killing processes
* Use resource string for "End Task"
* Remove entries for terminated processes
* Show User name
* Set default window size
* Make the new UI the default
* Reading paths from stdin, completed port to C#
* Fix small bug
* Moving to MVVM
* Adding Labs
* Merge branch 'ivan/file-locksmith' of https://github.com/microsoft/PowerToys into ivan/file-locksmith
Removing one parent commit for cleaner history
Co-Authored-By: Niels Laute <niels.laute@live.nl>
* Reintroducing features
* Moving UI strings to resources file
* Restored functionality
* Add missing dlls
* Add FIle Locksmith to publish.cmd
* Rebase fixes
* Try updating nuget.config
* Fix copy-paste blunder
* Add File Locksmith UI for publishing
* Add .pubxml file in FileLocksmith
* Change build output folder
* Fix installer build issues
Remove old projects from solution so MSBuild doesn't build them.
Downgrade target framework to what most other projects are using.
Fix publishing profile and project runtimes.
Remove unused CsWinRT references.
* [CI] Add clear to nuget packages
* Fix module reference counting
* Fix nuget for release CI
* Fix version and signing
* Fix path for resources
* Fix incorrect results when running 2 instances
* Fix default nuget source
* Windows 10 icon and fallback for UI
* Code clean-up and spaces instead of tabs
* Add gif showcasing FL
* Add screenshot of File Locksmith for Settings
* Add new files to the installer
* Add OOBE page
* Showing selected paths in the header
* Tweak path list
* Added new, wider gif
* Add GPO
* Add some logs
* [CI]Get CommunityToolkit.Labs from BigPark feed
* [CI]Use azure package feed for Nuget in release
* [CI]Another try for the labs source
* Revert changes to feed
* Use RestoreAdditionalProjectSources
* Add tooltip to file list
* Change tooltip to not trim the lines
* Add Tips and tricks section mentioning elevated
* Add some more logs messages.
* Grammar fix
* Add to bug report tool
* Fix UI virtualization not working
* Disable virtualization to avoid crashes
* Get better virtualization
* Add dialog instead of tooltip to show list of items
* No results refresh icon is now a button too
* Use managed methods for handling processes
* Remove registry code from Ext.
* Support drives too
Co-authored-by: Niels Laute <niels.laute@live.nl>
Co-authored-by: Jaime Bernardo <jaime@janeasystems.com>
2022-10-28 21:51:21 +08:00
|
|
|
|
case "FileLocksmith": StartupPage = typeof(Views.FileLocksmithPage); break;
|
2022-04-20 04:00:28 +08:00
|
|
|
|
case "Run": StartupPage = typeof(Views.PowerLauncherPage); break;
|
|
|
|
|
case "ImageResizer": StartupPage = typeof(Views.ImageResizerPage); break;
|
|
|
|
|
case "KBM": StartupPage = typeof(Views.KeyboardManagerPage); break;
|
|
|
|
|
case "MouseUtils": StartupPage = typeof(Views.MouseUtilsPage); break;
|
|
|
|
|
case "PowerRename": StartupPage = typeof(Views.PowerRenamePage); break;
|
2022-09-01 03:43:23 +08:00
|
|
|
|
case "QuickAccent": StartupPage = typeof(Views.PowerAccentPage); break;
|
2022-04-20 04:00:28 +08:00
|
|
|
|
case "FileExplorer": StartupPage = typeof(Views.PowerPreviewPage); break;
|
|
|
|
|
case "ShortcutGuide": StartupPage = typeof(Views.ShortcutGuidePage); break;
|
2022-09-01 03:43:23 +08:00
|
|
|
|
case "TextExtractor": StartupPage = typeof(Views.PowerOcrPage); break;
|
2022-04-20 04:00:28 +08:00
|
|
|
|
case "VideoConference": StartupPage = typeof(Views.VideoConferencePage); break;
|
2022-08-27 07:17:20 +08:00
|
|
|
|
case "MeasureTool": StartupPage = typeof(Views.MeasureToolPage); break;
|
2022-10-13 19:05:43 +08:00
|
|
|
|
case "Hosts": StartupPage = typeof(Views.HostsPage); break;
|
Registry Preview: complete feature with integration with Settings and the Launcher UX (#23709)
* Initial src for Registry Preview
Initial collection of files
* Update MainWindow.Utilities.cs
fixing a few spelling items
* Update expect.txt
* Update App.xaml.cs
* Update MainWindow.Events.cs
* Update MainWindow.Utilities.cs
* Update MainWindow.xaml.cs
* Update expect.txt
* Update MainWindow.Events.cs
* Rename AddPreviewtoRegfile.reg to AddPreviewToRegfile.reg
* Rename RemovePreviewtoRegfile.reg to RemovePreviewToRegfile.reg
* Update Resources.resw
* Update MainWindow.xaml
* Turns on self-contained mode
Updates the csproj file to compile the app as self-contained .
Includes fixes for code that expected the app to be in an ApplicationContainer.
Updates WindowsAppSDK from 1.1.5 to 1.2.230118.102.
* Updated to align with StyleCop errors
Multiple changes across the codebase that now aligns with StyleCop guidelines.
Tested again after the changes, to make sure no new bugs crept in.
* Added comments for spell-checker
Unclear if this side step should be done or not, but the kxz comes from a GUID and the other three names are constants.
* Adding code-custom.dic
Comments didn't work; trying a dic file
* Added four new terms to expects.txt file
Cleaning up attempt to update the spell-checker with dic file and moved it to expects.txt file
* Adding one more string
Adding one more string for Spell-Check
* Adding back egfile
Seems this is needed.
* Correcting a variable name
Seems one of the variable names that changed globally got missed in a XAML file.
* Update project to be more PowerToys friendly
Tweaking names and output file name to fit better with PowerToys.
* First pass at integration into Settings and Launcher
This PR is not as large as it seems:
- RegistryPreview's source moved around to a "better" directory that makes it look like the whole app changed. It didn't. In fact, I opened it in Beyond Compare and there's not much difference in the RegistryPreview app.
- Added RegistryPreviewExt that produces a DLL that the Launcher can run the EXE
- Changes to Runner calls the Ext DLL rather than the app
- Settings UI got a bunch of changes to enable the Settings page for enable/disable across ViewModels, Views, and string tables.
Still todo:
- Add "Preview" to .REG files, when the app is enable (and remove it when disabled)
- Update the thumbnail-screenshot in the Settings page
- Add support for OOBE
* Update expect.txt
Added REGISTRYPREVIEWEXT for recent changes and corrected an alphabetic sorting error.
* Updating project file for Release mode
Build failed due to a bad Includes path in Release mode.
* Adds REG registration but breaks settings
This update will update the HKCU branch of the Registry for REG files: if the app in PowerToys is enabled, it adds a Preview item to the context menu of REG files and disabling in PowerToys removes the menu item.
While working on this, I noticed that the application settings were broken, after moving to a self-contained EXE: there must have been old settings from past builds, when it was still using containers and family names.
Added TODO's to add a new way to save settings, likely as JSON.
* Re-enabled app settings
Moved from using ApplicationDataContainer for app settings and now use simple JSON.
Also cleaned up handling the scenario where the Launcher send in the PID from PowerToys' main thread.
Fixed past spelling errors as well.
* Update RegistryPreview.png
Captured new screenshot.
* Integration into OOBE
Integrates new page for Registry Preview into OOBE process.
* Removing old comment and unneeded calls
Two bits of source removed as they aren't needed any longer
Removing a chunk of old commented out code that doesn't make sense anymore.
* Merging file from upstream
Updating some files due to three merge conflicts from upstream changes and a couple of other changes to keep up.
* Update .gitignore
Adding two vcxproj files that have local updates for atls.lib locations.
* Update Resources.resw
Fixing a typo that involved a missing closing tag.
* Fix analyzer warnings
* Fix CI build
* Fix ARM64 build
Project file cleanup
* Add to installer
* expect.txt
* Remove unneeded dll
* Update MainWindow.xaml.cs
Added check for current Theme and adjust TextBox Foreground accordingly.
* Update expect.txt
Cleaning up merge cruft.
* Revert wrong .gitignore changes
* Fix ARM installer
* Update Brushes for textBox to use Theme based versions
Finally figured out how to use the built-in, Theme-aware Brushes for the font colors in the onscreen textBox. Also have it aligning the font color for the hover state.
* Align configuration in PowerToys.sln
* [installer] Add missing files
* Fix bad merge
* Fixes for stefansjfw's review
Includes:
- two new strings for UX localization
- adds compatibility section for Windows 10
- fix to only track successful activations
- Removes two REG files that were there for examples
* Fixes from review from htcfreek
Updates:
- Fixed an issue where TextBox_TextChanged was firing when you simply opened a file.
- Added clamp to prevent files larger than 10MB from being opened.
- Added support in the UX to show Keys and Values that are deleted via the file
- Added support to specially handle Keys that start with - and Values that have =- in them (delete scenario)
- Changed AppBarButton icon for Edit from Rename to NewWindow
* Create deleted-folder32.png
* Added Registry Preview to GPO
* Update expect.txt
Updating spellchecker works
* Updating Size/Move code for better results
- Moved the size/move to the MainWindow layer
- Cleaned up the JSON settings handling to avoid an access denied on first run
* Improving text handling
Changed how special characters are parse, which helps with live entry.
* Updates to parsing and other fixes
- Renamed the value PNG for parity
- Added new error image
- Added check that values have " at start and finish.
- Added support for a new "ERROR" type for Values
- Fixed support for @ versus "@" in values
- Fixed bug where Save wasn't activating in all scernarios
* Fix signing and versioning
* Update src/settings-ui/Settings.UI/ViewModels/RegistryPreviewViewModel.cs
Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com>
* Apply suggestions from code review
Adds Launch button to the settings page.
Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com>
* Update Resources.resw
Adding strings for new launch button
* Adding new version for GPO
Moving to 0.69.0
* More parsing bug fixes
- Changes to look for [- instead of -[ for syntax deleting keys (fix for developer's mental hiccup)
- Moved [- to top of the decision making stack, as it needs to come before [
- Added new StripEscapedCharacters function for both sides of a Value line
- Fixed crashing bug for scenario where no Keys are parsed before a Value
* Bug fixes from most recent review.
- Dictionary will now be case insensitive when searching for keys
- Added tool tips (and strings) to the images of the Keys and Values
- Updated delete handling for Keys, so that only the leaf-most node gets marked as deleted; also stops the top most roots from being marked deleted.
* Tweaking for @=-
Forces the UX to take @=- and treat it as @="" since that's what Registry Editor would do.
* Removing unused usings
* Updates app description
* Update src/gpo/assets/PowerToys.admx
Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com>
* cleanup proj file
launch process only if module is enabled
add process to bugreport process list
* Add context menu icon
* Update src/modules/registrypreview/RegistryPreviewUI/MainWindow.Utilities.cs
Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com>
* Use modulesRegistry.h to apply/unapply registry changes
* Tweaked window settings
Moved the loading of the settings a little later in the initialization code, which gives more time for things to initialize.
* Update registry.h
Moving the definition out of the detail namespace to the registry name space to fix a compilation issue in RegistryPreviewExt.
* Unapply on creation
If module is disabled in settings.json, on startup reg entries should be unnaplied.
TODO: read m_enabled from settings file on creation
* Removing size/move main window
Added a TODO comment that responds to the size/position settings that are being saved out in the JSON blob on close as it doesn't always work on every PC, as the MainWindow initializes at different times.
* Change to always keep Save As active
No reason for this to be disabled, honestly.
---------
Co-authored-by: Clint Rutkas <clint@rutkas.com>
Co-authored-by: Stefan Markovic <stefan@janeasystems.com>
Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com>
Co-authored-by: Stefan Markovic <57057282+stefansjfw@users.noreply.github.com>
2023-03-27 21:21:46 +08:00
|
|
|
|
case "RegistryPreview": StartupPage = typeof(Views.RegistryPreviewPage); break;
|
2023-02-23 22:59:49 +08:00
|
|
|
|
case "PastePlain": StartupPage = typeof(Views.PastePlainPage); break;
|
2022-04-20 04:00:28 +08:00
|
|
|
|
default: Debug.Assert(false, "Unexpected SettingsWindow argument value"); break;
|
|
|
|
|
}
|
2023-02-03 23:10:14 +08:00
|
|
|
|
|
|
|
|
|
currentArgumentIndex++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int flyout_x = 0;
|
|
|
|
|
int flyout_y = 0;
|
|
|
|
|
if (containsFlyoutPosition)
|
|
|
|
|
{
|
|
|
|
|
// get the flyout position arguments
|
2023-03-16 22:51:31 +08:00
|
|
|
|
_ = int.TryParse(cmdArgs[currentArgumentIndex++], out flyout_x);
|
|
|
|
|
_ = int.TryParse(cmdArgs[currentArgumentIndex++], out flyout_y);
|
2022-04-20 04:00:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RunnerHelper.WaitForPowerToysRunner(PowerToysPID, () =>
|
|
|
|
|
{
|
|
|
|
|
Environment.Exit(0);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ipcmanager = new TwoWayPipeMessageIPCManaged(cmdArgs[(int)Arguments.SettingsPipeName], cmdArgs[(int)Arguments.PTPipeName], (string message) =>
|
|
|
|
|
{
|
|
|
|
|
if (IPCMessageReceivedCallback != null && message.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
IPCMessageReceivedCallback(message);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
ipcmanager.Start();
|
|
|
|
|
|
2023-01-31 07:00:11 +08:00
|
|
|
|
if (!ShowOobe && !ShowScoobe && !ShowFlyout)
|
2022-04-20 04:00:28 +08:00
|
|
|
|
{
|
2022-07-01 17:52:48 +08:00
|
|
|
|
settingsWindow = new MainWindow(isDark);
|
2022-04-20 04:00:28 +08:00
|
|
|
|
settingsWindow.Activate();
|
|
|
|
|
settingsWindow.NavigateToSection(StartupPage);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-05-19 21:12:59 +08:00
|
|
|
|
// Create the Settings window hidden so that it's fully initialized and
|
2022-04-20 04:00:28 +08:00
|
|
|
|
// it will be ready to receive the notification if the user opens
|
|
|
|
|
// the Settings from the tray icon.
|
2022-07-01 17:52:48 +08:00
|
|
|
|
settingsWindow = new MainWindow(isDark, true);
|
2022-05-19 21:12:59 +08:00
|
|
|
|
|
2022-04-20 04:00:28 +08:00
|
|
|
|
if (ShowOobe)
|
|
|
|
|
{
|
|
|
|
|
PowerToysTelemetry.Log.WriteEvent(new OobeStartedEvent());
|
2022-07-01 17:52:48 +08:00
|
|
|
|
OobeWindow oobeWindow = new OobeWindow(OOBE.Enums.PowerToysModules.Overview, isDark);
|
2022-04-20 04:00:28 +08:00
|
|
|
|
oobeWindow.Activate();
|
|
|
|
|
SetOobeWindow(oobeWindow);
|
|
|
|
|
}
|
|
|
|
|
else if (ShowScoobe)
|
|
|
|
|
{
|
|
|
|
|
PowerToysTelemetry.Log.WriteEvent(new ScoobeStartedEvent());
|
2022-07-01 17:52:48 +08:00
|
|
|
|
OobeWindow scoobeWindow = new OobeWindow(OOBE.Enums.PowerToysModules.WhatsNew, isDark);
|
2022-04-20 04:00:28 +08:00
|
|
|
|
scoobeWindow.Activate();
|
|
|
|
|
SetOobeWindow(scoobeWindow);
|
|
|
|
|
}
|
2023-01-31 07:00:11 +08:00
|
|
|
|
else if (ShowFlyout)
|
|
|
|
|
{
|
2023-02-03 23:10:14 +08:00
|
|
|
|
POINT? p = null;
|
|
|
|
|
if (containsFlyoutPosition)
|
|
|
|
|
{
|
|
|
|
|
p = new POINT(flyout_x, flyout_y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ShellPage.OpenFlyoutCallback(p);
|
2023-01-31 07:00:11 +08:00
|
|
|
|
}
|
2022-04-20 04:00:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// For debugging purposes
|
|
|
|
|
// Window is also needed to show MessageDialog
|
2022-07-01 17:52:48 +08:00
|
|
|
|
settingsWindow = new MainWindow(isDark);
|
2022-04-20 04:00:28 +08:00
|
|
|
|
settingsWindow.Activate();
|
2022-07-27 18:39:31 +08:00
|
|
|
|
|
|
|
|
|
#if !DEBUG
|
|
|
|
|
ShowMessageDialogAndExit("The application cannot be run as a standalone process. Please start the application through the runner.", "Forbidden");
|
|
|
|
|
#else
|
2022-04-20 04:00:28 +08:00
|
|
|
|
ShowMessageDialog("The application cannot be run as a standalone process. Please start the application through the runner.", "Forbidden");
|
2022-07-27 18:39:31 +08:00
|
|
|
|
#endif
|
2022-04-20 04:00:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-27 18:39:31 +08:00
|
|
|
|
#if !DEBUG
|
|
|
|
|
private async void ShowMessageDialogAndExit(string content, string title = null)
|
|
|
|
|
#else
|
2022-04-20 04:00:28 +08:00
|
|
|
|
private async void ShowMessageDialog(string content, string title = null)
|
2022-07-27 18:39:31 +08:00
|
|
|
|
#endif
|
2022-04-20 04:00:28 +08:00
|
|
|
|
{
|
|
|
|
|
await ShowDialogAsync(content, title);
|
2022-07-27 18:39:31 +08:00
|
|
|
|
#if !DEBUG
|
|
|
|
|
this.Exit();
|
|
|
|
|
#endif
|
2022-04-20 04:00:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Task<IUICommand> ShowDialogAsync(string content, string title = null)
|
|
|
|
|
{
|
|
|
|
|
var dialog = new MessageDialog(content, title ?? string.Empty);
|
|
|
|
|
var handle = NativeMethods.GetActiveWindow();
|
|
|
|
|
if (handle == IntPtr.Zero)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
InitializeWithWindow.Initialize(dialog, handle);
|
|
|
|
|
return dialog.ShowAsync().AsTask<IUICommand>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static TwoWayPipeMessageIPCManaged GetTwoWayIPCManager()
|
|
|
|
|
{
|
|
|
|
|
return ipcmanager;
|
2020-03-07 09:46:51 +08:00
|
|
|
|
}
|
2021-02-26 19:21:58 +08:00
|
|
|
|
|
2022-07-01 17:52:48 +08:00
|
|
|
|
public static string SelectedTheme()
|
|
|
|
|
{
|
|
|
|
|
return SettingsRepository<GeneralSettings>.GetInstance(settingsUtils).SettingsConfig.Theme.ToUpper(CultureInfo.InvariantCulture);
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-26 19:21:58 +08:00
|
|
|
|
public static bool IsDarkTheme()
|
|
|
|
|
{
|
2022-07-01 17:52:48 +08:00
|
|
|
|
var selectedTheme = SelectedTheme();
|
|
|
|
|
return selectedTheme == "DARK" || (selectedTheme == "SYSTEM" && ThemeHelpers.GetAppTheme() == AppTheme.Dark);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void HandleThemeChange()
|
|
|
|
|
{
|
2022-07-05 20:25:25 +08:00
|
|
|
|
try
|
2022-07-01 17:52:48 +08:00
|
|
|
|
{
|
2022-07-05 20:25:25 +08:00
|
|
|
|
var isDark = IsDarkTheme();
|
|
|
|
|
if (settingsWindow != null)
|
|
|
|
|
{
|
|
|
|
|
var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(settingsWindow);
|
|
|
|
|
ThemeHelpers.SetImmersiveDarkMode(hWnd, isDark);
|
|
|
|
|
}
|
2022-07-01 17:52:48 +08:00
|
|
|
|
|
2022-07-05 20:25:25 +08:00
|
|
|
|
if (oobeWindow != null)
|
|
|
|
|
{
|
|
|
|
|
var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(oobeWindow);
|
|
|
|
|
ThemeHelpers.SetImmersiveDarkMode(hWnd, isDark);
|
|
|
|
|
}
|
2022-07-01 17:52:48 +08:00
|
|
|
|
|
2022-07-05 20:25:25 +08:00
|
|
|
|
var selectedTheme = SelectedTheme();
|
|
|
|
|
if (selectedTheme == "SYSTEM")
|
|
|
|
|
{
|
|
|
|
|
themeListener = new ThemeListener();
|
|
|
|
|
themeListener.ThemeChanged += (_) => HandleThemeChange();
|
|
|
|
|
}
|
|
|
|
|
else if (themeListener != null)
|
|
|
|
|
{
|
|
|
|
|
themeListener.Dispose();
|
|
|
|
|
themeListener = null;
|
|
|
|
|
}
|
2022-07-01 17:52:48 +08:00
|
|
|
|
}
|
2022-07-05 20:25:25 +08:00
|
|
|
|
catch (Exception e)
|
2022-07-01 17:52:48 +08:00
|
|
|
|
{
|
2022-07-05 20:25:25 +08:00
|
|
|
|
if (!loggedImmersiveDarkException)
|
|
|
|
|
{
|
|
|
|
|
Logger.LogError($"HandleThemeChange exception. Please install .NET 4.", e);
|
|
|
|
|
loggedImmersiveDarkException = true;
|
|
|
|
|
}
|
2022-07-01 17:52:48 +08:00
|
|
|
|
}
|
2021-02-26 19:21:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static ISettingsUtils settingsUtils = new SettingsUtils();
|
2022-04-20 04:00:28 +08:00
|
|
|
|
|
|
|
|
|
private static MainWindow settingsWindow;
|
|
|
|
|
private static OobeWindow oobeWindow;
|
2023-01-31 07:00:11 +08:00
|
|
|
|
private static FlyoutWindow flyoutWindow;
|
2022-07-01 17:52:48 +08:00
|
|
|
|
private static ThemeListener themeListener;
|
2022-04-20 04:00:28 +08:00
|
|
|
|
|
|
|
|
|
public static void ClearSettingsWindow()
|
|
|
|
|
{
|
|
|
|
|
settingsWindow = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static MainWindow GetSettingsWindow()
|
|
|
|
|
{
|
|
|
|
|
return settingsWindow;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static OobeWindow GetOobeWindow()
|
|
|
|
|
{
|
|
|
|
|
return oobeWindow;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-31 07:00:11 +08:00
|
|
|
|
public static FlyoutWindow GetFlyoutWindow()
|
|
|
|
|
{
|
|
|
|
|
return flyoutWindow;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-20 04:00:28 +08:00
|
|
|
|
public static void SetOobeWindow(OobeWindow window)
|
|
|
|
|
{
|
|
|
|
|
oobeWindow = window;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-31 07:00:11 +08:00
|
|
|
|
public static void SetFlyoutWindow(FlyoutWindow window)
|
|
|
|
|
{
|
|
|
|
|
flyoutWindow = window;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-20 04:00:28 +08:00
|
|
|
|
public static void ClearOobeWindow()
|
|
|
|
|
{
|
|
|
|
|
oobeWindow = null;
|
|
|
|
|
}
|
2023-01-31 07:00:11 +08:00
|
|
|
|
|
|
|
|
|
public static void ClearFlyoutWindow()
|
|
|
|
|
{
|
|
|
|
|
flyoutWindow = null;
|
|
|
|
|
}
|
2020-03-07 09:46:51 +08:00
|
|
|
|
}
|
|
|
|
|
}
|