public Task <BaseApiResult> ShowWallpaper(string path) { return(WallpaperApi.ShowWallpaper(new WallpaperModel() { Path = path })); }
public async Task <WallpaperModel> CreateWallpaperDraft(IFormCollection fc) { if (fc != null && fc.Files.Count > 0 && fc.Files[0].Length > 0) { var formFile = fc.Files[0]; var info = new WallpaperProjectInfo() { File = formFile.FileName }; var targetDir = await WallpaperApi.CreateWallpaperDraft(AppManager.UserSetting.Wallpaper.WallpaperSaveDir, info); var distFile = Path.Combine(targetDir, formFile.FileName); using var stream = System.IO.File.Create(distFile); await formFile.CopyToAsync(stream); var r = WallpaperApi.CreateWallpaperModel(distFile); if (string.IsNullOrEmpty(r.Info.Title)) { int lastIndex = r.Info.File.LastIndexOf("."); r.Info.Title = r.Info.File.Remove(lastIndex); } return(r); } return(null); }
private void InitializeAppContextComponent() { _components = new System.ComponentModel.Container(); _contextMenu = new ContextMenuStrip(); _btnMainUI = new ToolStripMenuItem() { Text = "打开Web控制台" }; _btnMainUI.Click += BtnMainUI_Click; _contextMenu.Items.Add(_btnMainUI); _btnExit = new ToolStripMenuItem { Text = "退出", }; _btnExit.Click += BtnExit_Click; _contextMenu.Items.Add(_btnExit); _notifyIcon = new NotifyIcon(_components) { Icon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location), ContextMenuStrip = _contextMenu, Text = "巨应壁纸", Visible = true }; _notifyIcon.MouseClick += new MouseEventHandler(NotifyIcon_MouseClick); WallpaperApi.Initlize(Dispatcher.CurrentDispatcher); Task.Run(() => { int port = GetPort(); ServerWrapper.Start(port); }); }
private void BtnApply_Click(object sender, RoutedEventArgs e) { var vm = (ConfigerViewModel)configer.DataContext; var setting = ConfigerService.GetData <LiveWallpaperOptions>(vm.Nodes); _ = WallpaperApi.SetOptions(setting); }
private async void BtnStop_Click(object sender, RoutedEventArgs e) { var activeWindowTitle = GetActiveWindowTitle(); //System.Diagnostics.Debug.WriteLine("btnStop_Click " + activeWindowTitle); var displayIds = monitorsVM.Where(m => m.Checked).Select(m => m.DeviceName).ToArray(); await WallpaperApi.CloseWallpaper(displayIds); }
internal void ShowWallpaper(IntPtr wallpaperHandle) { IntPtr hostForm = IntPtr.Zero; WallpaperApi.UIInvoke(() => { try { Controls.Clear(); Opacity = 1; hostForm = Handle; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine($"ShowWallpaper ex:{ex}"); } }); //hostfrom下潜桌面 WallpaperHelper.GetInstance(_screenName).SendToBackground(hostForm); //壁纸parent改为hostform User32Wrapper.SetParent(wallpaperHandle, hostForm); //把壁纸全屏铺满 hostform WallpaperHelper.FullScreen(wallpaperHandle, hostForm); }
public async Task <BaseApiResult <WallpaperModel> > GetWallpaper(string path) { await AppManager.WaitInitialized(); var result = await WallpaperApi.GetWallpaper(path); return(result); }
public async Task <BaseApiResult <WallpaperModel> > ShowWallpaper(string path) { var model = await WallpaperApi.ShowWallpaper(path); await AppManager.SaveCurrentWalpapers(); return(model); }
public async Task <BaseApiResult <List <WallpaperModel> > > GetWallpapers() { await AppManager.WaitInitialized(); var result = await WallpaperApi.GetWallpapers(AppManager.UserSetting.Wallpaper.WallpaperSaveDir); return(result); }
public Task <BaseApiResult> CloseWallpaper(string[] screen) { if (screen == null) { screen = WallpaperApi.Screens; } return(WallpaperApi.CloseWallpaper(screen)); }
//删除整个壁纸目录 public async Task <BaseApiResult> DeleteWallpaper(string path) { string dir = Path.GetDirectoryName(path); //不能删除非壁纸目录的文件 if (!dir.Contains(AppManager.UserSetting.Wallpaper.WallpaperSaveDir)) { return(BaseApiResult.ErrorState(ErrorType.Failed)); } return(await WallpaperApi.DeleteWallpaper(path)); }
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); }
public async Task <BaseApiResult> UpdateWallpaperOption(string destDir, WallpaperOption option) { try { await WallpaperApi.UpdateWallpaperOption(destDir, option); return(BaseApiResult.SuccessState()); } catch (Exception ex) { return(BaseApiResult.ExceptionState(ex)); } }
public async Task <BaseApiResult <WallpaperOption> > GetWallpaperOption(string wallpaperDir) { try { var res = await WallpaperApi.GetWallpaperOption(wallpaperDir, new WallpaperOption()); return(BaseApiResult <WallpaperOption> .SuccessState(res)); } catch (Exception ex) { return(BaseApiResult <WallpaperOption> .ExceptionState(ex)); } }
public async Task <BaseApiResult> UpdateProjectInfo(string destDir, WallpaperProjectInfo info) { try { await WallpaperApi.UpdateProjectInfo(destDir, info); return(BaseApiResult.SuccessState()); } catch (Exception ex) { return(BaseApiResult.ExceptionState(ex)); } }
public AppContext() { _uiDispatcher = Dispatcher.CurrentDispatcher; InitializeUI(); WallpaperApi.Initlize(_uiDispatcher); AppManager.CultureChanged += LanService_CultureChanged; SetMenuText(); _ = Task.Run(() => { int port = GetPort(); ServerWrapper.Start(port); }); CheckMutex(); }
public BaseApiResult SetupPlayer(WallpaperType wpType, string customDownloadUrl) { string url = customDownloadUrl; if (string.IsNullOrEmpty(url)) { url = WallpaperApi.PlayerUrls.FirstOrDefault(m => m.Type == wpType).DownloadUrl; } void WallpaperManager_SetupPlayerProgressChangedEvent(object sender, SetupPlayerProgressChangedArgs e) { _lastSetupPlayerRaiseLimiter.Execute(async() => { try { System.Diagnostics.Debug.WriteLine($"{e.ProgressPercentage} {e.ActionType}"); //向所有客户端推送,刷新后也能显示 var client = _hubEventEmitter.AllClient(); await client.SendAsync("SetupPlayerProgressChanged", e); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } }, 1000); } _lastSetupPlayerRaiseLimiter = new RaiseLimiter(); WallpaperApi.SetupPlayerProgressChangedEvent -= WallpaperManager_SetupPlayerProgressChangedEvent; WallpaperApi.SetupPlayerProgressChangedEvent += WallpaperManager_SetupPlayerProgressChangedEvent; var result = WallpaperApi.SetupPlayer(wpType, url, (async _ => { //设置完成 await _lastSetupPlayerRaiseLimiter.WaitExit(); WallpaperApi.SetupPlayerProgressChangedEvent -= WallpaperManager_SetupPlayerProgressChangedEvent; })); if (result.Ok) { //开始成功 //_lastSetupPlayerRaiseLimiter = new RaiseLimiter(); //WallpaperApi.SetupPlayerProgressChangedEvent += WallpaperManager_SetupPlayerProgressChangedEvent; //_lastConnectionId = Context.ConnectionId; } return(result); }
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)); } }
public async Task <BaseApiResult <string> > GetDraftDir() { string lastDraftPath = AppManager.RunningData.LastDraftPath; if (!string.IsNullOrEmpty(lastDraftPath)) { string projectPath = Path.Combine(lastDraftPath, "project.json"); if (!File.Exists(projectPath) && Directory.Exists(lastDraftPath)) { await Task.Run(() => { var files = Directory.GetFiles(lastDraftPath); foreach (var file in files) { try { //删除老文件 File.Delete(file); } catch (Exception ex) { Debug.WriteLine(ex); continue; } } }); //返回上一次的临时目录,防止创建太多无用目录 return(BaseApiResult <string> .SuccessState(lastDraftPath)); } } var r = WallpaperApi.GetDraftDir(AppManager.UserSetting.Wallpaper.WallpaperSaveDir); AppManager.RunningData.LastDraftPath = r; await AppManager.SaveRunningData(AppManager.RunningData); return(BaseApiResult <string> .SuccessState(r)); }
public static LiveWallpaperRenderForm GetHost(string screen, bool autoCreate = true) { if (!_hosts.ContainsKey(screen)) { if (autoCreate) { WallpaperApi.UIInvoke(() => { var host = _hosts[screen] = new LiveWallpaperRenderForm(screen); host.Show(); }); } } if (_hosts.ContainsKey(screen)) { return(_hosts[screen]); } else { return(null); } }
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); }
public Task <BaseApiResult> DeleteWallpaper(string path) { return(WallpaperApi.DeleteWallpaper(path)); }
private async void BtnCancelSetupPlayer_Click(object sender, RoutedEventArgs e) { _ = await WallpaperApi.StopSetupPlayer(); popup.Visibility = Visibility.Collapsed; }
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(); }
public MainWindow() { Activated += MainWindow_Activated; Deactivated += MainWindow_Deactivated; WallpaperApi.Initlize(Dispatcher); InitializeComponent(); monitors.ItemsSource = monitorsVM = Screen.AllScreens.Select(m => new Monitor() { DeviceName = m.DeviceName, Checked = true }).ToList(); var audioOption = Screen.AllScreens.Select(m => new DescriptorInfo() { Text = m.DeviceName, DefaultValue = m.DeviceName }).ToList(); audioOption.Insert(0, new DescriptorInfo() { Text = "Disabled", DefaultValue = null }); var screenSetting = Screen.AllScreens.Select(m => new ScreenOption() { Screen = m.DeviceName, WhenAppMaximized = ActionWhenMaximized.Pause, }).ToList(); var screenSettingOptions = new List <DescriptorInfo>() { new DescriptorInfo() { Text = "Play", DefaultValue = ActionWhenMaximized.Play }, new DescriptorInfo() { Text = "Pause", DefaultValue = ActionWhenMaximized.Pause }, new DescriptorInfo() { Text = "Stop", DefaultValue = ActionWhenMaximized.Stop }, }; var descInfo = new DescriptorInfoDict() { { nameof(LiveWallpaperOptions), new DescriptorInfo() { Text = "Wallpaper Settings", PropertyDescriptors = new DescriptorInfoDict() { { nameof(LiveWallpaperOptions.AudioScreen), new DescriptorInfo() { Text = "Audio Source", Type = PropertyType.Combobox, Options = new ObservableCollection <DescriptorInfo>(audioOption), DefaultValue = null, } }, //{ // nameof(LiveWallpaperOptions.AutoRestartWhenExplorerCrash), // new DescriptorInfo(){ // Text="崩溃后自动恢复", // DefaultValue=true, //}}, { nameof(LiveWallpaperOptions.AppMaximizedEffectAllScreen), new DescriptorInfo() { Text = "Full screen detection affects all screens", DefaultValue = true, } }, { nameof(LiveWallpaperOptions.ForwardMouseEvent), new DescriptorInfo() { Text = "Forward mouse event", DefaultValue = true, } }, { nameof(LiveWallpaperOptions.ScreenOptions), new DescriptorInfo() { Text = "Display Settings", Type = PropertyType.List, CanAddItem = false, CanRemoveItem = false, DefaultValue = screenSetting, PropertyDescriptors = new DescriptorInfoDict() { { nameof(ScreenOption.Screen), new DescriptorInfo() { Text = "Screen", Type = PropertyType.Label } }, { nameof(ScreenOption.WhenAppMaximized), new DescriptorInfo() { Text = "When other programs are maximized", Options = new ObservableCollection <DescriptorInfo>(screenSettingOptions) } } } } }, } } } }; var setting = new LiveWallpaperOptions() { ScreenOptions = screenSetting }; var vm = ConfigerService.GetVM(setting, descInfo); configer.DataContext = vm; }
//下载壁纸 public Task <BaseApiResult> DownloadWallpaper(string wallpaper, string cover, WallpaperProjectInfo info) { if (wallpaper == null) { return(Task.FromResult(BaseApiResult.ErrorState(ErrorType.Failed))); } string destFolder = null; if (info != null && info.ID != null) { destFolder = Path.Combine(AppManager.UserSetting.Wallpaper.WallpaperSaveDir, info.ID); } else { destFolder = WallpaperApi.GetDraftDir(AppManager.UserSetting.Wallpaper.WallpaperSaveDir); } if (info == null) { info = new WallpaperProjectInfo(); } CancellationTokenSource cts = new(); _ = Task.Run(async() => { RaiseLimiter _raiseLimiter = new(); var wpProgressInfo = new Progress <(float competed, float total)>((e) => { _raiseLimiter.Execute(async() => { var client = _hubEventEmitter.AllClient(); await client.SendAsync("DownloadWallpaperProgressChanged", new { path = wallpaper, e.competed, e.total, percent = e.competed / e.total * 90, completed = false }); }, 1000); }); var coverProgressInfo = new Progress <(float competed, float total)>((e) => { _raiseLimiter.Execute(async() => { var client = _hubEventEmitter.AllClient(); var percent = e.competed / e.total * 10 + 90; await client.SendAsync("DownloadWallpaperProgressChanged", new { path = cover, e.competed, e.total, percent, completed = percent == 100 }); }, 1000); }); info.File = Path.GetFileName(wallpaper); string destWp = Path.Combine(destFolder, info.File); await NetworkHelper.DownloadFileAsync(wallpaper, destWp, cts.Token, wpProgressInfo); if (cover != null) { info.Preview = Path.GetFileName(cover); string destCover = Path.Combine(destFolder, info.Preview); await NetworkHelper.DownloadFileAsync(cover, destCover, cts.Token, coverProgressInfo); } //生成json await UpdateProjectInfo(destFolder, info); }); return(Task.FromResult(BaseApiResult.SuccessState())); }
public Task <BaseApiResult> StopSetupPlayer() { return(WallpaperApi.StopSetupPlayer()); }
public Task <BaseApiResult <WallpaperModel> > ShowWallpaper(string path) { return(WallpaperApi.ShowWallpaper(path)); }
public BaseApiResult SetupPlayerByPath(string wallpaperPath, string customDownloadUrl) { var wpType = WallpaperApi.GetWallpaperType(wallpaperPath); return(SetupPlayer(wpType, customDownloadUrl)); }