Esempio n. 1
0
        public static bool SetAppMode(PreferredAppMode appMode)
        {
            var build = Environment.OSVersion.Version.Build;

            if (build >= 18362)
            {
                // memo: Workaround for the problem of not switching from dark theme to light theme.
                if (appMode == PreferredAppMode.APPMODE_DEFAULT || appMode == PreferredAppMode.APPMODE_FORCELIGHT)
                {
                    UxTheme.SetPreferredAppMode(PreferredAppMode.APPMODE_ALLOWDARK);
                    UxTheme.RefreshImmersiveColorPolicyState();
                }

                var ret = UxTheme.SetPreferredAppMode(appMode) == appMode;
                UxTheme.RefreshImmersiveColorPolicyState();
                return(ret);
            }
            else if (build >= 17763)
            {
                if (appMode == PreferredAppMode.APPMODE_DEFAULT || appMode == PreferredAppMode.APPMODE_FORCELIGHT)
                {
                    return(UxTheme.AllowDarkModeForApp(false));
                }
                else
                {
                    return(UxTheme.AllowDarkModeForApp(true));
                }
            }
            return(false);
        }
Esempio n. 2
0
        /// <summary>
        /// On app start
        /// </summary>
        /// <param name="e">Startup EventArgs</param>
        protected override void OnStartup(StartupEventArgs e)
        {
            DesktopNotificationManagerCompat.RegisterAumidAndComServer <BetterExplorerNotificationActivator>("Gainedge.ORG.BetterExplorer");
            DesktopNotificationManagerCompat.RegisterActivator <BetterExplorerNotificationActivator>();
            Settings.BESettings.LoadSettings();

            Process process = Process.GetCurrentProcess();

            process.PriorityClass = ProcessPriorityClass.Normal;

            // Set the current thread to run at 'Highest' Priority
            Thread thread = Thread.CurrentThread;

            thread.Priority = ThreadPriority.Highest;

            Boolean dmi = true;

            System.Windows.Forms.Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            Current.DispatcherUnhandledException             += this.Current_DispatcherUnhandledException;
            AppDomain.CurrentDomain.UnhandledException       += this.CurrentDomain_UnhandledException;
            System.Windows.Forms.Application.ThreadException += this.Application_ThreadException;

            if (!File.Exists(Path.Combine(KnownFolders.RoamingAppData.ParsingName, @"BExplorer\Settings.sqlite")))
            {
                var beAppDataPath = Path.Combine(KnownFolders.RoamingAppData.ParsingName, @"BExplorer");
                if (!Directory.Exists(beAppDataPath))
                {
                    Directory.CreateDirectory(beAppDataPath);
                }
                File.Copy(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Settings.sqlite"), Path.Combine(KnownFolders.RoamingAppData.ParsingName, @"BExplorer\Settings.sqlite"));
            }

            //// loads current Ribbon color theme
            try {
                switch (Settings.BESettings.CurrentTheme)
                {
                case "Dark":
                    ThemeManager.ChangeAppTheme(this, "BaseDark");
                    UxTheme.AllowDarkModeForApp(true);
                    break;

                default:
                    ThemeManager.ChangeAppTheme(this, "BaseLight");
                    UxTheme.AllowDarkModeForApp(false);
                    break;
                }
            } catch (Exception ex) {
                // MessageBox.Show(String.Format("An error occurred while trying to load the theme data from the Registry. \n\r \n\r{0}\n\r \n\rPlease let us know of this issue at http://bugtracker.better-explorer.com/", ex.Message), "RibbonTheme Error - " + ex.ToString());
                MessageBox.Show(
                    $"An error occurred while trying to load the theme data from the Registry. \n\r \n\rRibbonTheme Error - {ex}\n\r \n\rPlease let us know of this issue at http://bugtracker.better-explorer.com/",
                    ex.Message);
            }

            if (e.Args.Any())
            {
                dmi = e.Args.Length >= 1;
                IsStartWithStartupTab = e.Args.Contains("/norestore");

                if (e.Args[0] != "-minimized")
                {
                    this.Properties["cmd"] = e.Args[0];
                }
                else
                {
                    IsStartMinimized = true;
                }
            }

            if (!ApplicationInstanceManager.CreateSingleInstance(Assembly.GetExecutingAssembly().GetName().Name, this.SingleInstanceCallback) && dmi)
            {
                return; // exit, if same app. is running
            }

            base.OnStartup(e);

            try {
                this.SelectCulture(Settings.BESettings.Locale);
            } catch {
                // MessageBox.Show(String.Format("A problem occurred while loading the locale from the Registry. This was the value in the Registry: \r\n \r\n {0}\r\n \r\nPlease report this issue at http://bugtracker.better-explorer.com/.", Locale));
                MessageBox.Show($"A problem occurred while loading the locale from the Registry. This was the value in the Registry: \r\n \r\n {Settings.BESettings.Locale}\r\n \r\nPlease report this issue at http://bugtracker.better-explorer.com/.");

                this.Shutdown();
            }
        }