internal Task CheckForChimeMeetingsAsync() { // explicitly make this synchronous code async so that it runs in the background // and allows the UX to continue updating return(Task.Run(async() => { Debug.WriteLine(DateTime.Now + ":[ChimeHelperState] CheckForChimeMeetings() called"); // TODO: this really needs to be its own function / reevaluate this being part of state App.Current.Dispatcher.Invoke(new Action(() => { App.TrayIcon.DataContext = ChimeHelperTray.MEETINGS_LOADING; })); _lastCheck = DateTime.Now; var autoLaunchOutlook = Properties.Settings.Default.AutoLaunchOutlook; var meetings = await ChimeOutlookHelper.ChimeOutlookHelper.GetMeetingsAsync(autoLaunchOutlook); _meetingMenuItemCache = new ChimeMeetingMenuItems(); foreach (var meeting in meetings) { _meetingMenuItemCache.AddRange(ChimeMeetingMenuItem.Create(meeting)); } _ = App.Current.Dispatcher.BeginInvoke(new Action(() => { var menuItems = ChimeHelperTray.NO_MEETINGS; if (_meetingMenuItemCache.Count > 0) { menuItems = _meetingMenuItemCache; } else if (!ChimeOutlookHelper.ChimeOutlookHelper.OutlookRunning()) { menuItems = ChimeHelperTray.OUTLOOK_NOT_RUNNING; } App.TrayIcon.DataContext = menuItems; })); CheckForMeetingStart(); })); }
// Not using "Instance" since this Singleton is more of an action public static void CreateAndShow(ChimeMeetingMenuItem meetingStartingNow) { if (_meetingNotificationWindow == null || _meetingNotificationWindow.IsLoaded == false) { _meetingNotificationWindow = new MeetingNotificationWindow(); } _meetingNotificationWindow.CurrentMeetings = (ChimeMeetingMenuItems)(App.TrayIcon.DataContext); _meetingNotificationWindow.ResetAutoHideTimer(); _meetingNotificationWindow.DefaultMeeting = meetingStartingNow; // refresh DataContext since we just set default meeting _meetingNotificationWindow.DataContext = _meetingNotificationWindow; WindowPositioner.MoveToMouse(_meetingNotificationWindow); _meetingNotificationWindow.Show(); _meetingNotificationWindow.Topmost = true; }