private void ContinueStartup() { ((UI.Themes.Manager)Resources["ThemeManager"]).Load(); var deviceManager = WindowsAudioFactory.Create(AudioDeviceKind.Playback); deviceManager.Loaded += (_, __) => CompleteStartup(); CollectionViewModel = new DeviceCollectionViewModel(deviceManager, _settings); _trayIcon = new ShellNotifyIcon(new TaskbarIconSource(CollectionViewModel, _settings)); Exit += (_, __) => _trayIcon.IsVisible = false; CollectionViewModel.TrayPropertyChanged += () => _trayIcon.SetTooltip(CollectionViewModel.GetTrayToolTip()); _flyoutViewModel = new FlyoutViewModel(CollectionViewModel, () => _trayIcon.SetFocus()); FlyoutWindow = new FlyoutWindow(_flyoutViewModel); // Initialize the FlyoutWindow last because its Show/Hide cycle will pump messages, causing UI frames // to be executed, breaking the assumption that startup is complete. FlyoutWindow.Initialize(); }
private void CreateTrayExperience() { if (!SndVolSSO.SystemIconsAreAvailable()) { _settings.UseLegacyIcon = true; } TaskbarIconSource iconSource = null; iconSource = new TaskbarIconSource(icon => { if (_settings.UseLegacyIcon) { icon?.Dispose(); icon = IconHelper.LoadIconForTaskbar(SystemSettings.IsSystemLightTheme ? $"{AssetBaseUri}Application.ico" : $"{AssetBaseUri}Tray.ico"); } double iconFillPercent = ((SndVolSSO.IconId)iconSource.Tag) == SndVolSSO.IconId.NoDevice && !_settings.UseLegacyIcon ? 0.4 : 1; if (SystemParameters.HighContrast) { icon = IconHelper.ColorIcon(icon, iconFillPercent, _trayIcon.IsMouseOver ? SystemColors.HighlightTextColor : SystemColors.WindowTextColor); } else if (SystemSettings.IsSystemLightTheme && !_settings.UseLegacyIcon) { icon = IconHelper.ColorIcon(icon, iconFillPercent, System.Windows.Media.Colors.Black); } return(icon); }, () => $"hc={SystemParameters.HighContrast} {(SystemParameters.HighContrast ? $"mouse={_trayIcon.IsMouseOver}" : "")} dpi={WindowsTaskbar.Dpi} theme={SystemSettings.IsSystemLightTheme} legacy={_settings.UseLegacyIcon}"); _settings.UseLegacyIconChanged += (_, __) => iconSource.CheckForUpdate(); _trayIcon = new ShellNotifyIcon(iconSource, () => _settings.TrayIconIdentity, _settings.ResetTrayIconIdentity); _trayIcon.PrimaryInvoke += (_, type) => FlyoutViewModel.OpenFlyout(type); _trayIcon.SecondaryInvoke += (_, __) => _trayIcon.ShowContextMenu(GetTrayContextMenuItems()); _trayIcon.TertiaryInvoke += (_, __) => PlaybackDevicesViewModel.Default?.ToggleMute.Execute(null); _trayIcon.Scrolled += (_, wheelDelta) => PlaybackDevicesViewModel.Default?.IncrementVolume(Math.Sign(wheelDelta) * 2); Exit += (_, __) => _trayIcon.IsVisible = false; UpdateTrayTooltipAndIcon(); }
public FormsTrayApp() { syncCollectionDelegate = new SyncCollectionDelegate(syncCollection); syncFileDelegate = new SyncFileDelegate(syncFile); createChangeEventDelegate = new CreateChangeEventDelegate(createChangeEvent); notifyMessageDelegate = new NotifyMessageDelegate(notifyMessage); appRestart = Novell.Win32Util.Win32Window.RegisterWindowMsg("AppCreated"); RegistryKey regKey = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\Novell\iFolder"); string language = regKey.GetValue("language") as String; if (language != null) { try { Thread.CurrentThread.CurrentUICulture = new CultureInfo(language); } catch { } } string windowName = FormsTrayApp.resourceManager.GetString("iFolderServices") + Environment.UserName; Novell.Win32Util.Win32Window window = Novell.Win32Util.Win32Window.FindWindow(null, windowName); if (window != null) { Novell.Win32Util.Win32Window iFolderWindow = Novell.Win32Util.Win32Window.FindWindow(null, resourceManager.GetString("myiFolders")); if (iFolderWindow != null) { iFolderWindow.SendMsg(HWND_BOARDCAST, appRestart, IntPtr.Zero, IntPtr.Zero); } shutdown = true; } else { iFolderLogPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "iFolder"); if (!Directory.Exists(iFolderLogPath)) { Directory.CreateDirectory(iFolderLogPath); } this.simiasManager = new Manager( Environment.GetCommandLineArgs() ); InitializeComponent(); this.Text = FormsTrayApp.resourceManager.GetString("iFolderServices") + Environment.UserName; this.components = new System.ComponentModel.Container(); this.ClientSize = new System.Drawing.Size(292, 266); try { string basePath = Path.Combine(Application.StartupPath, "res"); startupIcon = new Icon(Path.Combine(basePath, "ifolder_waiting_16.ico")); shutdownIcon = new Icon(Path.Combine(basePath, "ifolder_download_16.ico")); trayIcon = new Icon(Path.Combine(basePath, "ifolder_16.ico")); syncIcons[0] = new Icon(trayIcon, trayIcon.Size); for (int i = 0; i < numberOfSyncIcons; i++) { string syncIcon = string.Format(Path.Combine(basePath, "ifolder_sync{0}.ico"), i+1); syncIcons[i] = new Icon(syncIcon); } this.ShowInTaskbar = false; this.WindowState = FormWindowState.Minimized; Win32Window win32Window = new Win32Window(); win32Window.Handle = this.Handle; win32Window.MakeToolWindow(); shellNotifyIcon = new ShellNotifyIcon(this.Handle); shellNotifyIcon.Text = resourceManager.GetString("iFolderServicesStarting"); shellNotifyIcon.Icon = startupIcon; if( !iFolderComponent.DisplayTrayIconEnabled ) shellNotifyIcon.Visible = false; shellNotifyIcon.ContextMenu = contextMenu1; shellNotifyIcon.Click += new Novell.CustomUIControls.ShellNotifyIcon.ClickDelegate(shellNotifyIcon_Click); shellNotifyIcon.BalloonClick += new Novell.CustomUIControls.ShellNotifyIcon.BalloonClickDelegate(shellNotifyIcon_BalloonClick); shellNotifyIcon.ContextMenuPopup += new Novell.CustomUIControls.ShellNotifyIcon.ContextMenuPopupDelegate(shellNotifyIcon_ContextMenuPopup); } catch { } } this.Closing += new System.ComponentModel.CancelEventHandler(this.FormsTrayApp_Closing); this.Load += new System.EventHandler(FormsTrayApp_Load); }