Exemplo n.º 1
0
        public async Task LoadState()
        {
            var task = await StartupTask.GetAsync("StickyNotes");

            switch (task.State)
            {
            case StartupTaskState.Disabled:
                // 禁用狀態
                BtnSetState.Content   = "啟用";
                BtnSetState.IsEnabled = true;
                break;

            case StartupTaskState.DisabledByPolicy:
                // 由管理員或組策略禁用
                BtnSetState.Content   = "被系統策略禁用";
                BtnSetState.IsEnabled = false;
                break;

            case StartupTaskState.DisabledByUser:
                // 由用户手工禁用
                BtnSetState.Content   = "被用户禁用";
                BtnSetState.IsEnabled = false;
                break;

            case StartupTaskState.Enabled:
                // 當前狀態為已啟用
                BtnSetState.Content   = "已啟用";
                BtnSetState.IsEnabled = false;
                break;
            }
        }
        public async Task <bool> Set(bool enabled)
        {
#pragma warning disable UWP003 // UWP-only
            var startupTask = await StartupTask.GetAsync("EyeNurse");

#pragma warning restore UWP003 // UWP-only
            if (!enabled && startupTask.State == StartupTaskState.Enabled)
            {
                startupTask.Disable();
                return(true);
            }
            else if (enabled)
            {
                var state = await startupTask.RequestEnableAsync();

                switch (state)
                {
                case StartupTaskState.DisabledByUser:
                    return(false);

                case StartupTaskState.Enabled:
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 3
0
        private async void StartupButton_Click(object sender, RoutedEventArgs e)
        {
            StartupTask startupTask = await StartupTask.GetAsync("AmethystWindowsId");

            StartupStatus.Text = startupTask.State.ToString();
            switch (startupTask.State)
            {
            case StartupTaskState.Disabled:
                // Task is disabled but can be enabled.
                StartupTaskState newState = await startupTask.RequestEnableAsync();

                StartupStatus.Text = newState.ToString();
                break;

            case StartupTaskState.DisabledByUser:
                // Task is disabled and user must enable it manually.
                MessageDialog disabledDialog = new MessageDialog(
                    "You can enable this in the Startup tab in Task Manager.");
                await disabledDialog.ShowAsync();

                break;

            case StartupTaskState.DisabledByPolicy:
                MessageDialog policyDialog = new MessageDialog(
                    "You do not have rights to start this app at login.");
                await policyDialog.ShowAsync();

                break;

            case StartupTaskState.Enabled:
                break;
            }
        }
Exemplo n.º 4
0
 private async Task AcquirePackageTask()
 {
     if (packageTask == null)
     {
         packageTask = (await StartupTask.GetForCurrentPackageAsync())[StartupTargetIndex];
     }
 }
Exemplo n.º 5
0
    private async void setStartupCheckBox()
    {
        StartupTask startupTask = await StartupTask.GetAsync("StartCaffeinated");

        Debug.WriteLine("Startup is " + startupTask.State.ToString());

        switch (startupTask.State)
        {
        case StartupTaskState.Disabled:
            // Task is disabled but can be enabled.
            StartupChkBox.Checked = false;
            break;

        case StartupTaskState.DisabledByUser:
            // Task is disabled and user must enable it manually.
            StartupChkBox.Checked = false;
            StartupChkBox.Enabled = false;

            StartupChkBox.Text += "\nDisabled in Task Manager";
            break;

        case StartupTaskState.Enabled:
            StartupChkBox.Checked = true;
            break;
        }
    }
Exemplo n.º 6
0
        private async Task CheckStartupTaskAccessAsync()
        {
            StartupTask startupTask = await StartupTask.GetAsync("ToastPusherStartupTask");

            startupTaskStatusText.Text = startupTask.State.ToString();
            switch (startupTask.State)
            {
            case StartupTaskState.Disabled:
                // Task is disabled but can be enabled.
                StartupTaskState newState = await startupTask.RequestEnableAsync();

                startupTaskStatusText.Text = newState.ToString();
                Debug.WriteLine("Request to enable startup, result = {0}", newState);
                break;

            case StartupTaskState.DisabledByUser:
                // Task is disabled and user must enable it manually.
                startupTaskStatusText.Text = "Was actively disabled";
                break;

            case StartupTaskState.DisabledByPolicy:
                Debug.WriteLine(
                    "Startup disabled by group policy, or not supported on this device");
                break;

            case StartupTaskState.Enabled:
                Debug.WriteLine("Startup is enabled.");
                break;
            }
        }
Exemplo n.º 7
0
        private async void AutoStartSwitch_Toggled(object sender, RoutedEventArgs e)
        {
            if (AutoStartSwitch != null)
            {
                if (AutoStartSwitch.IsOn == true)
                {
                    localSettings.Values["AutoStart"] = "1";
                    var task = await StartupTask.GetAsync("AppAutoRun");

                    if (task.State == StartupTaskState.Disabled)
                    {
                        await task.RequestEnableAsync();
                    }

                    // 重新加载状态
                    await LoadState();
                }
                else
                {
                    localSettings.Values["AutoStart"] = "0";
                    var task = await StartupTask.GetAsync("AppAutoRun");

                    task.Disable();
                }
            }
            await LoadState();
        }
Exemplo n.º 8
0
        /// <summary>
        /// Occurs when the page has loaded
        /// </summary>
        /// <param name="sender">The sender</param>
        /// <param name="e">The arguments</param>
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            var packageVersion = Package.Current.Id.Version;

            VersionNumberText.Text = $"{packageVersion.Major}.{packageVersion.Minor}.{packageVersion.Build}";

            var asusStartupTask = await StartupTask.GetAsync("Asus");

            var corsairStartupTask = await StartupTask.GetAsync("Corsair");

            if (asusStartupTask.State == StartupTaskState.Enabled)
            {
                AsusToggleSwitch.IsOn = true;
            }

            if (corsairStartupTask.State == StartupTaskState.Enabled)
            {
                CorsairToggleSwitch.IsOn = true;
            }

            var debugMode = ApplicationData.Current.LocalSettings.Values["DebugMode"];

            if (debugMode != null && (bool)debugMode)
            {
                DebugToggleSwitch.IsOn = (bool)debugMode;
            }

            _pageLoaded = true;
        }
Exemplo n.º 9
0
        private async Task RegisterStartupAsync()
        {
            StartupTask startupTask = await StartupTask.GetAsync("DuckDNSUpdaterStartup"); // Pass the task ID you specified in the appxmanifest file

            switch (startupTask.State)
            {
            case StartupTaskState.Disabled:
                // Task is disabled but can be enabled.
                StartupTaskState newState = await startupTask.RequestEnableAsync();     // ensure that you are on a UI thread when you call RequestEnableAsync()

                Debug.WriteLine("Request to enable startup, result = {0}", newState);
                break;

            case StartupTaskState.DisabledByUser:
                // Task is disabled and user must enable it manually.
                MessageDialog dialog = new MessageDialog(
                    "You have disabled this app's ability to run " +
                    "as soon as you sign in, but if you change your mind, " +
                    "you can enable this in the Startup tab in Task Manager.",
                    "Duck DNS Updater");
                await dialog.ShowAsync();

                break;

            case StartupTaskState.DisabledByPolicy:
                Debug.WriteLine("Startup disabled by group policy, or not supported on this device");
                break;

            case StartupTaskState.Enabled:
                Debug.WriteLine("Startup is enabled.");
                break;
            }
        }
Exemplo n.º 10
0
        public Startup(string name)
        {
#if APPX
            this._task = GetStartupTask();
#endif
            this._path = GetStartupFilePath(name);
        }
Exemplo n.º 11
0
        private void InitializeContextMenus()
        {
            toolStripMenuItem2.Text = Properties.Resources.AutoStartText;
            toolStripMenuItem1.Text = Properties.Resources.ExitText;

            contextMenuStrip1.Opening += async(sender, e) =>
            {
                var startupTask = await StartupTask.GetAsync("WinQuickLookTask");

                toolStripMenuItem2.Checked = startupTask.State == StartupTaskState.Enabled;
            };

            toolStripMenuItem1.Click += (sender, e) => Application.Current.Shutdown();
            toolStripMenuItem2.Click += async(sender, e) =>
            {
                var startupTask = await StartupTask.GetAsync("WinQuickLookTask");

                if (startupTask.State == StartupTaskState.Enabled)
                {
                    startupTask.Disable();

                    toolStripMenuItem2.Checked = false;
                }
                else
                {
                    var state = await startupTask.RequestEnableAsync();

                    toolStripMenuItem2.Checked = state == StartupTaskState.Enabled;
                }
            };
        }
Exemplo n.º 12
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="serverPort">Port to start server on</param>
 internal WebServer(StartupTask st, int serverPort)
 {
     _startupTask  = st;
     _webhelper    = new WebHelper();
     _devices      = new Devices();
     _listener     = new StreamSocketListener();
     _webApiHelper = new WebApiHelper();
     _port         = serverPort;
     _listener.ConnectionReceived += (s, e) =>
     {
         try
         {
             if (_startupTask.IsClosing)
             {
                 _listener.CancelIOAsync().GetResults();
             }
             else
             {
                 // Process incoming request
                 processRequestAsync(e.Socket);
             }
         }
         catch (Exception ex)
         {
             Debug.WriteLine("Exception in StreamSocketListener.ConnectionReceived(): " + ex.Message);
         }
     };
 }
Exemplo n.º 13
0
        // ToggleSwitchを切り替えたときのイベントハンドラー
        private async void AutoStartupToggle_Toggled(object sender, RoutedEventArgs e)
        {
            if (!_isSetupCompleted)
            {
                return; // 初期化中にコードからトグルを切り替えた
            }
            // StartupTaskオブジェクトを得る
            StartupTask startupTask = await StartupTask.GetAsync(StartUpTaskId);

            if ((sender as ToggleSwitch).IsOn)
            {
                // 自動起動を要求する
                StartupTaskState state = await startupTask.RequestEnableAsync();

                // 返されたstateを見て、実際に自動起動が有効になったかどうか判定できる
            }
            else
            {
                // 自動起動をOFFにする
                startupTask.Disable();
            }

            // 実際の状態がトグルと異なっているかもしれないので、再度初期化する
            SetupAutoStartupToggle();
        }
Exemplo n.º 14
0
        public SettingsWindow()
        {
            InitializeComponent();
            LowColor.Background                = new SolidColorBrush(ToMediaColor(Default.LowColor));
            CriticalColor.Background           = new SolidColorBrush(ToMediaColor(Default.CriticalColor));
            ChargingColor.Background           = new SolidColorBrush(ToMediaColor(Default.ChargingColor));
            CriticalNotification.IsChecked     = Default.CriticalNotification;
            LowNotification.IsChecked          = Default.LowNotification;
            HighNotification.IsChecked         = Default.HighNotification;
            FullNotification.IsChecked         = Default.FullNotification;
            HighNotificationValue.SelectedItem = Default.HighNotificationValue;
            RefreshSeconds.SelectedItem        = Default.RefreshSeconds;
            RegisterEventHandling();
            new Action(async() =>
            {
                try
                {
                    AutoStart.IsChecked = (_startupTask = await StartupTask.GetAsync(Program.Id)).State ==
                                          StartupTaskState.Enabled;
                }
                catch (Exception e)
                {
                    AutoStart.IsEnabled = true;
                    AutoStart.Cursor    = Cursors.No;
                    AutoStart.Opacity   = 0.3;
                    AutoStart.ToolTip   = "Auto start requires this app to run as UWP.\r\n\r\n" + e.Message;
                    return;
                }

                RegisterAutoStartEventHandling();
                AutoStart.IsEnabled = true;
            })();
        }
Exemplo n.º 15
0
        public async Task LoadState()
        {
            var task = await StartupTask.GetAsync("LovelyMother.UWP");

            this.tbState.Text = $"Status: {task.State}";
            switch (task.State)
            {
            case StartupTaskState.Disabled:
                // 禁用状态
                this.btnSetStatet.Content   = "启用";
                this.btnSetStatet.IsEnabled = true;
                break;

            case StartupTaskState.DisabledByPolicy:
                // 由管理员或组策略禁用
                this.btnSetStatet.Content   = "被系统策略禁用";
                this.btnSetStatet.IsEnabled = false;
                break;

            case StartupTaskState.DisabledByUser:
                // 由用户手工禁用
                this.btnSetStatet.Content   = "被用户禁用";
                this.btnSetStatet.IsEnabled = false;
                break;

            case StartupTaskState.Enabled:
                // 当前状态为已启用
                this.btnSetStatet.Content   = "已启用";
                this.btnSetStatet.IsEnabled = false;
                break;
            }
        }
Exemplo n.º 16
0
        public async Task <StartupTaskState> AskForStartupTaskAccessAsync()
        {
            StartupTask startupTask = await StartupTask.GetAsync("ToastPusherStartupTask");

            startupTaskStatusText.Text = startupTask.State.ToString();
            StartupTaskState newState = await startupTask.RequestEnableAsync();

            switch (startupTask.State)
            {
            case StartupTaskState.DisabledByUser:
                // Task is disabled and user must enable it manually.
                var dialog = new MessageDialog(
                    "Since you explicitely disabled launching Toast Pusher on startup, " +
                    "you can now only re-activate it manually via the \"Startup\" tab in Task Manager due " +
                    "to a Windows policy. You will have to restart the app in order to see the changes take effect.",
                    "Startup must be enabled in Task Manager");
                await dialog.ShowAsync();

                break;

            case StartupTaskState.DisabledByPolicy:
                var dialog2 = new MessageDialog(
                    "You cannot activate startup, because it was disabled by a system policy. You will have to ask your administrator to enable it.",
                    "Startup was disabled by policy");
                await dialog2.ShowAsync();

                break;

            case StartupTaskState.Enabled:
                Debug.WriteLine("Startup is already enabled.");
                break;
            }
            startupTaskStatusText.Text = newState.ToString();
            return(startupTask.State);
        }
Exemplo n.º 17
0
        private async void AppOptionsPage_Loaded(object sender, RoutedEventArgs e)
        {
            StartupTask startupTask = await StartupTask.GetAsync("eSheepId");

            switch (startupTask.State)
            {
            case StartupTaskState.Disabled:
                // Task is disabled but can be enabled.
                autostartToggle.IsEnabled = true;
                taskText.Visibility       = Visibility.Collapsed;
                break;

            case StartupTaskState.DisabledByUser:
                autostartToggle.IsOn      = false;
                autostartToggle.IsEnabled = false;
                taskText.Visibility       = Visibility.Visible;
                break;

            case StartupTaskState.DisabledByPolicy:
                taskText.Visibility           = Visibility.Visible;
                autostartToggle.IsEnabled     = false;
                (sender as ToggleSwitch).IsOn = false;
                break;

            case StartupTaskState.Enabled:
                autostartToggle.IsOn      = true;
                autostartToggle.IsEnabled = false;
                Debug.WriteLine("Startup is enabled.");
                break;
            }

            autostartToggle.Toggled += AutostartToggle_Toggled;
        }
Exemplo n.º 18
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            StartupTask startupTask = await StartupTask.GetAsync("MyStartupId");

            switch (startupTask.State)
            {
            case StartupTaskState.Disabled:
                // Task is disabled but can be enabled.
                StartupTaskState newState = await startupTask.RequestEnableAsync();

                Debug.WriteLine("Request to enable startup, result = {0}", newState);
                break;

            case StartupTaskState.DisabledByUser:
                // Task is disabled and user must enable it manually.
                MessageDialog dialog = new MessageDialog(
                    "I know you don't want this app to run " +
                    "as soon as you sign in, but if you change your mind, " +
                    "you can enable this in the Startup tab in Task Manager.",
                    "TestStartup");
                await dialog.ShowAsync();

                break;

            case StartupTaskState.DisabledByPolicy:
                Debug.WriteLine(
                    "Startup disabled by group policy, or not supported on this device");
                break;

            case StartupTaskState.Enabled:
                Debug.WriteLine("Startup is enabled.");
                break;
            }
        }
Exemplo n.º 19
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            StartupTask.Register(services);

            services.AddRawRabbit(config => config.AddJsonFile("rabbitmq.json"),
                ioc => { ioc.AddSingleton<IConfigurationEvaluator, AttributeConfigEvaluator>(); });

            var token = this.Configuration.GetSection("Jwk").Get<JsonWebKey>();

            services.AddAuthorization(conf =>
            {
                conf.AddPolicy("Read", pol => pol.RequireClaim("authorities", "FOO_READ"));
                conf.AddPolicy("Write", pol => pol.RequireClaim("authorities", "FOO_WRITE"));
            })
            .AddAuthentication(conf =>
            {
                conf.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                conf.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(conf =>
            {
                conf.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateAudience = false,
                    ValidateIssuer = false,
                    IssuerSigningKey = token
                };
            });

            this._applicationContainer = Bootstrapper.SetupContainer(services);
            this._bus = Bootstrapper.SetupMessageSubscriptions(services, this._applicationContainer);
            Bootstrapper.CreateIndexes(this._applicationContainer);
        }
        public async Task <bool> Check()
        {
            try
            {
                bool result = false;
#pragma warning disable UWP003 // UWP-only
                var startupTask = await StartupTask.GetAsync("EyeNurse");

#pragma warning restore UWP003 // UWP-only
                switch (startupTask.State)
                {
                case StartupTaskState.Disabled:
                    result = false;
                    break;

                case StartupTaskState.DisabledByUser:
                    result = false;
                    break;

                case StartupTaskState.Enabled:
                    result = true;
                    break;
                }
                return(result);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemplo n.º 21
0
        private async void btnStartup_Click(object sender, RoutedEventArgs e)
        {
            // Сначала проверяем состояние автозапуска. Получаем его в переменную startupTask
            StartupTask startupTask = await StartupTask.GetAsync("FallCreatorsAppId");

            switch (startupTask.State)
            {
            case StartupTaskState.Disabled:
                // В случае если автозапуск просто выключен пробуем его включить
                StartupTaskState newState = await startupTask.RequestEnableAsync();

                // в переменной newState будет получен результат того было ли включение автозапуска благополучным
                break;

            case StartupTaskState.DisabledByUser:
                // Здесь автоматически включить автозапуск не получится. Раз выключено пользователем, то значит он автоматически его не хочет включать…
                break;

            case StartupTaskState.DisabledByPolicy:
                // автозапуск выключен групповыми политиками или не поддерживается устройством
                break;

            case StartupTaskState.Enabled:
                // все уже включено :)
                break;
            }
        }
Exemplo n.º 22
0
        private void RestartPlugin()
        {
            // re-executes the startup task to reinitialize the HTML filter
            var startUpTask = new StartupTask();

            startUpTask.Execute();
        }
Exemplo n.º 23
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            StartupTask startupTask = await StartupTask.GetAsync("MyStartupId");

            switch (startupTask.State)
            {
            case StartupTaskState.Disabled:
                // Task is disabled but can be enabled.
                StartupTaskState newState = await startupTask.RequestEnableAsync();

                break;

            case StartupTaskState.DisabledByUser:
                // Task is disabled and user must enable it manually.
                MessageDialog dialog = new MessageDialog(
                    "I know you don't want this app to run " +
                    "as soon as you sign in, but if you change your mind, " +
                    "you can enable this in the Startup tab in Task Manager.",
                    "TestStartup");
                await dialog.ShowAsync();

                break;

            case StartupTaskState.DisabledByPolicy:
                break;

            case StartupTaskState.Enabled:
                break;
            }
        }
Exemplo n.º 24
0
        public async Task <StartupTaskStatus> EnableStartupTask()
        {
            var startupTask = await StartupTask.GetAsync(StartupTaskname);

            var newState = await startupTask.RequestEnableAsync();

            return(ConvertState(newState));
        }
        public async Task <StartupTaskStatus> EnableStartupTaskAsync()
        {
            var startupTask = await StartupTask.GetAsync(StartupTaskName);

            var newState = await startupTask.RequestEnableAsync();

            return(ToStartupTaskStatus(newState));
        }
Exemplo n.º 26
0
 public StartupTask(StartupTask dependancy)
 {
     if (dependancy != null)
     {
         m_dependancies    = new StartupTask[1];
         m_dependancies[0] = dependancy;
     }
 }
Exemplo n.º 27
0
        public async Task <StartupTaskState> DisableStartupTask()
        {
            StartupTask startupTask = await StartupTask.GetAsync("ToastPusherStartupTask");

            startupTask.Disable();
            Debug.WriteLine("disabled startup task");
            startupTaskStatusText.Text = StartupTaskState.Disabled.ToString();
            return(StartupTaskState.Disabled);
        }
Exemplo n.º 28
0
        private async void AppOptionsPage_Loaded(object sender, RoutedEventArgs e)
        {
            StartupTask startupTask = null;

            try
            {
                startupTask = await StartupTask.GetAsync("eSheepId");
            }
            catch (Exception)
            {
                startupTask = null;
            }

            if (startupTask == null)
            {
                MessageDialog dialog = new MessageDialog(
                    "Unable to get application Id",
                    "eSheep Id");
                await dialog.ShowAsync();

                return;
            }

            switch (startupTask.State)
            {
            case StartupTaskState.Disabled:
                // Task is disabled but can be enabled.
                autostartToggle.IsEnabled = true;
                taskText.Visibility       = Visibility.Collapsed;
                break;

            case StartupTaskState.DisabledByUser:
                autostartToggle.IsOn      = false;
                autostartToggle.IsEnabled = false;
                taskText.Visibility       = Visibility.Visible;
                break;

            case StartupTaskState.DisabledByPolicy:
                taskText.Visibility           = Visibility.Visible;
                autostartToggle.IsEnabled     = false;
                (sender as ToggleSwitch).IsOn = false;
                break;

            case StartupTaskState.Enabled:
                autostartToggle.IsOn      = true;
                autostartToggle.IsEnabled = false;
                Debug.WriteLine("Startup is enabled.");
                break;
            }

            petsQuantitySlider.Value = App.MyData.GetAutoStartPets();

            petsQuantitySlider.Header = petsQuantitySlider.Value;

            autostartToggle.Toggled         += AutostartToggle_Toggled;
            petsQuantitySlider.ValueChanged += PetsQuantitySlider_ValueChanged;
        }
Exemplo n.º 29
0
        private static StartupTask GetStartupTask(string taskId)
        {
            if (string.IsNullOrWhiteSpace(taskId))
            {
                throw new ArgumentNullException(nameof(taskId));
            }

            return(StartupTask.GetAsync(taskId).AsTask().Result);
        }
Exemplo n.º 30
0
        public static async Task <bool> GetRunAtStartupEnabled()
        {
            try
            {
                StartupTask startupTask = await StartupTask.GetAsync(StartupId);

                return(startupTask.State == StartupTaskState.Enabled);
            } catch { return(true); }
        }
Exemplo n.º 31
0
 public Startup(string name)
 {
     if (Platform.IsUwp)
     {
         this._task = GetStartupTask();
     }
     else
     {
         this._path = GetStartupFilePath(name);
     }
 }