Let user disable auto-updates

pull/37/head
Alexey Golub 7 years ago
parent 4540134a98
commit 9988300942

@ -4,6 +4,8 @@ namespace DiscordChatExporter.Core.Services
{ {
public interface ISettingsService public interface ISettingsService
{ {
bool IsAutoUpdateEnabled { get; set; }
string DateFormat { get; set; } string DateFormat { get; set; }
int MessageGroupLimit { get; set; } int MessageGroupLimit { get; set; }

@ -5,6 +5,8 @@ namespace DiscordChatExporter.Core.Services
{ {
public class SettingsService : SettingsManager, ISettingsService public class SettingsService : SettingsManager, ISettingsService
{ {
public bool IsAutoUpdateEnabled { get; set; } = true;
public string DateFormat { get; set; } = "dd-MMM-yy hh:mm tt"; public string DateFormat { get; set; } = "dd-MMM-yy hh:mm tt";
public int MessageGroupLimit { get; set; } = 20; public int MessageGroupLimit { get; set; } = 20;

@ -7,13 +7,16 @@ namespace DiscordChatExporter.Core.Services
{ {
public class UpdateService : IUpdateService public class UpdateService : IUpdateService
{ {
private readonly ISettingsService _settingsService;
private readonly UpdateManager _updateManager; private readonly UpdateManager _updateManager;
private Version _lastVersion; private Version _lastVersion;
private bool _applied; private bool _applied;
public UpdateService() public UpdateService(ISettingsService settingsService)
{ {
_settingsService = settingsService;
_updateManager = new UpdateManager( _updateManager = new UpdateManager(
new GithubPackageResolver("Tyrrrz", "DiscordChatExporter", "DiscordChatExporter.zip"), new GithubPackageResolver("Tyrrrz", "DiscordChatExporter", "DiscordChatExporter.zip"),
new ZipPackageExtractor()); new ZipPackageExtractor());
@ -26,6 +29,10 @@ namespace DiscordChatExporter.Core.Services
return null; return null;
#endif #endif
// Don't update if user disabled it
if (!_settingsService.IsAutoUpdateEnabled)
return null;
try try
{ {
// Remove some junk left over from last update // Remove some junk left over from last update

@ -2,6 +2,8 @@
{ {
public interface ISettingsViewModel public interface ISettingsViewModel
{ {
bool IsAutoUpdateEnabled { get; set; }
string DateFormat { get; set; } string DateFormat { get; set; }
int MessageGroupLimit { get; set; } int MessageGroupLimit { get; set; }
} }

@ -8,6 +8,12 @@ namespace DiscordChatExporter.Gui.ViewModels
{ {
private readonly ISettingsService _settingsService; private readonly ISettingsService _settingsService;
public bool IsAutoUpdateEnabled
{
get => _settingsService.IsAutoUpdateEnabled;
set => _settingsService.IsAutoUpdateEnabled = value;
}
public string DateFormat public string DateFormat
{ {
get => _settingsService.DateFormat; get => _settingsService.DateFormat;

@ -21,6 +21,23 @@ UserControl "DiscordChatExporter.Gui.Views.SettingsDialog" {
Text: bind MessageGroupLimit Text: bind MessageGroupLimit
} }
// Auto-update
DockPanel {
LastChildFill: false
TextBlock {
Margin: [16, 8, 16, 8]
DockPanel.Dock: Left
Text: "Auto-updates"
}
ToggleButton {
Margin: [16, 8, 16, 8]
DockPanel.Dock: Right
IsChecked: bind IsAutoUpdateEnabled
}
}
// Save // Save
Button { Button {
Margin: 8 Margin: 8

Loading…
Cancel
Save