Exemple #1
0
        protected override void OnStartup(StartupEventArgs e)
        {
            DispatcherUnhandledException += App_DispatcherUnhandledException;
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            Environment.CurrentDirectory = WpfUtil.AssemblyDirectory;

#if DEBUG
            if (!Directory.Exists("logs"))
            {
                Directory.CreateDirectory("logs");
            }
            Trace.Listeners.Add(new FileLogTraceListener("filelistener")
            {
                Location = LogFileLocation.Custom, CustomLocation = "logs", Append = true, BaseFileName = "InstantTimer", AutoFlush = true, TraceOutputOptions = TraceOptions.DateTime, Delimiter = "\t|\t"
            });
#endif
            Trace.TraceInformation("OnStartup called.");

            try
            {
                WpfUtil.Init("jp.instanttimer");
                if (!WpfUtil.IsFirstInstance)
                {
                    Shutdown(0);
                    return;
                }
            }
            catch (Exception)
            {
                //ignored
            }
            WpfUtil.SecondInstanceStarted += WpfUtil_SecondInstanceStarted;

            SetupDi();
            HookManager.InitInstance();
            Injector.Get <ISettingsProvider>().Load();

            this.ShowCreateMainWindow <MainWindow>();

            base.OnStartup(e);
        }
Exemple #2
0
        protected override void OnStartup(StartupEventArgs e)
        {
            DispatcherUnhandledException += App_DispatcherUnhandledException;

            Environment.CurrentDirectory = Util.AssemblyDirectory;

            this.ShutdownMode = ShutdownMode.OnExplicitShutdown;

            WpfUtil.Init("AnperiHostApp");
            WpfUtil.SecondInstanceStarted += WpfUtil_SecondInstanceStarted;
            if (!WpfUtil.IsFirstInstance)
            {
                Shutdown();
                return;
                //aborting startup here to prevent the ui from being initialized.
            }

#if DEBUG
            if (!Directory.Exists("logs"))
            {
                Directory.CreateDirectory("logs");
            }
            Trace.Listeners.Add(new FileLogTraceListener("filelistener")
            {
                Location = LogFileLocation.Custom, CustomLocation = "logs", Append = true, BaseFileName = "anperi", AutoFlush = true
            });
#endif
            Trace.TraceInformation("Starting as first, new instance gonna start ...");

            bool createUi   = true;
            bool trayActive = true;
            foreach (string arg in e.Args)
            {
                switch (arg.ToLowerInvariant())
                {
                case "-tray":
                    createUi = false;
                    break;

                case "-notray":
                    trayActive        = false;
                    this.ShutdownMode = ShutdownMode.OnMainWindowClose;
                    break;

                default:
                    Trace.TraceWarning("Got invalid commandline argument. Ignoring '{0}'", arg);
                    break;
                }
            }
            if (!createUi && !trayActive)
            {
                MessageBox.Show("Can't use -tray and -notray together.", "Anperi configuration Error", MessageBoxButton.OK, MessageBoxImage.Error);
                Shutdown(1);
                return;
            }
            if (trayActive)
            {
                TrayHelper.Instance.DoubleClick   += TrayIcon_DoubleClick;
                TrayHelper.Instance.ItemExitClick += TrayIcon_ItemExitClick;
                TrayHelper.Instance.IconVisible    = true;
            }
            _initialized = true;
            var _ = HostModel.Instance;

            if (createUi)
            {
                this.ShowCreateMainWindow <MainWindow>();
            }

            base.OnStartup(e);
        }
Exemple #3
0
        protected override void OnStartup(StartupEventArgs e)
        {
            DispatcherUnhandledException += App_DispatcherUnhandledException;
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            Environment.CurrentDirectory = Util.AssemblyDirectory;

#if DEBUG
            if (!Directory.Exists("logs"))
            {
                Directory.CreateDirectory("logs");
            }
            Trace.Listeners.Add(new FileLogTraceListener("filelistener")
            {
                Location = LogFileLocation.Custom, CustomLocation = "logs", Append = true, BaseFileName = "AnperiRemote", AutoFlush = true, TraceOutputOptions = TraceOptions.DateTime, Delimiter = "\t|\t"
            });
#endif
            Trace.TraceInformation("OnStartup called.");

            object _ = SettingsModel.Instance;
            this.ShutdownMode = ShutdownMode.OnExplicitShutdown;
            try
            {
                WpfUtil.Init("jp.anperiremote");
                if (!WpfUtil.IsFirstInstance)
                {
                    Shutdown(0);
                    return;
                }
            }
            catch (Exception)
            {
                //ignored
            }
            WpfUtil.SecondInstanceStarted += WpfUtil_SecondInstanceStarted;
            bool createUi = true;
            foreach (string arg in e.Args)
            {
                switch (arg)
                {
                case "-tray":
                    createUi = false;
                    break;

                default:
                    Trace.TraceWarning($"Got invalid argument '{arg}', ignoring ...");
                    break;
                }
            }

            TrayHelper.Instance.IconVisible    = true;
            TrayHelper.Instance.DoubleClick   += TrayIcon_DoubleClick;
            TrayHelper.Instance.ItemExitClick += TrayIcon_ItemExitClick;

            AnperiModel.Init();
            if (createUi)
            {
                this.ShowCreateMainWindow <MainWindow>(out bool _);
            }

            base.OnStartup(e);
        }