Ejemplo n.º 1
0
        public override void CloseWallpaper(params uint[] screenIndexs)
        {
            base.CloseWallpaper(screenIndexs);

            var haveExeWallpaper = WallpaperManager.CurrentWalpapers.Values.FirstOrDefault(m => m.Type == WallpaperType.Exe) != null;

            if (!haveExeWallpaper)
            {
                DesktopMouseEventReciver.Stop();
            }
        }
Ejemplo n.º 2
0
 protected override async Task InnerCloseWallpaperAsync(List <RenderInfo> wallpaperRenders, bool closeBeforeOpening)
 {
     //不论是否临时关闭,都需要关闭进程重启进程
     foreach (var render in wallpaperRenders)
     {
         try
         {
             var p = Process.GetProcessById(render.PId);
             p.Kill();
         }
         catch (Exception ex)
         {
             Debug.WriteLine($"InnerCloseWallpaper ex:{ex}");
         }
         finally
         {
             if (SupportMouseEvent)
             {
                 await DesktopMouseEventReciver.RemoveHandle(render.ReceiveMouseEventHandle);
             }
         }
     }
 }
Ejemplo n.º 3
0
        protected override async Task <BaseApiResult <List <RenderInfo> > > InnerShowWallpaper(WallpaperModel wallpaper, CancellationToken ct, params string[] screens)
        {
            List <RenderInfo> infos    = new List <RenderInfo>();
            List <Task>       tmpTasks = new List <Task>();

            ProcessStartInfo pInfo = await Task.Run(() => GetRenderExeInfo(wallpaper));

            if (pInfo == null)
            {
                return(BaseApiResult <List <RenderInfo> > .ErrorState(ErrorType.NoPlayer));
            }

            foreach (var screenItem in screens)
            {
                if (ct.IsCancellationRequested)
                {
                    break;
                }
                var task = Task.Run(async() =>
                {
                    try
                    {
                        var processResult = await StartProcess(pInfo, ct);

                        //壁纸启动失败
                        if (processResult.HostHandle == IntPtr.Zero)
                        {
                            return;
                        }

                        var host = LiveWallpaperRenderForm.GetHost(screenItem);
                        host !.ShowWallpaper(processResult.HostHandle);

                        infos.Add(new RenderInfo(processResult)
                        {
                            Wallpaper = wallpaper,
                            Screen    = screenItem
                        });
                    }
                    catch (OperationCanceledException)
                    {
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex);
                    }
                }, ct);

                tmpTasks.Add(task);
            }
            await Task.WhenAll(tmpTasks);

            if (SupportMouseEvent && WallpaperApi.Options.ForwardMouseEvent && wallpaper.Option.EnableMouseEvent)
            {
                foreach (var item in infos)
                {
                    await DesktopMouseEventReciver.AddHandle(item.ReceiveMouseEventHandle, item.Screen);
                }
            }
            return(BaseApiResult <List <RenderInfo> > .SuccessState(infos));
        }