示例#1
0
        // --------------------------------------------------------------------------
        /// <summary>
        /// OnStartup
        /// </summary>
        // --------------------------------------------------------------------------
        protected override void OnStartup(StartupEventArgs e)
        {
            DraggingLogic.SetDpiAwareness();
            var talismanProcesses = Process.GetProcessesByName("Talisman");

            if (talismanProcesses.Length > 1)
            {
                Debug.WriteLine("Found an extra Talisman procress.");
#if DEBUG
                foreach (var process in talismanProcesses)
                {
                    Debug.WriteLine("Shutting down other Talisman ...");
                    var currentProcessId = Process.GetCurrentProcess().Id;
                    if (process.Id != currentProcessId)
                    {
                        try
                        {
                            process.Kill();
                        }
                        catch (Exception err)
                        {
                            Debug.WriteLine($"Could not end other talisman process: {err.Message}");
                        }
                    }
                }
#else
                Debug.WriteLine("Shutting down myself.");
                Application.Current.Shutdown();
#endif
            }
            var assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
            if (Settings.Default.CurrentVersion != assemblyVersion)
            {
                Settings.Default.Upgrade();
                Settings.Default.Reload();
                Settings.Default.CurrentVersion = assemblyVersion;
                Settings.Default.Save();
                Debug.WriteLine("Upgraded Settings: " + Settings.Default.Location);
            }

            if (String.IsNullOrEmpty(Settings.Default.CheckForNewVersions))
            {
                var result = MessageBox.Show("Check for new versions of Talisman?", "Talisman", MessageBoxButton.YesNo);
                Settings.Default.CheckForNewVersions = result.ToString();
                Settings.Default.Save();
            }

            if (Settings.Default.CheckForNewVersions == "Yes")
            {
                this.newVersionCheck = System.Threading.Tasks.Task.Run(CheckForNewVersion);
            }

            TestEws();
            base.OnStartup(e);
        }
        // --------------------------------------------------------------------------
        /// <summary>
        /// ctor
        /// </summary>
        // --------------------------------------------------------------------------
        public NotificationWidget(TimerInstance data, AppModel appModel, double location)
        {
            InitializeComponent();
            this._data       = data;
            this._appModel   = appModel;
            this.DataContext = data;
            LocationTheta    = location;
            data.OnDismiss  += () => this.Close();

            this.Loaded += (a, b) =>
            {
                _draggingLogic = new DraggingLogic(this, this);
                _draggingLogic.OnPositionChanged += (xm, ym) =>
                {
                    Center = new Point(Center.X + xm / _draggingLogic.DpiCorrectionX, Center.Y + ym / _draggingLogic.DpiCorrectionY);
                };
            };
        }
示例#3
0
        // --------------------------------------------------------------------------
        /// <summary>
        /// Stuff to do when we know about the display mode
        /// </summary>
        // --------------------------------------------------------------------------
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            _draggingLogic = new DraggingLogic(this, StoneArea);
            Debug.WriteLine("MainWindowLoaded Settings: Entry: " + Settings.Default.Location);

            _draggingLogic.OnPositionChanged += (xm, ym) =>
            {
                _newLocation = null;
                Settings.Default.Location = JsonConvert.SerializeObject(new Point((int)Left, (int)Top));
                Settings.Default.Save();
            };
            _draggingLogic.OnClick += () =>
            {
                // Try to position the settngs window well inside the main screen
                _settingsWindow.Left = this.Left;
                _settingsWindow.Top  = this.Top;
                if (this.Left > ScreenHelper.MainScreen.WorkingArea.Left + ScreenHelper.MainScreen.WorkingArea.Width / 2)
                {
                    _settingsWindow.Left = this.Left + this.Width - _settingsWindow.Width;
                }
                if (this.Top > ScreenHelper.MainScreen.WorkingArea.Top + ScreenHelper.MainScreen.WorkingArea.Height / 2)
                {
                    _settingsWindow.Top = this.Top + this.Height - _settingsWindow.Height;
                }
                _settingsWindow.Popup();
            };

            _settingsWindow      = new SettingsForm(_theModel);
            _settingsWindow.Left = this.Left;
            _settingsWindow.Top  = this.Top;


            // For some reason, need to do this to see the ticks on the time picker
            _settingsWindow.Show();
            _settingsWindow.Hide();

            var locationSetting = "\"1000,800\""; // Settings.Default.Location;
            var resetLocation   = false;

            if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
            {
                Debug.WriteLine("Resetting Location");
                // Hold down cntrl key on enter to reset location of new notifications
                resetLocation = true;
            }
            if (!Settings.Default.CrashedLastTime && !resetLocation)
            {
                if (!string.IsNullOrEmpty(Settings.Default.Location))
                {
                    Debug.WriteLine("Reading Location");
                    locationSetting = Settings.Default.Location;
                }
            }

            Debug.WriteLine("Location: " + locationSetting);

            Settings.Default.CrashedLastTime = true;
            Settings.Default.Save();
            Debug.WriteLine("MainWindow_Loaded Exit Settings: " + Settings.Default.Location);

            _newLocation = JsonConvert.DeserializeObject <Point>(locationSetting);
            Left         = _newLocation.Value.X;
            Top          = _newLocation.Value.Y;

            //ScreenHelper.EnsureWindowIsVisible(this);
        }