Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using ReactiveUI;
- using System;
- using System.Diagnostics;
- using System.Runtime.InteropServices;
- using Todo.Services;
- namespace Todo.ViewModels;
- public partial class UpdateAvailableViewModel : ViewModelBase
- {
- public string _informationText;
- public UpdateAvailableViewModel(GithubVersionService gvs, GithubVersionService.VersionData version)
- {
- InformationText = $"There is an update. The apps current version {version.CurrentVersion} does not match the new version {version.LatestVersion}";
- }
- public string InformationText
- {
- get => _informationText;
- set => this.RaiseAndSetIfChanged(ref _informationText, value);
- }
- SupportedOperatingSystem GetSupportedOs()
- {
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
- return SupportedOperatingSystem.Windows;
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
- return SupportedOperatingSystem.Linux;
- if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
- return SupportedOperatingSystem.Mac;
- throw new PlatformNotSupportedException();
- }
- public void LaunchUpdate()
- {
- var userOs = GetSupportedOs();
- try
- {
- switch (userOs)
- {
- case SupportedOperatingSystem.Windows:
- var p = new Process();
- p.StartInfo.FileName = "/Executables/win/Installer.exe";
- p.Start();
- Environment.Exit(0);
- break;
- case SupportedOperatingSystem.Linux:
- // some code to launch installer on linux
- Environment.Exit(0);
- break;
- case SupportedOperatingSystem.Mac:
- // some code to launch installer on Mac
- Environment.Exit(0);
- break;
- }
- }
- catch (Exception ex)
- {
- InformationText = ex.Message;
- return;
- }
- }
- }
- public enum SupportedOperatingSystem
- {
- Windows,
- Linux,
- Mac
- }
Add Comment
Please, Sign In to add comment