예제 #1
0
        public ShellView()
        {
            InitializeComponent();

            // Check if there was instance before this. If there was-close the current one.
            if (ProcessUtilities.ThisProcessIsAlreadyRunning())
            {
                ProcessUtilities.SetFocusToPreviousInstance("Carnac");
                Application.Current.Shutdown();
            }

            var exitMenuItem = new MenuItem
            {
                Text = Properties.Resources.ShellView_Exit
            };

            var iconStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Carnac.icon.embedded.ico");

            var ni = new NotifyIcon
            {
                Icon        = new Icon(iconStream),
                ContextMenu = new ContextMenu(new[] { exitMenuItem })
            };

            exitMenuItem.Click += (sender, args) =>
            {
                ni.Visible = false;
                Application.Current.Shutdown();
            };
            ni.MouseClick += NotifyIconClick;
            ni.Visible     = true;
        }
예제 #2
0
파일: App.xaml.cs 프로젝트: zdrawku/carnac
        protected override void OnStartup(StartupEventArgs e)
        {
            ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
            // Check if there was instance before this. If there was-close the current one.
            if (ProcessUtilities.ThisProcessIsAlreadyRunning())
            {
                ProcessUtilities.SetFocusToPreviousInstance("Carnac");
                Shutdown();
                return;
            }

            trayIcon = new CarnacTrayIcon();
            trayIcon.OpenPreferences += TrayIconOnOpenPreferences;
            var keyShowViewModel = new KeyShowViewModel(settings);

            keyShowView = new KeyShowView(keyShowViewModel);
            keyShowView.Show();

            carnac = new KeysController(keyShowViewModel.Messages, messageProvider, new ConcurrencyService(), settingsProvider);
            carnac.Start();

#if !DEBUG
            if (settings.AutoUpdate)
            {
                Observable
                .Timer(TimeSpan.FromMinutes(5))
                .Subscribe(async x =>
                {
                    try
                    {
                        using (var mgr = UpdateManager.GitHubUpdateManager(carnacUpdateUrl))
                        {
                            await mgr.Result.UpdateApp();
                        }
                    }
                    catch
                    {
                        // Do something useful with the exception
                    }
                });
            }
#endif

            base.OnStartup(e);
        }
예제 #3
0
파일: App.xaml.cs 프로젝트: phaufe/carnac
        protected override void OnStartup(StartupEventArgs e)
        {
            // Check if there was instance before this. If there was-close the current one.
            if (ProcessUtilities.ThisProcessIsAlreadyRunning())
            {
                ProcessUtilities.SetFocusToPreviousInstance("Carnac");
                Shutdown();
                return;
            }

            trayIcon = new CarnacTrayIcon();
            trayIcon.OpenPreferences += TrayIconOnOpenPreferences;
            keyCollection             = new ObservableCollection <Message>();
            keyShowView = new KeyShowView(new KeyShowViewModel(keyCollection, settings));
            keyShowView.Show();

            carnac = new KeysController(keyCollection, messageProvider, keyProvider, new ConcurrencyService());
            carnac.Start();

            base.OnStartup(e);
        }
예제 #4
0
        protected override void OnStartup(StartupEventArgs e)
        {
            // Check if there was instance before this. If there was-close the current one.
            if (ProcessUtilities.ThisProcessIsAlreadyRunning())
            {
                ProcessUtilities.SetFocusToPreviousInstance("Carnac");
                Shutdown();
                return;
            }

            trayIcon = new CarnacTrayIcon();
            trayIcon.OpenPreferences += TrayIconOnOpenPreferences;
            var keyShowViewModel = new KeyShowViewModel(settings);

            keyShowView = new KeyShowView(keyShowViewModel);
            keyShowView.Show();

            carnac = new KeysController(keyShowViewModel.Messages, messageProvider, new ConcurrencyService(), settingsProvider);
            carnac.Start();

            MouseWatcher.OnMouseInput += (s, me) =>
            {
                if (!keyShowView.IsVisible)
                {
                    return;
                }
                var msg     = me.Message;
                var needAct = msg == MouseMessages.WM_LBUTTONUP || msg == MouseMessages.WM_RBUTTONUP;
                if (!needAct)
                {
                    return;
                }

                Dispatcher.Invoke(() =>
                {
                    keyShowViewModel.CursorPosition = keyShowView.PointFromScreen(new System.Windows.Point(me.Point.x, me.Point.y));
                    if (msg == MouseMessages.WM_LBUTTONUP)
                    {
                        keyShowView.LeftClick();
                    }
                    if (msg == MouseMessages.WM_RBUTTONUP)
                    {
                        keyShowView.RightClick();
                    }
                });
            };

            if (settings.ShowMouseClicks)
            {
                MouseWatcher.Start();
            }
            settings.PropertyChanged += (s, se) => {
                switch (se.PropertyName)
                {
                case "ShowMouseClicks":
                    if (this.settings.ShowMouseClicks)
                    {
                        MouseWatcher.Start();
                    }
                    else
                    {
                        MouseWatcher.Stop();
                    }
                    break;
                }
            };

#if !DEBUG
            if (settings.AutoUpdate)
            {
                Observable
                .Timer(TimeSpan.FromMinutes(5))
                .Subscribe(async x =>
                {
                    try
                    {
                        using (var mgr = UpdateManager.GitHubUpdateManager(carnacUpdateUrl))
                        {
                            await mgr.Result.UpdateApp();
                        }
                    }
                    catch
                    {
                        // Do something useful with the exception
                    }
                });
            }
#endif

            base.OnStartup(e);
        }