public static void Main(string[] args) { Console.WriteLine("Monitor BlinkSticks inserted and removed"); UsbMonitor monitor = new UsbMonitor(); //Attach to connected event monitor.BlinkStickConnected += (object sender, DeviceModifiedArgs e) => { Console.WriteLine("BlinkStick " + e.Device.Serial + " connected!"); }; //Attach to disconnected event monitor.BlinkStickDisconnected += (object sender, DeviceModifiedArgs e) => { Console.WriteLine("BlinkStick " + e.Device.Serial + " disconnected..."); }; List <BlinkStick> devices = new List <BlinkStick> (BlinkStick.FindAll()); //List BlinkSticks already connected foreach (BlinkStick device in devices) { Console.WriteLine("BlinkStick " + device.Serial + " already connected"); } //Start monitoring monitor.Start(); Console.WriteLine("Monitoring for BlinkStick devices... Press any key to exit."); //Start application event loop. Alternatively you can run main form: // Application.Run ([Your form]); while (true) { //Process messages Application.DoEvents(); //Exit if key is pressed if (Console.KeyAvailable) { break; } } //Stop monitoring monitor.Stop(); }
public Device() { _monitor = new UsbMonitor(); _monitor.UsbChangeEventArrival += new UsbMonitor.UsbChangeEventHandler(monitor_Arrival); _monitor.UsbChangeEventRemoved += new UsbMonitor.UsbChangeEventHandler(monitor_Removed); }
public void LoadEverything() { MainWindow.Instance = this; if (HidSharp.PlatformDetector.RunningPlatform() == HidSharp.PlatformDetector.Platform.Windows) { SetupSingleInstanceEvent(); } Build(); String brandingPath = global::System.IO.Path.Combine(global::System.AppDomain.CurrentDomain.BaseDirectory, "branding.png"); if (File.Exists(brandingPath)) { this.imageBranding.File = brandingPath; this.SetSizeRequest(500, this.imageBranding.Pixbuf.Height + 500); } if (ApplicationSettings.ApplicationTitle != "") { this.Title = String.Format(ApplicationSettings.ApplicationTitle, ApplicationDataModel.ApplicationVersion); } else { this.Title = "BlinkStick " + ApplicationDataModel.ApplicationVersion; } log.Info("Loading data"); DataModel.Load(); log.Debug("Registering/Unregistering startup"); RegisterStartup(ApplicationSettings.StartWithWindows); log.Debug("Loading main form icon"); this.Icon = new global::Gdk.Pixbuf(global::System.IO.Path.Combine(global::System.AppDomain.CurrentDomain.BaseDirectory, "icon.png")); DeviceMonitor = new UsbMonitor(); DeviceMonitor.UsbDevicesChanged += (object sender, EventArgs e) => { Gtk.Application.Invoke(delegate { RefreshDevices(); }); }; DeviceMonitor.Start(); log.Debug("Building popup menu"); //Build Popup Menu for TrayIcon popupMenu = new Menu(); //Settings menu item ImageMenuItem menuItemSettings = new ImageMenuItem("Settings"); menuItemSettings.Image = new Gtk.Image("icons-dark-cog-small", IconSize.Menu); menuItemSettings.Activated += ToggleMainWindow; popupMenu.Append(menuItemSettings); popupMenu.Append(new SeparatorMenuItem()); //Quit menu item ImageMenuItem menuItemQuit = new ImageMenuItem("Quit"); menuItemQuit.Image = new Gtk.Image("icon-dark-sign-out-small", IconSize.Menu); menuItemQuit.Activated += OnQuitActionActivated; popupMenu.Append(menuItemQuit); log.Debug("Showing popup menu"); popupMenu.ShowAll(); //TODO: Remove ifdef and use platform detection #if LINUX indicator = new ApplicationIndicator("blinkstick", "icon", Category.ApplicationStatus, ExecutableFolder); indicator.Menu = popupMenu; indicator.Status = AppIndicator.Status.Active; #else log.Debug("Setting up tray icon"); if (HidSharp.PlatformDetector.RunningPlatform() == HidSharp.PlatformDetector.Platform.Windows) { trayIcon = new StatusIcon(new Pixbuf(System.IO.Path.Combine(ExecutableFolder, "icon.ico"))); } else if (HidSharp.PlatformDetector.RunningPlatform() == HidSharp.PlatformDetector.Platform.Mac) { trayIcon = new StatusIcon(new Pixbuf(System.IO.Path.Combine(ExecutableFolder, "icon-osx.ico"))); } trayIcon.Tooltip = this.Title; trayIcon.Visible = true; // Show/Hide the window (even from the Panel/Taskbar) when the TrayIcon has been clicked. if (HidSharp.PlatformDetector.RunningPlatform() == HidSharp.PlatformDetector.Platform.Windows) { trayIcon.Activate += ToggleMainWindow; } trayIcon.PopupMenu += delegate { if (HidSharp.PlatformDetector.RunningPlatform() == HidSharp.PlatformDetector.Platform.Mac) { this.Show(); } else { popupMenu.ShowAll(); popupMenu.Popup(); } }; #endif if (HidSharp.PlatformDetector.RunningPlatform() == HidSharp.PlatformDetector.Platform.Mac) { //enable the global key handler for keyboard shortcuts MacMenu.GlobalKeyHandlerEnabled = true; //Tell the IGE library to use your GTK menu as the Mac main menu //MacMenu.MenuBar = menubar2; //tell IGE which menu item should be used for the app menu's quit item MacMenu.QuitMenuItem = menuItemQuit; //add a new group to the app menu, and add some items to it var appGroup = MacMenu.AddAppMenuGroup(); ImageMenuItem menuItemAbout = new ImageMenuItem("About"); menuItemAbout.Activated += (sender, e) => { this.Show(); VisiblePage = this.Pages[this.Pages.Count - 1]; }; appGroup.AddMenuItem(menuItemAbout, "About BlinkStick Client..."); ImageMenuItem menuItemPreferences = new ImageMenuItem("Preferences"); menuItemPreferences.Activated += (sender, e) => { this.Show(); VisiblePage = this.Pages[this.Pages.Count - 2]; }; appGroup.AddMenuItem(menuItemPreferences, "Preferences..."); ApplicationEvents.Quit += delegate(object sender, ApplicationQuitEventArgs e) { OnQuitActionActivated(null, null); e.Handled = true; }; ApplicationEvents.Reopen += delegate(object sender, ApplicationEventArgs e) { this.Deiconify(); this.Visible = true; e.Handled = true; }; //optional, only need this if your Info.plist registers to handle urls ApplicationEvents.OpenUrls += delegate(object sender, ApplicationUrlEventArgs e) { if (e.Urls != null || e.Urls.Count > 0) { //OpenUrls (e.Urls); } e.Handled = true; }; } NotificationRegistry.Register("Utilities", "Simple test notification", typeof(NotificationTest), typeof(TestEditorWidget), Gdk.Pixbuf.LoadFromResource("BlinkStickClient.Resources.notifications.notification-test.png")); NotificationRegistry.Register("Utilities", "Play pattern after BlinkStick Client application starts", typeof(NotificationStart), typeof(TestEditorWidget), Gdk.Pixbuf.LoadFromResource("BlinkStickClient.Resources.notifications.notification-test.png")); NotificationRegistry.Register("Utilities", "Play pattern before BlinkStick Client application exits", typeof(NotificationExit), typeof(TestEditorWidget), Gdk.Pixbuf.LoadFromResource("BlinkStickClient.Resources.notifications.notification-test.png")); NotificationRegistry.Register("Background", "Creates an ambilight effect", typeof(NotificationAmbilight), null, Gdk.Pixbuf.LoadFromResource("BlinkStickClient.Resources.notifications.notification-ambilight.png")); NotificationRegistry.Register("Background", "Runs a Boblight service prefonfigured for BlinkStick " + "which allows applications supporting Boblight protocol " + "to control the device and create ambilight effects", typeof(NotificationBoblight), null); NotificationRegistry.Register("Email", "Checks your GMail account and notifies when new mail arrives", typeof(NotificationGmail), typeof(GmailEditorWidget), Gdk.Pixbuf.LoadFromResource("BlinkStickClient.Resources.notifications.notification-gmail.png")); NotificationRegistry.Register("Email", "Checks your IMAP email account and notifies when new mail arrives", typeof(NotificationImap), typeof(EmailEditorWidget), Gdk.Pixbuf.LoadFromResource("BlinkStickClient.Resources.notifications.notification-mail.png")); NotificationRegistry.Register("Email", "Checks your POP3 email account and notifies when new mail arrives", typeof(NotificationPop3), typeof(EmailEditorWidget), Gdk.Pixbuf.LoadFromResource("BlinkStickClient.Resources.notifications.notification-mail.png")); NotificationRegistry.Register("Background", "Randomly changes BlinkStick color to create color mood", typeof(NotificationMood), typeof(MoodlightEditorWidget), Gdk.Pixbuf.LoadFromResource("BlinkStickClient.Resources.notifications.notification-moodlight.png")); NotificationRegistry.Register("Background", "Sets color for currently activated application", typeof(NotificationApplication), typeof(ApplicationEditorWidget), Gdk.Pixbuf.LoadFromResource("BlinkStickClient.Resources.notifications.notification-application.png")); NotificationRegistry.Register("Hardware", "Displays a notification when CPU usage is above limit", typeof(NotificationCpu), typeof(CpuEditorWidget), Gdk.Pixbuf.LoadFromResource("BlinkStickClient.Resources.notifications.notification-cpu.png")); NotificationRegistry.Register("Hardware", "Displays a notification when RAM usage is above limit", typeof(NotificationRam), typeof(CpuEditorWidget), Gdk.Pixbuf.LoadFromResource("BlinkStickClient.Resources.notifications.notification-ram.png")); NotificationRegistry.Register("Hardware", "Displays a notification when battery charge drops below certain limit", typeof(NotificationBattery), typeof(CpuEditorWidget), Gdk.Pixbuf.LoadFromResource("BlinkStickClient.Resources.notifications.notification-battery.png")); NotificationRegistry.Register("Hardware", "Displays a notification when available disk space drops below certain limit", typeof(NotificationDiskSpace), typeof(DiskSpaceEditorWidget), Gdk.Pixbuf.LoadFromResource("BlinkStickClient.Resources.notifications.notification-hdd.png")); NotificationRegistry.Register("Hardware", "Activate pattern when keyboard key combination is pressed", typeof(NotificationKeyboard), typeof(KeyboardEditorWidget), Gdk.Pixbuf.LoadFromResource("BlinkStickClient.Resources.notifications.notification-key.png")); NotificationRegistry.Register("Services", "Creates a remote control server accessible via HTTP.", typeof(NotificationRemoteControl), typeof(RemoteControlEditorWidget), Gdk.Pixbuf.LoadFromResource("BlinkStickClient.Resources.notifications.notification-remote-control.png")); NotificationRegistry.Register("Services", "Creates an MQTT server which allows remote control of connected BlinkStick devices via MQTT protocol.", typeof(NotificationMqtt), null); NotificationRegistry.Register("Services", "Connects to www.blinkstick.com and allows remote control of a BlinkStick device", typeof(NotificationBlinkStickDotCom), typeof(BlinkStickDotComEditorWidget), Gdk.Pixbuf.LoadFromResource("BlinkStickClient.Resources.notifications.notification-blinkstickdotcom.png")); NotificationRegistry.Register("Services", "Connects to IFTTT and allows remote control of a BlinkStick device", typeof(NotificationIfttt), null); if (ApplicationSettings.SingleBlinkStickMode) { overviewWidget = new OverviewSingleWidget(); hbox1.PackEnd(overviewWidget, true, true, 0); Pages.Add(overviewWidget); VisiblePage = overviewWidget; } else { overviewWidget = new OverviewWidget(); hbox1.PackEnd(overviewWidget, true, true, 0); Pages.Add(overviewWidget); VisiblePage = overviewWidget; } notificationsWidget = new NotificationsWidget(); notificationsWidget.ParentForm = this; notificationsWidget.DataModel = DataModel; notificationsWidget.ApplicationSettings = this.ApplicationSettings; notificationsWidget.Initialize(); hbox1.PackEnd(notificationsWidget, true, true, 0); Pages.Add(notificationsWidget); PatternEditorWidget patternEditorWidget = new PatternEditorWidget(); patternEditorWidget.DataModel = this.DataModel; hbox1.PackEnd(patternEditorWidget, true, true, 0); Pages.Add(patternEditorWidget); eventsWidget = new EventsWidget(); eventsWidget.DataModel = this.DataModel; hbox1.PackEnd(eventsWidget, true, true, 0); Pages.Add(eventsWidget); SettingsWidget settingsWidget = new SettingsWidget(); settingsWidget.LoadSettings(ApplicationSettings); hbox1.PackEnd(settingsWidget, true, true, 0); Pages.Add(settingsWidget); HelpWidget helpWidget = new HelpWidget(); hbox1.PackEnd(helpWidget, true, true, 0); Pages.Add(helpWidget); if (overviewWidget is OverviewWidget) { ((OverviewWidget)overviewWidget).DataModel = this.DataModel; } else { ((OverviewSingleWidget)overviewWidget).DataModel = this.DataModel; ((OverviewSingleWidget)overviewWidget).ApplicationSettings = this.ApplicationSettings; ((OverviewSingleWidget)overviewWidget).UpdateUI(); } notificationsWidget.DataModel = this.DataModel; notificationsWidget.ApplicationSettings = this.ApplicationSettings; RefreshDevices(); notificationService = new NotificationService(); notificationService.DataModel = this.DataModel; notificationService.Start(); log.Debug("Initialization done"); }
public MainWindow (): base (Gtk.WindowType.Toplevel) { if (!BlinkstickDeviceFinder.IsUnix()) { SetupSingleInstanceEvent(); } Build (); this.Title = "BlinkStick " + ApplicationVersion; log.Debug("Setting up controls"); Gtk.TreeViewColumn eventTitleColumn = new Gtk.TreeViewColumn (); eventTitleColumn.Title = "Name"; Gtk.TreeViewColumn eventTypeColumn = new Gtk.TreeViewColumn (); eventTypeColumn.Title = "Type"; Gtk.TreeViewColumn eventColorColumn = new Gtk.TreeViewColumn (); eventColorColumn.Title = "Color"; // Create the text cell that will display the artist name Gtk.CellRendererText eventTitleCell = new Gtk.CellRendererText (); Gtk.CellRendererText eventTypeCell = new Gtk.CellRendererText (); Gtk.CellRendererPixbuf eventColorCell = new Gtk.CellRendererPixbuf (); log.Debug ("Loading main form icon"); this.Icon = new global::Gdk.Pixbuf (global::System.IO.Path.Combine (global::System.AppDomain.CurrentDomain.BaseDirectory, "icon.png")); log.Debug( "Setting up treeview"); // Add the cell to the column eventColorColumn.PackStart (eventColorCell, false); eventTypeColumn.PackEnd (eventTypeCell, true); eventTitleColumn.PackEnd (eventTitleCell, true); // Tell the Cell Renderers which items in the model to display //eventTitleColumn.AddAttribute (eventTitleCell, "name", 0); eventTitleColumn.SetCellDataFunc (eventTitleCell, new Gtk.TreeCellDataFunc (RenderEventName)); eventTypeColumn.SetCellDataFunc (eventTypeCell, new Gtk.TreeCellDataFunc (RenderEventType)); eventColorColumn.SetCellDataFunc (eventColorCell, new Gtk.TreeCellDataFunc (RenderEventColor)); treeviewEvents.Model = EventListStore; treeviewEvents.AppendColumn (eventColorColumn); treeviewEvents.AppendColumn (eventTypeColumn); treeviewEvents.AppendColumn (eventTitleColumn); log.Debug("Updating buttons"); UpdateButtons (); log.Debug("Setting up notification manager"); Manager = new NotificationManager (); Manager.NotificationUpdated += HandleNotificationUpdated; Manager.Load (); Manager.UpdateControllers(); DeviceMonitor = new UsbMonitor(this.GdkWindow.Handle); DeviceMonitor.UsbDeviceAdded += (object sender, EventArgs e) => { Gtk.Application.Invoke (delegate { Manager.UpdateControllers(); if (testForm != null) { testForm.PopulateForm(); } }); }; DeviceMonitor.Start (); log.Debug("Adding notifications to the tree"); //Gtk.TreeIter customEventRoot = EventListStore.AppendValues(new TriggeredEvent("Custom")); foreach (CustomNotification e in Manager.Notifications) { //EventListStore.AppendValues(customEventRoot, e); EventListStore.AppendValues (e); } log.Debug("Starting notification manager"); Manager.Start (); log.Debug ("Building popup menu"); //Build Popup Menu for TrayIcon popupMenu = new Menu (); //Settings menu item ImageMenuItem menuItemSettings = new ImageMenuItem ("Settings"); menuItemSettings.Image = new Gtk.Image(Stock.Preferences, IconSize.Menu); menuItemSettings.Activated += ToggleMainWindow; popupMenu.Append(menuItemSettings); popupMenu.Append(new SeparatorMenuItem()); //Quit menu item ImageMenuItem menuItemQuit = new ImageMenuItem ("Quit"); menuItemQuit.Image = new Gtk.Image (Stock.Quit, IconSize.Menu); menuItemQuit.Activated += OnQuitActionActivated; popupMenu.Append (menuItemQuit); log.Debug("Showing popup menu"); popupMenu.ShowAll(); #if LINUX indicator = new ApplicationIndicator ("blinkstick", "icon", Category.ApplicationStatus, ExecutableFolder); indicator.Menu = popupMenu; indicator.Status = AppIndicator.Status.Active; #else log.Debug ("Setting up tray icon"); trayIcon = new StatusIcon (new Pixbuf (System.IO.Path.Combine(ExecutableFolder, "icon.ico"))); trayIcon.Tooltip = this.Title; trayIcon.Visible = true; // Show/Hide the window (even from the Panel/Taskbar) when the TrayIcon has been clicked. trayIcon.Activate += ToggleMainWindow; trayIcon.PopupMenu += delegate { popupMenu.ShowAll (); popupMenu.Popup (); }; #endif log.Debug("Initialization done"); }
public BeamgunViewModel(Window mainWindow) { BeamgunState = new BeamgunState { MainWindowVisibility = Visibility.Hidden }; BeamgunState.Disabler = new Disabler(BeamgunState); BeamgunState.Disabler.Enable(); DisableCommand = new DisableCommand(this); TrayIconCommand = new TrayIconCommand(this); LoseFocusCommand = new DeactivatedCommand(this); ResetCommand = new ResetCommand(this); ExitCommand = new ExitCommand(this); _workstationLocker = new WorkstationLocker(); const uint repeatInterval = 10; var converter = new KeyConverter(); _keystrokeHooker = new KeystrokeHooker(); _alarm = new Alarm(repeatInterval, BeamgunState); _alarm.AlarmCallback += () => { BeamgunState.MainWindowState = WindowState.Normal; BeamgunState.MainWindowVisibility = Visibility.Visible; BeamgunState.SetGraphicsAlert(); if (BeamgunState.StealFocus) { StealFocus(); } }; var windowHandle = new WindowInteropHelper(mainWindow).Handle; _usbMonitor = new UsbMonitor(windowHandle); _usbMonitor.DeviceAdded += () => { BeamgunState.AppendToAlert("USB device inserted."); _alarm.Trigger("Alerting on USB device insertion."); if (!BeamgunState.LockWorkStation) { return; } var result = _workstationLocker.Lock(); var message = result ? "Successfully locked the workstation." : "Could not lock the workstation."; BeamgunState.AppendToAlert(message); }; _usbMonitor.DeviceRemoved += () => { BeamgunState.AppendToAlert("USB device removed."); }; _keystrokeHooker.Callback += key => { if (!_alarm.Triggered) { return; } BeamgunState.AppendToKeyLog(converter.Convert(key)); }; }