| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086 |
- using System.Runtime.InteropServices;
- using Avalonia;
- using Avalonia.Controls.ApplicationLifetimes;
- using Avalonia.Threading;
- using PicView.Avalonia.Clipboard;
- using PicView.Avalonia.ColorManagement;
- using PicView.Avalonia.Crop;
- using PicView.Avalonia.FileSystem;
- using PicView.Avalonia.Gallery;
- using PicView.Avalonia.ImageHandling;
- using PicView.Avalonia.ImageTransformations;
- using PicView.Avalonia.Navigation;
- using PicView.Avalonia.SettingsManagement;
- using PicView.Avalonia.ViewModels;
- using PicView.Avalonia.WindowBehavior;
- using PicView.Core.Config;
- using PicView.Core.FileHandling;
- using PicView.Core.ImageDecoding;
- using PicView.Core.ProcessHandling;
- namespace PicView.Avalonia.UI;
- public static class FunctionsHelper
- {
- public static MainViewModel? Vm;
- public static Task<Func<Task>> GetFunctionByName(string functionName)
- {
- // Remember to have exact matching names, or it will be null
- return Task.FromResult<Func<Task>>(functionName switch
- {
- // Navigation values
- "Next" => Next,
- "Prev" => Prev,
- "NextFolder" => NextFolder,
- "PrevFolder" => PrevFolder,
- "Up" => Up,
- "Down" => Down,
- "Last" => Last,
- "First" => First,
- "Next10" => Next10,
- "Prev10" => Prev10,
- "Next100" => Next100,
- "Prev100" => Prev100,
-
- // Rotate
- "RotateLeft" => RotateLeft,
- "RotateRight" => RotateRight,
- // Scroll
- "ScrollUp" => ScrollUp,
- "ScrollDown" => ScrollDown,
- "ScrollToTop" => ScrollToTop,
- "ScrollToBottom" => ScrollToBottom,
- // Zoom
- "ZoomIn" => ZoomIn,
- "ZoomOut" => ZoomOut,
- "ResetZoom" => ResetZoom,
- "ChangeCtrlZoom" => ChangeCtrlZoom,
- // Toggles
- "ToggleScroll" => ToggleScroll,
- "ToggleLooping" => ToggleLooping,
- "ToggleGallery" => ToggleGallery,
- // Scale Window
- "AutoFitWindow" => AutoFitWindow,
- "AutoFitWindowAndStretch" => AutoFitWindowAndStretch,
- "NormalWindow" => NormalWindow,
- "NormalWindowAndStretch" => NormalWindowAndStretch,
- // Window functions
- "Fullscreen" => Fullscreen,
- "ToggleFullscreen" => ToggleFullscreen,
- "SetTopMost" => SetTopMost,
- "Close" => Close,
- "ToggleInterface" => ToggleInterface,
- "NewWindow" => NewWindow,
- "Center" => Center,
- // Windows
- "AboutWindow" => AboutWindow,
- "EffectsWindow" => EffectsWindow,
- "ImageInfoWindow" => ImageInfoWindow,
- "ResizeWindow" => ResizeWindow,
- "SettingsWindow" => SettingsWindow,
- "KeybindingsWindow" => KeybindingsWindow,
- // Open functions
- "Open" => Open,
- "OpenWith" => OpenWith,
- "OpenInExplorer" => OpenInExplorer,
- "Save" => Save,
- "SaveAs" => SaveAs,
- "Print" => Print,
- "Reload" => Reload,
- // Copy functions
- "CopyFile" => CopyFile,
- "CopyFilePath" => CopyFilePath,
- "CopyImage" => CopyImage,
- "CopyBase64" => CopyBase64,
- "DuplicateFile" => DuplicateFile,
- "CutFile" => CutFile,
- "Paste" => Paste,
- // File functions
- "DeleteFile" => DeleteFile,
- "DeleteFilePermanently" => DeleteFilePermanently,
- "Rename" => Rename,
- "ShowFileProperties" => ShowFileProperties,
- // Image functions
- "ResizeImage" => ResizeImage,
- "Crop" => Crop,
- "Flip" => Flip,
- "OptimizeImage" => OptimizeImage,
- "Stretch" => Stretch,
- // Set stars
- "Set0Star" => Set0Star,
- "Set1Star" => Set1Star,
- "Set2Star" => Set2Star,
- "Set3Star" => Set3Star,
- "Set4Star" => Set4Star,
- "Set5Star" => Set5Star,
-
- // Background and lock screen image
- "SetAsLockScreen" => SetAsLockScreen,
- "SetAsLockscreenCentered" => SetAsLockscreenCentered,
- "SetAsWallpaper" => SetAsWallpaper,
- "SetAsWallpaperFitted" => SetAsWallpaperFitted,
- "SetAsWallpaperStretched" => SetAsWallpaperStretched,
- "SetAsWallpaperFilled" => SetAsWallpaperFilled,
- "SetAsWallpaperCentered" => SetAsWallpaperCentered,
- "SetAsWallpaperTiled" => SetAsWallpaperTiled,
- // Misc
- "ChangeBackground" => ChangeBackground,
- "SideBySide" => SideBySide,
- "GalleryClick" => GalleryClick,
- "Slideshow" => Slideshow,
- "ColorPicker" => ColorPicker,
- "Restart" => Restart,
- _ => null
- });
- }
- #region Functions
- #region Menus
- public static Task CloseMenus()
- {
- if (Vm is null)
- {
- return Task.CompletedTask;
- }
- UIHelper.CloseMenus(Vm);
- return Task.CompletedTask;
- }
- public static Task ToggleFileMenu()
- {
- if (Vm is null)
- {
- return Task.CompletedTask;
- }
- UIHelper.ToggleFileMenu(Vm);
- return Task.CompletedTask;
- }
- public static Task ToggleImageMenu()
- {
- if (Vm is null)
- {
- return Task.CompletedTask;
- }
- UIHelper.ToggleImageMenu(Vm);
- return Task.CompletedTask;
- }
- public static Task ToggleSettingsMenu()
- {
- if (Vm is null)
- {
- return Task.CompletedTask;
- }
- UIHelper.ToggleSettingsMenu(Vm);
- return Task.CompletedTask;
- }
- public static Task ToggleToolsMenu()
- {
- if (Vm is null)
- {
- return Task.CompletedTask;
- }
- UIHelper.ToggleToolsMenu(Vm);
- return Task.CompletedTask;
- }
- #endregion Menus
- #region Navigation, zoom and rotation
- public static async Task Next()
- {
- await NavigationHelper.Iterate(next: true, Vm);
- }
-
- public static async Task NextFolder()
- {
- await NavigationHelper.GoToNextFolder(true, Vm);
- }
-
- public static async Task Last()
- {
- await NavigationHelper.NavigateFirstOrLast(last: true, Vm);
- }
- public static async Task Prev()
- {
- await NavigationHelper.Iterate(next: false, Vm);
- }
-
- public static async Task PrevFolder()
- {
- await NavigationHelper.GoToNextFolder(false, Vm);
- }
- public static async Task First()
- {
- await NavigationHelper.NavigateFirstOrLast(last: false, Vm);
- }
-
- public static async Task Next10()
- {
- await NavigationHelper.Next10(Vm).ConfigureAwait(false);
- }
-
- public static async Task Next100()
- {
- await NavigationHelper.Next100(Vm).ConfigureAwait(false);
- }
-
- public static async Task Prev10()
- {
- await NavigationHelper.Prev10(Vm).ConfigureAwait(false);
- }
-
- public static async Task Prev100()
- {
- await NavigationHelper.Prev100(Vm).ConfigureAwait(false);
- }
-
- public static async Task Up()
- {
- await UIHelper.NavigateUp(Vm);
- }
- public static async Task RotateRight()
- {
- await Rotation.RotateRight(Vm);
- }
- public static async Task RotateLeft()
- {
- await Rotation.RotateLeft(Vm);
- }
- public static async Task Down()
- {
- await UIHelper.NavigateDown(Vm);
- }
-
- public static async Task ScrollDown()
- {
- await Dispatcher.UIThread.InvokeAsync(() =>
- {
- Vm.ImageViewer.ImageScrollViewer.LineDown();
- });
- }
-
- public static async Task ScrollUp()
- {
- await Dispatcher.UIThread.InvokeAsync(() =>
- {
- Vm.ImageViewer.ImageScrollViewer.LineUp();
- });
- }
- public static async Task ScrollToTop()
- {
- await Dispatcher.UIThread.InvokeAsync(() =>
- {
- Vm.ImageViewer.ImageScrollViewer.ScrollToHome();
- });
- }
- public static async Task ScrollToBottom()
- {
- await Dispatcher.UIThread.InvokeAsync(() =>
- {
- Vm.ImageViewer.ImageScrollViewer.ScrollToEnd();
- });
- }
- public static async Task ZoomIn()
- {
- if (Vm is null)
- {
- return;
- }
- await Dispatcher.UIThread.InvokeAsync(Vm.ImageViewer.ZoomIn);
- }
- public static async Task ZoomOut()
- {
- if (Vm is null)
- {
- return;
- }
- await Dispatcher.UIThread.InvokeAsync(Vm.ImageViewer.ZoomOut);
- }
- public static async Task ResetZoom()
- {
- if (Vm is null)
- {
- return;
- }
- await Dispatcher.UIThread.InvokeAsync(() => Vm.ImageViewer.ResetZoom(true));
- }
-
- #endregion
- #region Toggle UI functions
- public static async Task ToggleScroll()
- {
- await SettingsUpdater.ToggleScroll(Vm).ConfigureAwait(false);
- }
- public static async Task ChangeCtrlZoom()
- {
- await SettingsUpdater.ToggleCtrlZoom(Vm);
- }
- public static async Task ToggleLooping()
- {
- await SettingsUpdater.ToggleLooping(Vm);
- }
-
- public static async Task ToggleInterface()
- {
- await HideInterfaceLogic.ToggleUI(Vm);
- }
-
- public static async Task ToggleSubdirectories()
- {
- await SettingsUpdater.ToggleSubdirectories(vm: Vm);
- }
-
- public static async Task ToggleBottomToolbar()
- {
- if (Vm is null)
- {
- return;
- }
- await HideInterfaceLogic.ToggleBottomToolbar(Vm);
- }
-
- public static async Task ToggleTaskbarProgress()
- {
- await SettingsUpdater.ToggleTaskbarProgress(Vm);
- }
-
- #endregion
- #region Gallery functions
- public static async Task ToggleGallery()
- {
- await GalleryFunctions.ToggleGallery(Vm).ConfigureAwait(false);
- }
- public static async Task OpenCloseBottomGallery()
- {
- await GalleryFunctions.OpenCloseBottomGallery(Vm).ConfigureAwait(false);
- }
-
- public static async Task CloseGallery()
- {
- await GalleryFunctions.CloseGallery(Vm);
- }
-
- public static async Task GalleryClick()
- {
- await GalleryNavigation.GalleryClick(Vm);
- }
- #endregion
-
- #region Windows and window functions
- public static async Task ShowStartUpMenu()
- {
- await Dispatcher.UIThread.InvokeAsync(() =>
- {
- ErrorHandling.ShowStartUpMenu(Vm);
- });
- }
-
- public static async Task Close()
- {
- if (Vm is null)
- {
- return;
- }
- await UIHelper.Close(Vm);
- }
-
- public static async Task Center()
- {
- // TODO: scroll to center when the gallery is open
- await Dispatcher.UIThread.InvokeAsync(() =>
- {
- WindowFunctions.CenterWindowOnScreen();
- });
- }
- public static async Task NewWindow()
- {
- await Task.Run(ProcessHelper.StartNewProcess);
- }
- public static Task AboutWindow()
- {
- Vm?.PlatformService?.ShowAboutWindow();
- return Task.CompletedTask;
- }
- public static Task KeybindingsWindow()
- {
- Vm?.PlatformService?.ShowKeybindingsWindow();
- return Task.CompletedTask;
- }
- public static Task EffectsWindow()
- {
- Vm?.PlatformService?.ShowEffectsWindow();
- return Task.CompletedTask;
- }
- public static Task ImageInfoWindow()
- {
- Vm.PlatformService.ShowExifWindow();
- return Task.CompletedTask;
- }
- public static Task ResizeWindow()
- {
- Vm?.PlatformService?.ShowSingleImageResizeWindow();
- return Task.CompletedTask;
- }
- public static Task SettingsWindow()
- {
- Vm?.PlatformService.ShowSettingsWindow();
- return Task.CompletedTask;
- }
-
- #endregion Windows
- #region Image Scaling and Window Behavior
-
- public static async Task Stretch()
- {
- await WindowFunctions.Stretch(Vm);
- }
- public static async Task AutoFitWindow()
- {
- await WindowFunctions.ToggleAutoFit(Vm);
- }
- public static async Task AutoFitWindowAndStretch()
- {
- await WindowFunctions.AutoFitAndStretch(Vm);
- }
- public static async Task NormalWindow()
- {
- await WindowFunctions.NormalWindow(Vm);
- }
- public static async Task NormalWindowAndStretch()
- {
- await WindowFunctions.NormalWindowStretch(Vm);
- }
- public static async Task ToggleFullscreen()
- {
- if (Vm is null)
- {
- return;
- }
- await WindowFunctions.ToggleFullscreen(Vm);
- }
-
- public static Task Fullscreen()
- {
- if (Vm is null)
- {
- return Task.CompletedTask;
- }
- WindowFunctions.Fullscreen(Vm, Application.Current?.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime);
- return Task.CompletedTask;
- }
- public static async Task SetTopMost()
- {
- if (Vm is null)
- {
- return;
- }
- await WindowFunctions.ToggleTopMost(Vm);
- }
- #endregion
- #region File funnctions
- public static async Task OpenLastFile()
- {
- if (Vm is null)
- {
- return;
- }
- await FileHistoryNavigation.OpenLastFileAsync(Vm).ConfigureAwait(false);
- }
- public static async Task OpenPreviousFileHistoryEntry()
- {
- if (Vm is null)
- {
- return;
- }
- await FileHistoryNavigation.PrevAsync(Vm).ConfigureAwait(false);
- }
- public static async Task OpenNextFileHistoryEntry()
- {
- if (Vm is null)
- {
- return;
- }
- await FileHistoryNavigation.NextAsync(Vm).ConfigureAwait(false);
- }
-
- public static async Task Print()
- {
- await Task.Run(() =>
- {
- Vm?.PlatformService?.Print(Vm.FileInfo?.FullName);
- });
- }
- public static async Task Open()
- {
- await FilePicker.SelectAndLoadFile(Vm);
- }
- public static Task OpenWith()
- {
- Vm?.PlatformService?.OpenWith(Vm.FileInfo?.FullName);
- return Task.CompletedTask;
- }
- public static Task OpenInExplorer()
- {
- Vm?.PlatformService?.LocateOnDisk(Vm.FileInfo?.FullName);
- return Task.CompletedTask;
- }
- public static async Task Save()
- {
- await FileSaverHelper.SaveCurrentFile(Vm);
- }
-
- public static async Task SaveAs()
- {
- await FileSaverHelper.SaveFileAs(Vm);
- }
-
- public static async Task DeleteFile()
- {
- if (Vm is null)
- {
- return;
- }
- await FileManager.DeleteFile(true, Vm);
- }
-
- public static async Task DeleteFilePermanently()
- {
- if (Vm is null)
- {
- return;
- }
- await FileManager.DeleteFile(false, Vm);
- }
- public static async Task Rename()
- {
- await Dispatcher.UIThread.InvokeAsync(() =>
- {
- UIHelper.GetEditableTitlebar.SelectFileName();
- });
- }
-
- public static async Task ShowFileProperties()
- {
- await Task.Run(() => Vm?.PlatformService?.ShowFileProperties(Vm.FileInfo?.FullName));
- }
-
- #endregion
- #region Copy and Paste functions
- public static async Task CopyFile()
- {
- await ClipboardHelper.CopyFileToClipboard(Vm?.FileInfo?.FullName, Vm);
- }
- public static async Task CopyFilePath()
- {
- await ClipboardHelper.CopyTextToClipboard(Vm?.FileInfo?.FullName);
- }
- public static async Task CopyImage()
- {
- if (Vm is null)
- {
- return;
- }
- await ClipboardHelper.CopyImageToClipboard(Vm);
- }
- public static async Task CopyBase64()
- {
- if (Vm is null)
- {
- return;
- }
- await ClipboardHelper.CopyBase64ToClipboard(Vm.FileInfo?.FullName, vm: Vm);
- }
- public static async Task DuplicateFile()
- {
- await NavigationHelper.DuplicateAndNavigate(Vm).ConfigureAwait(false);
- }
- public static async Task CutFile()
- {
- if (Vm is null)
- {
- return;
- }
- await ClipboardHelper.CutFile(Vm.FileInfo.FullName, Vm);
- }
- public static async Task Paste()
- {
- if (Vm is null)
- {
- return;
- }
- await ClipboardHelper.Paste(Vm);
- }
-
- #endregion
- #region Image Functions
-
- public static async Task ChangeBackground()
- {
- if (Vm is null)
- {
- return;
- }
-
- BackgroundManager.ChangeBackground(Vm);
- await SettingsHelper.SaveSettingsAsync();
- }
-
- public static async Task SideBySide()
- {
- await SettingsUpdater.ToggleSideBySide(Vm);
- }
-
- public static async Task Reload()
- {
- if (Vm is null)
- {
- return;
- }
- await ErrorHandling.ReloadAsync(Vm);
- }
- public static Task ResizeImage()
- {
- Vm?.PlatformService?.ShowSingleImageResizeWindow();
- return Task.CompletedTask;
- }
- public static async Task Crop()
- {
- await Dispatcher.UIThread.InvokeAsync(() => CropFunctions.Init(Vm));
- }
- public static Task Flip()
- {
- ImageControl.Flip(Vm);
- return Task.CompletedTask;
- }
- public static async Task OptimizeImage()
- {
- await ImageHelper.OptimizeImage(Vm);
- }
- public static async Task Slideshow()
- {
- await Navigation.Slideshow.StartSlideshow(Vm);
- }
- public static Task ColorPicker()
- {
- return Task.CompletedTask;
- }
-
- #endregion
- #region Sorting
- public static async Task SortFilesByName()
- {
- if (Vm?.PlatformService is null)
- {
- return;
- }
- await FileListManager.UpdateFileList(Vm.PlatformService, Vm, FileListHelper.SortFilesBy.Name);
- }
- public static async Task SortFilesByCreationTime()
- {
- if (Vm?.PlatformService is null)
- {
- return;
- }
- await FileListManager.UpdateFileList(Vm?.PlatformService, Vm, FileListHelper.SortFilesBy.CreationTime);
- }
- public static async Task SortFilesByLastAccessTime()
- {
- if (Vm?.PlatformService is null)
- {
- return;
- }
- await FileListManager.UpdateFileList(Vm?.PlatformService, Vm, FileListHelper.SortFilesBy.LastAccessTime);
- }
- public static async Task SortFilesByLastWriteTime()
- {
- if (Vm?.PlatformService is null)
- {
- return;
- }
- await FileListManager.UpdateFileList(Vm?.PlatformService, Vm, FileListHelper.SortFilesBy.LastWriteTime);
- }
- public static async Task SortFilesBySize()
- {
- if (Vm?.PlatformService is null)
- {
- return;
- }
- await FileListManager.UpdateFileList(Vm?.PlatformService, Vm, FileListHelper.SortFilesBy.FileSize);
- }
- public static async Task SortFilesByExtension()
- {
- if (Vm?.PlatformService is null)
- {
- return;
- }
- await FileListManager.UpdateFileList(Vm?.PlatformService, Vm, FileListHelper.SortFilesBy.Extension);
- }
- public static async Task SortFilesRandomly()
- {
- if (Vm?.PlatformService is null)
- {
- return;
- }
- await FileListManager.UpdateFileList(Vm?.PlatformService, Vm, FileListHelper.SortFilesBy.Random);
- }
- public static async Task SortFilesAscending()
- {
- if (Vm?.PlatformService is null)
- {
- return;
- }
- await FileListManager.UpdateFileList(Vm?.PlatformService, Vm, ascending: true);
- }
- public static async Task SortFilesDescending()
- {
- if (Vm?.PlatformService is null)
- {
- return;
- }
- await FileListManager.UpdateFileList(Vm?.PlatformService, Vm, ascending: false);
- }
- #endregion Sorting
- #region Rating
- public static async Task Set0Star()
- {
- if (Vm is null)
- {
- return;
- }
- await Task.Run(() => { EXIFHelper.SetEXIFRating(Vm.FileInfo.FullName, 0); });
- Vm.EXIFRating = 0;
- }
- public static async Task Set1Star()
- {
- if (Vm is null)
- {
- return;
- }
- await Task.Run(() => { EXIFHelper.SetEXIFRating(Vm.FileInfo.FullName, 1); });
- Vm.EXIFRating = 1;
- }
- public static async Task Set2Star()
- {
- if (Vm is null)
- {
- return;
- }
- await Task.Run(() => { EXIFHelper.SetEXIFRating(Vm.FileInfo.FullName, 2); });
- Vm.EXIFRating = 2;
- }
- public static async Task Set3Star()
- {
- if (Vm is null)
- {
- return;
- }
- await Task.Run(() => { EXIFHelper.SetEXIFRating(Vm.FileInfo.FullName, 3); });
- Vm.EXIFRating = 3;
- }
- public static async Task Set4Star()
- {
- if (Vm is null)
- {
- return;
- }
- await Task.Run(() => { EXIFHelper.SetEXIFRating(Vm.FileInfo.FullName, 4); });
- Vm.EXIFRating = 4;
- }
- public static async Task Set5Star()
- {
- if (Vm is null)
- {
- return;
- }
- await Task.Run(() => { EXIFHelper.SetEXIFRating(Vm.FileInfo.FullName, 5); });
- Vm.EXIFRating = 5;
- }
- #endregion
- #region Open GPS link
- public static async Task OpenGoogleMaps()
- {
- if (Vm is null)
- {
- return;
- }
- if (string.IsNullOrEmpty(Vm.GoogleLink))
- {
- return;
- }
- await Task.Run(() => ProcessHelper.OpenLink(Vm.GoogleLink));
- }
-
- public static async Task OpenBingMaps()
- {
- if (Vm is null)
- {
- return;
- }
- if (string.IsNullOrEmpty(Vm.BingLink))
- {
- return;
- }
- await Task.Run(() => ProcessHelper.OpenLink(Vm.BingLink));
- }
- #endregion
- #region Wallpaper and lockscreen image
-
- public static async Task SetAsWallpaper()
- {
- if (Vm is null)
- {
- return;
- }
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
- {
- await SetAsWallpaperFilled();
- }
- // TODO: Add setting wallpaper support for macOS
- }
- public static async Task SetAsWallpaperTiled()
- {
- if (Vm is null)
- {
- return;
- }
- await Task.Run(() => Vm.PlatformService.SetAsWallpaper(Vm.FileInfo.FullName, 0));
- }
-
- public static async Task SetAsWallpaperCentered()
- {
- if (Vm is null)
- {
- return;
- }
- await Task.Run(() => Vm.PlatformService.SetAsWallpaper(Vm.FileInfo.FullName, 1));
- }
-
- public static async Task SetAsWallpaperStretched()
- {
- if (Vm is null)
- {
- return;
- }
- await Task.Run(() => Vm.PlatformService.SetAsWallpaper(Vm.FileInfo.FullName, 2));
- }
-
- public static async Task SetAsWallpaperFitted()
- {
- if (Vm is null)
- {
- return;
- }
- await Task.Run(() => Vm.PlatformService.SetAsWallpaper(Vm.FileInfo.FullName, 3));
- }
-
- public static async Task SetAsWallpaperFilled()
- {
- if (Vm is null)
- {
- return;
- }
- await Task.Run(() => Vm.PlatformService.SetAsWallpaper(Vm.FileInfo.FullName, 4));
- }
-
- public static async Task SetAsLockscreenCentered()
- {
- if (Vm is null)
- {
- return;
- }
- await Task.Run(() => Vm.PlatformService.SetAsLockScreen(Vm.FileInfo.FullName));
- }
-
- public static async Task SetAsLockScreen()
- {
- if (Vm is null)
- {
- return;
- }
- await Task.Run(() => Vm.PlatformService.SetAsLockScreen(Vm.FileInfo.FullName));
- }
- #endregion
- #region Other settings
- public static async Task ResetSettings()
- {
- await SettingsUpdater.ResetSettings(Vm);
- }
-
- public static async Task Restart()
- {
- var openFile = string.Empty;
- var getFromArgs = false;
- if (Vm?.FileInfo is not null)
- {
- if (Vm.FileInfo.Exists)
- {
- openFile = Vm.FileInfo.FullName;
- }
- else
- {
- getFromArgs = true;
- }
- }
- else
- {
- getFromArgs = true;
- }
- if (getFromArgs)
- {
- var args = Environment.GetCommandLineArgs();
- if (args is not null && args.Length > 0)
- {
- openFile = args[1];
- }
- }
- ProcessHelper.RestartApp(openFile);
- if (Application.Current?.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop)
- {
- Environment.Exit(0);
- return;
- }
- await Dispatcher.UIThread.InvokeAsync(() =>
- {
- desktop.MainWindow?.Close();
- });
- }
-
- public static async Task ToggleUsingTouchpad()
- {
- if (Vm is null)
- {
- return;
- }
- await SettingsUpdater.ToggleUsingTouchpad(Vm);
- }
- #endregion
-
- #endregion
- #if DEBUG
- public static async Task Invalidate()
- {
- Vm?.ImageViewer?.MainImage?.InvalidateVisual();
- //Vm?.ImageViewer?.InvalidateVisual();
- }
- #endif
- }
|