mirror of
https://github.com/microsoft/terminal.git
synced 2026-07-08 17:46:05 +00:00
Before we had a Settings UI, we added support for a setting called `startOnUserLogin`. It was a boolean, and on startup we would try to yeet the value of that setting into the Windows API responsible for registering us as a startup task. Unfortunately, we failed to take into account a few things. - Startup tasks can be independently controlled by the user in Windows Settings or by an enterprise using enterprise policy - This control is not limited to *disabling* the task; it also supports enabling it! Users could enable our startup task outside the settings file and we would never know it. We would load up, see that `startOnUserLogin` was `false`, and go disable the task again. 🤦 Conversely, if the user disables our task outside the app _we can never enable it from inside the app._ If an enterprise has configured it either direction, we can't change it either. The best way forward is to remove it from our settings model and only ever interact with the Windows API. This pull request replaces `startOnUserLogin` with a rich settings experience that will reflect the current and final state of the task as configured through Windows. Terminal will enable it if it can and display a message if it can't. My first attempt at this PR (which you can read in the commit history) made us try harder to sync the state between the settings model and the OS; we would propagate the disabled state back to the user setting when the task was disabled in the OS or if we failed to enable it when the user asked for it. That was fragile and didn't support reporting the state in the settings UI, and it seems like it would be confusing for a setting to silently turn itself back off anyway... Closes #12564
82 lines
4.0 KiB
C++
82 lines
4.0 KiB
C++
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the MIT license.
|
|
|
|
#pragma once
|
|
|
|
#include "LaunchViewModel.g.h"
|
|
#include "ViewModelHelpers.h"
|
|
#include "Utils.h"
|
|
#include <cppwinrt_utils.h>
|
|
|
|
namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
|
{
|
|
struct LaunchViewModel : LaunchViewModelT<LaunchViewModel>, ViewModelHelper<LaunchViewModel>
|
|
{
|
|
public:
|
|
LaunchViewModel(Model::CascadiaSettings settings);
|
|
|
|
// LanguageDisplayConverter maps the given BCP 47 tag to a localized string.
|
|
// For instance "en-US" produces "English (United States)", while "de-DE" produces
|
|
// "Deutsch (Deutschland)". This works independently of the user's locale.
|
|
static winrt::hstring LanguageDisplayConverter(const winrt::hstring& tag);
|
|
|
|
bool LanguageSelectorAvailable();
|
|
winrt::Windows::Foundation::Collections::IObservableVector<winrt::hstring> LanguageList();
|
|
winrt::Windows::Foundation::IInspectable CurrentLanguage();
|
|
void CurrentLanguage(const winrt::Windows::Foundation::IInspectable& tag);
|
|
|
|
winrt::hstring LaunchSizeCurrentValue() const;
|
|
winrt::hstring LaunchParametersCurrentValue();
|
|
double InitialPosX();
|
|
double InitialPosY();
|
|
void InitialPosX(double xCoord);
|
|
void InitialPosY(double yCoord);
|
|
void UseDefaultLaunchPosition(bool useDefaultPosition);
|
|
bool UseDefaultLaunchPosition();
|
|
|
|
IInspectable CurrentDefaultProfile();
|
|
void CurrentDefaultProfile(const IInspectable& value);
|
|
winrt::Windows::Foundation::Collections::IObservableVector<Model::Profile> DefaultProfiles() const;
|
|
|
|
IInspectable CurrentDefaultTerminal();
|
|
void CurrentDefaultTerminal(const IInspectable& value);
|
|
winrt::Windows::Foundation::Collections::IObservableVector<Model::DefaultTerminal> DefaultTerminals() const;
|
|
|
|
// We cannot use the macro for LaunchMode because we want to insert an event into the setter
|
|
winrt::Windows::Foundation::IInspectable CurrentLaunchMode();
|
|
void CurrentLaunchMode(const winrt::Windows::Foundation::IInspectable& enumEntry);
|
|
winrt::Windows::Foundation::Collections::IObservableVector<winrt::Microsoft::Terminal::Settings::Editor::EnumEntry> LaunchModeList();
|
|
|
|
GETSET_BINDABLE_ENUM_SETTING(DefaultInputScope, winrt::Microsoft::Terminal::Control::DefaultInputScope, _Settings.GlobalSettings().DefaultInputScope);
|
|
GETSET_BINDABLE_ENUM_SETTING(FirstWindowPreference, Model::FirstWindowPreference, _Settings.GlobalSettings().FirstWindowPreference);
|
|
GETSET_BINDABLE_ENUM_SETTING(WindowingBehavior, Model::WindowingMode, _Settings.GlobalSettings().WindowingBehavior);
|
|
|
|
PERMANENT_OBSERVABLE_PROJECTED_SETTING(_Settings.GlobalSettings(), CenterOnLaunch);
|
|
PERMANENT_OBSERVABLE_PROJECTED_SETTING(_Settings.GlobalSettings(), InitialRows);
|
|
PERMANENT_OBSERVABLE_PROJECTED_SETTING(_Settings.GlobalSettings(), InitialCols);
|
|
|
|
bool StartOnUserLoginAvailable();
|
|
safe_void_coroutine PrepareStartOnUserLoginSettings();
|
|
bool StartOnUserLoginConfigurable();
|
|
winrt::hstring StartOnUserLoginStatefulHelpText();
|
|
bool StartOnUserLogin();
|
|
safe_void_coroutine StartOnUserLogin(bool enable);
|
|
|
|
private:
|
|
Model::CascadiaSettings _Settings;
|
|
winrt::Windows::Foundation::Collections::IObservableVector<winrt::hstring> _languageList;
|
|
winrt::Windows::Foundation::IInspectable _currentLanguage;
|
|
bool _useDefaultLaunchPosition;
|
|
|
|
winrt::Windows::Foundation::Collections::IObservableVector<winrt::Microsoft::Terminal::Settings::Editor::EnumEntry> _LaunchModeList;
|
|
winrt::Windows::Foundation::Collections::IMap<Model::LaunchMode, winrt::Microsoft::Terminal::Settings::Editor::EnumEntry> _LaunchModeMap;
|
|
|
|
winrt::Windows::ApplicationModel::StartupTask _startOnUserLoginTask{ nullptr };
|
|
};
|
|
};
|
|
|
|
namespace winrt::Microsoft::Terminal::Settings::Editor::factory_implementation
|
|
{
|
|
BASIC_FACTORY(LaunchViewModel);
|
|
}
|