Skip to content

Commit

Permalink
Add autoupdater (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcanyucel committed Jun 22, 2023
1 parent c4e23bc commit 0a09c41
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
10 changes: 8 additions & 2 deletions DovizKuru.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<ApplicationIcon>assets\icon.ico</ApplicationIcon>
<FileVersion></FileVersion>
<AssemblyVersion>1.0.5.4</AssemblyVersion>
<FileVersion>1.1.0.0</FileVersion>
<AssemblyVersion>1.1.0.0</AssemblyVersion>
<PackageIcon>icon.ico</PackageIcon>
</PropertyGroup>

Expand All @@ -32,6 +32,12 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

<ItemGroup>
<Reference Include="AutoUpdater">
<HintPath>..\AutoUpdater\bin\Release\net7.0-windows\publish\AutoUpdater.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup>
<None Update="assets\icon.ico">
<Pack>True</Pack>
Expand Down
2 changes: 1 addition & 1 deletion Installer/Package.wxs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"
xmlns:ui="http://wixtoolset.org/schemas/v4/wxs/ui">
<Package Name="Döviz Kuru" Manufacturer="MCY Yazılım" Version="1.0.5.4" UpgradeCode="0d5b56c2-a581-4834-878f-c46268cdcb19" Codepage="Windows-1254">
<Package Name="Döviz Kuru" Manufacturer="MCY Yazılım" Version="1.1.0.0" UpgradeCode="0d5b56c2-a581-4834-878f-c46268cdcb19" Codepage="Windows-1254">
<MajorUpgrade DowngradeErrorMessage="!(loc.DowngradeError)" />
<MediaTemplate EmbedCab="yes" />

Expand Down
1 change: 1 addition & 0 deletions services/IWindowService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ internal interface IWindowService
public void ShowPreferenceWindow();
public void ShowAlarmSettingsWindow();
public void ShowAlarm(string title, string message);
public bool ShowUpdateWindowDialog();
}
}
3 changes: 3 additions & 0 deletions services/implementations/WindowService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using DovizKuru.views;
using Microsoft.Toolkit.Uwp.Notifications;
using System;
using System.Windows;

namespace DovizKuru.services.implementations
{
Expand Down Expand Up @@ -42,6 +43,8 @@ public void ShowPreferenceWindow()
throw new NotImplementedException();
}

public bool ShowUpdateWindowDialog() => MessageBox.Show("Yeni bir sürüm mevcut. İndirip kurmak ister misiniz?", "Güncelleme Var", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes;

public void Dispose()
{
ToastNotificationManagerCompat.Uninstall();
Expand Down
25 changes: 24 additions & 1 deletion viewmodels/MainViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
using CommunityToolkit.Mvvm.ComponentModel;
using AutoUpdater;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using DovizKuru.models;
using DovizKuru.services;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;

namespace DovizKuru.viewmodels
{
Expand Down Expand Up @@ -52,6 +55,9 @@ public MainViewModel(IWebService webService, IPreferenceService preferenceServic
m_AsyncCommands = new IAsyncRelayCommand[] { m_LoadPreferencesCommand };

m_UpdateTimer = new(QueryExchangeRates, null, Timeout.Infinite, Timeout.Infinite);

var executingAssemblyName = Assembly.GetExecutingAssembly().GetName();
m_UpdateEngine = new(executingAssemblyName.Name!, executingAssemblyName.Version!.ToString(), "https://software.mustafacanyucel.com/update");
}

private void RemoveAlarmItem(AlarmItem item) => AlarmHistory.Remove(item);
Expand All @@ -63,6 +69,21 @@ private async Task LoadPreferences()
SelectedAlarmExchange = ExchangeRates.First();

AlarmList = (ObservableCollection<Alarm>)await m_PreferenceService.LoadAlarms();

var hasUpdate = await m_UpdateEngine.CheckForUpdateAsync();
if (hasUpdate)
{
var shouldUpdate = m_WindowService.ShowUpdateWindowDialog();
if (shouldUpdate)
{
var downloaded = await m_UpdateEngine.DownloadAndRunUpdate();
if (downloaded)
Application.Current.Shutdown();
else
m_WindowService.ShowMessage("Hata", "Güncelleme indirilemedi.");
}
}

IsIdle = true;
}

Expand Down Expand Up @@ -183,6 +204,8 @@ private void UpdateCommandStates()

private ObservableCollection<Alarm> m_AlarmList = new();
private readonly ObservableCollection<AlarmItem> m_AlarmHistory = new();

private readonly UpdateEngine m_UpdateEngine;
#endregion
}
}

0 comments on commit 0a09c41

Please sign in to comment.