Exemplo n.º 1
0
        private static IDisposable ShowDesktopWindow(int number)
        {
            var vmodel = new NotificationWindowViewModel
            {
                Title = ProductInfo.Title,
                Body  = GetDesktopName(number),
            };
            var source = new CancellationTokenSource();

            var settings = Settings.General.Display.Value;

            Monitor[] targets;
            if (settings == 0)
            {
                targets = new[] { MonitorService.GetCurrentArea() };
            }
            else
            {
                var monitors = MonitorService.GetAreas();
                if (settings == uint.MaxValue)
                {
                    targets = monitors;
                }
                else
                {
                    targets = new[] { monitors[settings - 1] };
                }
            }
            var windows = targets.Select(area =>
            {
                var window = new SwitchWindow(area.WorkArea)
                {
                    DataContext = vmodel,
                };
                window.Show();
                return(window);
            }).ToList();

            Task.Delay(TimeSpan.FromMilliseconds(Settings.General.NotificationDuration), source.Token)
            .ContinueWith(_ => windows.ForEach(window => window.Close()), TaskScheduler.FromCurrentSynchronizationContext());

            return(Disposable.Create(() => source.Cancel()));
        }
Exemplo n.º 2
0
        private static IDisposable ShowRenameWindow()
        {
            var current = VirtualDesktop.Current;
            int number  = DesktopHelper.GetNumber(current);

            var source = new CancellationTokenSource();

            var vmodel = new RenameWindowViewModel
            {
                Number = number,
            };
            var window = new RenameWindow(MonitorService.GetCurrentArea().WorkArea)
            {
                DataContext = vmodel,
            };

            window.Show();

            Task.Delay(TimeSpan.FromMilliseconds(30000), source.Token)
            .ContinueWith(_ => window.Close(), TaskScheduler.FromCurrentSynchronizationContext());

            return(Disposable.Create(() => source.Cancel()));
        }