public Task <BaseApiResult> ShowWallpaper(string path)
 {
     return(WallpaperApi.ShowWallpaper(new WallpaperModel()
     {
         Path = path
     }));
 }
        public async Task <BaseApiResult <WallpaperModel> > ShowWallpaper(string path)
        {
            var model = await WallpaperApi.ShowWallpaper(path);

            await AppManager.SaveCurrentWalpapers();

            return(model);
        }
        public static async Task Initialize(int hostPort)
        {
            //MyDocuments这个路径不会虚拟化,方便从Dart端读取
            _runningDataFilePath = $"{Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)}\\{AppName}\\runningData.json";
            _userSettingFilePath = $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\\{AppName}\\Config\\userSetting.json";

            try
            {
                //应用程序数据
                RunningData = await JsonHelper.JsonDeserializeFromFileAsync <RunningData>(_runningDataFilePath);

                if (RunningData == null)
                {
                    //生成默认运行数据
                    RunningData = new RunningData();
                }
                //更新端口号
                RunningData.HostPort = hostPort;
                await JsonHelper.JsonSerializeAsync(RunningData, _runningDataFilePath);

                await LoadUserSetting();

                //开机启动
                DesktopBridge.Helpers helpers = new DesktopBridge.Helpers();
                if (helpers.IsRunningAsUwp())
                {
                    _startupManager = new DesktopBridgeStartupManager(AppName);
                }
                else
                {
                    string path = Assembly.GetEntryAssembly().Location.Replace(".dll", ".exe");
                    _startupManager = new DesktopStartupHelper(AppName, path);
                }

                await ApplySetting(UserSetting);

                if (RunningData.CurrentWalpapers != null)
                {
                    foreach (var item in RunningData.CurrentWalpapers)
                    {
                        await WallpaperApi.ShowWallpaper(item.Value, item.Key);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error($"WallpaperStore constructor Ex:{ex}");
            }
            finally
            {
                Initialized = true;
            }
        }
        public async Task <BaseApiResult <WallpaperModel> > ShowWallpaper(string path, string targetScreen)
        {
            if (AppManager.PlayerDownloader.IsBusy)
            {
                return(BaseApiResult <WallpaperModel> .ErrorState(ErrorType.NoPlayer, null, null));
            }

            var model = await WallpaperApi.ShowWallpaper(path, targetScreen);

            await AppManager.SaveCurrentWalpapers();

            return(model);
        }
Exemple #5
0
 public Task <BaseApiResult <WallpaperModel> > ShowWallpaper(string path)
 {
     return(WallpaperApi.ShowWallpaper(path));
 }
Exemple #6
0
        private async void BtnSelect_Click(object sender, RoutedEventArgs e)
        {
            //System.Diagnostics.Debug.WriteLine("before ShowWallpaper " + GetActiveWindowTitle());
            using (var openFileDialog = new OpenFileDialog())
            {
                openFileDialog.InitialDirectory = "WallpaperSamples";
                openFileDialog.Filter           = "All files (*.*)|*.*";

                if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    var displayScreen = monitorsVM.Where(m => m.Checked).Select(m => m.DeviceName).ToArray();
                    BtnApply_Click(null, null);
                    var showResult = await WallpaperApi.ShowWallpaper(openFileDialog.FileName, displayScreen);

                    var wp = showResult.Data;
                    if (!showResult.Ok)
                    {
                        if (showResult.Error == ErrorType.NoPlayer)
                        {
                            var r = System.Windows.MessageBox.Show($"{showResult.Error} {showResult.Message}, Whether to download the player?", "", MessageBoxButton.OKCancel);
                            if (r == MessageBoxResult.OK)
                            {
                                popup.Visibility = Visibility.Visible;
                                txtPopup.Text    = "downloading...";
                                var url = WallpaperApi.PlayerUrls.FirstOrDefault(m => m.Type == wp.RunningData.Type).DownloadUrl;

                                void WallpaperManager_SetupPlayerProgressChangedEvent(object sender, SetupPlayerProgressChangedArgs e)
                                {
                                    Dispatcher.BeginInvoke(new Action(async() =>
                                    {
                                        txtPopup.Text = $"{(e.ActionType == SetupPlayerProgressChangedArgs.Type.Unpacking ? "unpacking" : "downloading")} ... {(int)(e.ProgressPercentage * 100)}%";

                                        if (e.AllCompleted)
                                        {
                                            WallpaperApi.SetupPlayerProgressChangedEvent -= WallpaperManager_SetupPlayerProgressChangedEvent;
                                            popup.Visibility = Visibility.Collapsed;

                                            if (e.Result.Ok)
                                            {
                                                showResult = await WallpaperApi.ShowWallpaper(wp, displayScreen);
                                            }
                                            else
                                            {
                                                System.Windows.Forms.MessageBox.Show($"Message:{e.Result.Message},Error:{e.Result.Error}");
                                            }
                                        }
                                    }));
                                }

                                WallpaperApi.SetupPlayerProgressChangedEvent -= WallpaperManager_SetupPlayerProgressChangedEvent;
                                WallpaperApi.SetupPlayerProgressChangedEvent += WallpaperManager_SetupPlayerProgressChangedEvent;

                                var setupResult = WallpaperApi.SetupPlayer(wp.RunningData.Type.Value, url);
                            }
                        }
                        else
                        {
                            System.Windows.MessageBox.Show($"{showResult.Error} {showResult.Message} ");
                        }
                    }
                }
            }
            //System.Diagnostics.Debug.WriteLine("after ShowWallpaper" + GetActiveWindowTitle());
            //IntPtr progman = User32Wrapper.FindWindow("Progman", null);
            //User32Wrapper.SetForegroundWindow(window); //change focus from the started window//application.
            //User32Wrapper.SetFocus(window);
            Activate();
        }