Example #1
0
        public MainWindow()
        {
            Console.WriteLine("--------- AppStart");
            LanguageHelper(); //set current UI language
            InitializeComponent();

            //only run at first startup
            if (Settings.Default.FirstRun)
            {
                SystemTimeFormat(); //check if system uses 12 hour clock
                AddJumpList();      //create jump list entries

                var regEdit = new RegeditHandler();
                //is accent color for taskbar active?
                if (regEdit.GetColorPrevalence())
                {
                    Settings.Default.AccentColor = true;
                }

                //set taskfolder name with username for multiple user environments
                try
                {
                    Settings.Default.TaskFolderTitle          = "ADM_" + Environment.UserName;
                    Settings.Default.TaskFolderTitleMultiUser = true;
                }
                catch
                {
                    Settings.Default.TaskFolderTitle          = "Auto Dark Mode";
                    Settings.Default.TaskFolderTitleMultiUser = true;
                }

                //finished first startup code
                Settings.Default.FirstRun = false;
            }
        }
Example #2
0
        public MainWindow()
        {
            DataContext  = this;
            WindowX      = ((int)(Settings.Default.UIScale * BasewindowX)).ToString();
            WindowY      = ((int)((Settings.Default.UIScale) * BaseWindowY)).ToString();
            ScaleStringX = Settings.Default.UIScale.ToString("N2", CultureInfo.CreateSpecificCulture("en-US"));
            ScaleStringY = Settings.Default.UIScale.ToString("N2", CultureInfo.CreateSpecificCulture("en-US"));
            Console.WriteLine("--------- AppStart");
            LanguageHelper(); //set current UI language
            InitializeComponent();

            //only run at first startup
            if (Settings.Default.FirstRun)
            {
                SystemTimeFormat(); //check if system uses 12 hour clock
                AddJumpList();      //create jump list entries

                var regEdit = new RegeditHandler();
                //is accent color for taskbar active?
                if (regEdit.GetColorPrevalence())
                {
                    Settings.Default.AccentColor = true;
                }

                //set taskfolder name with username for multiple user environments
                try
                {
                    Settings.Default.TaskFolderTitle          = "ADM_" + Environment.UserName;
                    Settings.Default.TaskFolderTitleMultiUser = true;
                }
                catch
                {
                    Settings.Default.TaskFolderTitle          = "Auto Dark Mode";
                    Settings.Default.TaskFolderTitleMultiUser = true;
                }

                //finished first startup code
                Settings.Default.FirstRun = false;
            }

            if (Settings.Default.LanguageChanged)
            {
                AddJumpList();
                Settings.Default.LanguageChanged = false;
            }
        }
Example #3
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            if (!Mutex.WaitOne(TimeSpan.FromMilliseconds(100)))
            {
                Shutdown();
            }

            List <string> args = new List <string>();

            if (e.Args.Length > 0)
            {
                args = new List <string>(e.Args);
            }
            if (args.Count > 0 && args.Contains("/debug"))
            {
                debug = true;
                args.Remove("/debug");
            }

            StartService();
            int  maxTries    = 5;
            int  tries       = 0;
            bool heartBeatOK = false;

            while (tries < maxTries && !heartBeatOK)
            {
                tries++;
                heartBeatOK = commandClient.SendMessage(Command.Alive);
            }
            if (maxTries == tries && !heartBeatOK)
            {
                string error = "could not get a heartbeat from the backend. Check if AutoDarkModeSvc.exe is running and try again";
                MsgBox msg   = new MsgBox(error, AutoDarkModeApp.Properties.Resources.errorOcurredTitle, "error", "close")
                {
                };
                msg.ShowDialog();
                return;
            }
            //handle command line arguments
            if (args.Count > 0)
            {
                Thread.Sleep(1000);
                Mutex.Dispose();
                Mutex = new Mutex(true, "7f326fe1-181c-414f-b7f1-0df4baa578a7");
                Mutex.WaitOne(TimeSpan.FromMilliseconds(100));
                foreach (var value in args)
                {
                    if (value == "/switch")
                    {
                        commandClient.SendMessage(value);
                    }
                    else if (value == "/swap")
                    {
                        commandClient.SendMessage(value);
                    }
                    else if (value == "/dark")
                    {
                        commandClient.SendMessage(value);
                    }
                    else if (value == "/light")
                    {
                        commandClient.SendMessage(value);
                    }
                    else if (value == "/noForce")
                    {
                        commandClient.SendMessage(value);
                    }
                    else if (value == "/update")
                    {
                        var result = commandClient.SendMessageAndGetReply(value);

                        if (result != Response.Err)
                        {
                            Updater updater = new Updater(true);
                            updater.ParseResponse(result);
                        }
                    }
                    else if (value == "/location")
                    {
                        commandClient.SendMessage(Command.Location);
                    }
                    else if (value == "/removeAutostart")
                    {
                        RegeditHandler regEditHandler = new RegeditHandler();
                        regEditHandler.RemoveAutoStart();
                    }
                    else if (value == "/shutdownService")
                    {
                        commandClient.SendMessage(Command.Shutdown);
                    }
                    else if (value == "/pipeclienttest")
                    {
                        //ICommandClient pc = new PipeClient(Tools.DefaultPipeName);
                        bool result = commandClient.SendMessage(Command.Location);
                        Console.Out.WriteLine(result);
                    }
                    NetMQConfig.Cleanup();
                    Mutex.Dispose();
                    Shutdown();
                }
            }
            else
            {
                MainWindow mainWin = new MainWindow();
                mainWin.Show();
            }
        }