Beispiel #1
0
        private void BtnApply_Click(object sender, RoutedEventArgs e)
        {
            var vm      = (ConfigerViewModel)configer.DataContext;
            var setting = ConfigerService.GetData <LiveWallpaperOptions>(vm.Nodes);

            _ = WallpaperApi.SetOptions(setting);
        }
        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);
                }

                var result = await WallpaperApi.SetOptions(UserSetting.Wallpaper);
            }
            catch (Exception ex)
            {
                logger.Error($"WallpaperStore constructor Ex:{ex}");
            }
            finally
            {
                Initialized = true;
            }
        }
        public async Task <BaseApiResult> SetUserSetting(UserSetting setting)
        {
            await AppManager.WaitInitialized();

            try
            {
                var result = await WallpaperApi.SetOptions(setting.Wallpaper);

                //成功设置后保存,防止有异常导致启动崩溃
                await AppManager.SaveUserSetting(setting);

                return(result);
            }
            catch (Exception ex)
            {
                return(BaseApiResult.ExceptionState(ex));
            }
        }
Beispiel #4
0
        private static async Task ApplySetting(UserSetting setting)
        {
            //设置开机启动
            _ = await _startupManager.Set(setting.General.StartWithSystem);

            // 更新开机启动结果
            if (setting?.General?.StartWithSystem != null)
            {
                setting.General.StartWithSystem = await _startupManager.Check();
            }

            string ffmpegSaveDir = FFmpegSaveDir;

            if (_FFMpegDownloader != null)
            {
                _FFMpegDownloader.DistDir = ffmpegSaveDir;
            }

            ProcessHelper.AddPathToEnvoirment(ffmpegSaveDir);

            //设置壁纸参数
            _ = await WallpaperApi.SetOptions(setting.Wallpaper);
        }