コード例 #1
0
        private async void TryRegisterForStartup()
        {
            try
            {
#if SQUIRREL
                var startupManager = new StartupManager("Roamit Cloud Clipboard");
                startupManager.AddApplicationToCurrentUserStartup();
#else
                var startupTask = await Windows.ApplicationModel.StartupTask.GetAsync("RoamitStartupTask");

                if (startupTask.State != Windows.ApplicationModel.StartupTaskState.Enabled)
                {
                    var state = await startupTask.RequestEnableAsync();

                    if (state == Windows.ApplicationModel.StartupTaskState.DisabledByUser)
                    {
                        notifyIcon?.ShowBalloonTip(int.MaxValue, "Roamit is not allowed to run on startup",
                                                   "For best universal clipboard experience, please allow Roamit to run on startup from Task Manager", ToolTipIcon.Warning);
                    }
                }
#endif
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed to register program to run at startup.");
#if !SQUIRREL
                notifyIcon?.ShowBalloonTip(int.MaxValue, "Failed to register Roamit to run on startup",
                                           ex.Message, ToolTipIcon.Warning);
#endif
            }
        }