Beispiel #1
0
 public WindowManager(IAppConfiguration appConfig, IEnumerable <WindowBase> windows, ILogger logger)
 {
     _appConfig = appConfig;
     _logger    = logger;
     _shortcuts = ElectronNET.API.Electron.GlobalShortcut;
     _windows   = windows.ToDictionary(w => w.Name, w => w, StringComparer.InvariantCultureIgnoreCase);
 }
Beispiel #2
0
 public MainWindow()
 {
     GlobalData.Init();
     Instance = this;
     //WindowState = WindowState.Normal;
     InitializeComponent();
     ContentRendered += MainWindow_ContentRendered;
     if (GlobalData.Config.TransConfig.HotKey != null)
     {
         var text = GlobalData.Config.TransConfig.HotKey;
         if (text.Split('+').Length <= 1)
         {
             Hot.Key = (Key)Key.Parse(typeof(Key), text);
             var keyStr = Hot.Modifiers != ModifierKeys.None ? $"{Hot.Modifiers.ToString()} + {Hot.Key.ToString()}" : Hot.Key.ToString();
             (DataContext as MainViewModel).KeyText = keyStr;
             var keybinds = GlobalShortcut.GetKeyBindings(this).ToList();
             GlobalShortcut.Init(keybinds);
         }
         else
         {
             Hot.Modifiers = (ModifierKeys)ModifierKeys.Parse(typeof(ModifierKeys), text.Split('+')[0].Trim());
             Hot.Key       = (Key)Key.Parse(typeof(Key), text.Split('+')[1].Trim());
             var keyStr = Hot.Modifiers != ModifierKeys.None ? $"{Hot.Modifiers.ToString()} + {Hot.Key.ToString()}" : Hot.Key.ToString();
             (DataContext as MainViewModel).KeyText = keyStr;
             var keybinds = GlobalShortcut.GetKeyBindings(this).ToList();
             GlobalShortcut.Init(keybinds);
         }
     }
 }
 public async Task Handle(GlobalShortcut request, Responder respond)
 {
     if (request.CallbackId == _callbackId)
     {
         await _handler.Handle(request, respond).ConfigureAwait(false);
     }
 }
Beispiel #4
0
        public void GlobalShortcutTrue1()
        {
            var actual = new GlobalShortcut(System.Windows.Input.ModifierKeys.Alt, System.Windows.Input.Key.A);

            Assert.NotNull(actual);
            Assert.Equal(System.Windows.Input.ModifierKeys.Alt, actual.ModifierKeys);
            Assert.Equal(System.Windows.Input.Key.A, actual.Key);
        }
Beispiel #5
0
 public ShortcutManager(IConfigurationProvider configProvider, IWindowsServices windowServices)
 {
     _configProvider = configProvider;
     _currentConfig  = _configProvider.GetAppConfiguration();
     _windowServices = windowServices;
     _shortcuts      = ElectronNET.API.Electron.GlobalShortcut;
     configProvider.ConfigurationUpdated += (sender, args) => BindShortcuts();
 }
        protected override void OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);

            Messenger.Default.Send <object>(null, MessageToken.ClearLeftSelected);
            Messenger.Default.Send(true, MessageToken.FullSwitch);
            Messenger.Default.Send(AssemblyHelper.CreateInternalInstance($"UserControl.{MessageToken.OverView}"), MessageToken.LoadShowContent);

            GlobalShortcut.Init(this);
        }
Beispiel #7
0
        public void SavePreferences(
            string delimiter,
            ModifierKeys showHideModifierKeys, Key showHideKey,
            string themeName,
            bool autoLaunch)
        {
            var showHideGlobalShortcut = new GlobalShortcut(showHideModifierKeys, showHideKey);
            var preferences            = new Preferences(delimiter, showHideGlobalShortcut, themeName, autoLaunch);

            PreferencesRepository.Save(preferences);
        }
Beispiel #8
0
        public void PreferencesTrue1()
        {
            var globalShortcut = new GlobalShortcut(System.Windows.Input.ModifierKeys.None, System.Windows.Input.Key.A);
            var actual         = new Preferences(",", globalShortcut, AppTheme.GenerateDefault().ThemeName, true);

            Assert.NotNull(actual);
            Assert.Equal(nowVersion, actual.Version);
            Assert.Equal(",", actual.Delimiter);
            Assert.Equal(globalShortcut, actual.ShowHideShortcut);
            Assert.Equal("Dark.Steel", actual.ThemeName);
            Assert.True(actual.AutoLaunch);
        }
Beispiel #9
0
        public void GenerateDefaultTrue1()
        {
            var globalShortcut = new GlobalShortcut(System.Windows.Input.ModifierKeys.Control | System.Windows.Input.ModifierKeys.Shift, System.Windows.Input.Key.Space);
            var actual         = Preferences.GenerateDefault();

            Assert.NotNull(actual);
            Assert.Equal(nowVersion, actual.Version);
            Assert.Equal(",", actual.Delimiter);
            Assert.Equal(globalShortcut.ModifierKeys, actual.ShowHideShortcut.ModifierKeys);
            Assert.Equal(globalShortcut.Key, actual.ShowHideShortcut.Key);
            Assert.Equal("Dark.Steel", actual.ThemeName);
            Assert.False(actual.AutoLaunch);
        }
        protected override void OnContentRendered(EventArgs e)
        {
            base.OnContentRendered(e);

            DataContext          = ViewModelLocator.Instance.Main;
            NonClientAreaContent = new NonClientAreaContent();
            ControlMain.Content  = new MainWindowContent();

            GlobalShortcut.Init(new List <KeyBinding>
            {
                new KeyBinding(ViewModelLocator.Instance.Main.GlobalShortcutInfoCmd, Key.I, ModifierKeys.Control | ModifierKeys.Alt),
                new KeyBinding(ViewModelLocator.Instance.Main.GlobalShortcutWarningCmd, Key.E, ModifierKeys.Control | ModifierKeys.Alt)
            });

            Dialog.SetToken(this, MessageToken.MainWindow);
            WindowAttach.SetIgnoreAltF4(this, true);

            Messenger.Default.Send(true, MessageToken.FullSwitch);
            Messenger.Default.Send(AssemblyHelper.CreateInternalInstance($"UserControl.{MessageToken.PracticalDemo}"), MessageToken.LoadShowContent);
        }
Beispiel #11
0
        private void HitTest(Key key)
        {
            if (IsModifierKey(key))
            {
                return;
            }

            var modifierKeys = Keyboard.Modifiers;
            var keyStr       = modifierKeys != ModifierKeys.None ? $"{modifierKeys.ToString()} + {key.ToString()}" : key.ToString();

            Hot.Modifiers = Keyboard.Modifiers;
            Hot.Key       = key;
            (DataContext as MainViewModel).KeyText = keyStr;
            //(DataContext as MainViewModel).ModifierKeys = modifierKeys;
            //(DataContext as MainViewModel).Key = key;
            var keybinds = GlobalShortcut.GetKeyBindings(this).ToList();

            GlobalShortcut.Init(keybinds);
            GlobalData.Config.TransConfig.HotKey = (DataContext as MainViewModel).KeyText;
            GlobalData.Save();
            Growl.SuccessGlobal($"HotKey is {keyStr}");
        }
Beispiel #12
0
        public void RegisterGlobalShortcutHandler()
        {
            // Arrange
            var keyedHandler        = Substitute.For <IGlobalShortcutHandler>();
            var genericHandler      = Substitute.For <IGlobalShortcutHandler>();
            var keyedAsyncHandler   = Substitute.For <IAsyncGlobalShortcutHandler>();
            var genericAsyncHandler = Substitute.For <IAsyncGlobalShortcutHandler>();
            var otherShortcut       = new GlobalShortcut {
                CallbackId = "other"
            };
            var shortcut = new GlobalShortcut {
                CallbackId = "key"
            };
            var responder = Substitute.For <Responder>();

            var sut = Configure(c => c
                                .RegisterGlobalShortcutHandler("key", keyedHandler)
                                .RegisterGlobalShortcutHandler(genericHandler)
                                .RegisterAsyncGlobalShortcutHandler("key", keyedAsyncHandler)
                                .RegisterAsyncGlobalShortcutHandler(genericAsyncHandler));

            // Act
            HandleGlobalShortcuts(sut, responder, new[] { otherShortcut, shortcut });

            // Assert
            keyedHandler.DidNotReceive().Handle(otherShortcut);
            keyedHandler.Received().Handle(shortcut);

            genericHandler.Received().Handle(otherShortcut);
            genericHandler.Received().Handle(shortcut);

            keyedAsyncHandler.DidNotReceive().Handle(otherShortcut, responder);
            keyedAsyncHandler.Received().Handle(shortcut, responder);

            genericAsyncHandler.Received().Handle(otherShortcut, responder);
            genericAsyncHandler.Received().Handle(otherShortcut, responder);
        }
Beispiel #13
0
 private Task <SlackResult> HandleGlobalShortcut(GlobalShortcut globalShortcut) =>
 RespondAsync(r => _globalShortcutHandler.Handle(globalShortcut, r));
Beispiel #14
0
 public async Task Handle(GlobalShortcut request, Responder respond)
 {
 }
Beispiel #15
0
 public async Task Handle(GlobalShortcut request)
 {
 }
Beispiel #16
0
 public Task Handle(GlobalShortcut shortcut, Responder respond) => ResolvedHandle(h => h.Handle(shortcut, respond));