-
Notifications
You must be signed in to change notification settings - Fork 1
/
IsthereanydealCollectionSyncSettings.cs
99 lines (90 loc) · 3.09 KB
/
IsthereanydealCollectionSyncSettings.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using Playnite.SDK;
using Playnite.SDK.Data;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Markup;
namespace IsthereanydealCollectionSync
{
public class IsthereanydealCollectionSyncSettings : ObservableObject
{
private bool importModeReplace = false; // true replace, false ignore
private bool removeFromWaitlist = false;
private string importGroup = "Playnite";
public bool ImportModeReplace { get => importModeReplace; set => SetValue(ref importModeReplace, value); }
public bool RemoveFromWaitlist { get => removeFromWaitlist; set => SetValue(ref removeFromWaitlist, value); }
public string ImportGroup { get => importGroup; set => SetValue(ref importGroup, value); }
}
public class IsthereanydealCollectionSyncSettingsViewModel : ObservableObject, ISettings
{
private readonly IsthereanydealCollectionSync plugin;
private IsthereanydealCollectionSyncSettings editingClone { get; set; }
private IsthereanydealCollectionSyncSettings settings;
public IsthereanydealCollectionSyncSettings Settings
{
get => settings;
set
{
settings = value;
OnPropertyChanged();
}
}
public IsthereanydealCollectionSyncSettingsViewModel(IsthereanydealCollectionSync plugin)
{
this.plugin = plugin;
var savedSettings = plugin.LoadPluginSettings<IsthereanydealCollectionSyncSettings>();
if (savedSettings != null)
{
Settings = savedSettings;
}
else
{
Settings = new IsthereanydealCollectionSyncSettings();
}
}
public bool IsUserLoggedIn
{
get
{
using (var view = plugin.PlayniteApi.WebViews.CreateOffscreenView())
{
var client = new IsthereanydealClient(plugin, view);
return client.GetIsUserLoggedIn().GetAwaiter().GetResult();
}
}
}
public RelayCommand<object> LoginCommand
{
get => new RelayCommand<object>((a) =>
{
using (var view = plugin.PlayniteApi.WebViews.CreateView(600, 800))
{
var client = new IsthereanydealClient(plugin, view);
client.Login();
}
OnPropertyChanged(nameof(IsUserLoggedIn));
});
}
public void BeginEdit()
{
editingClone = Serialization.GetClone(Settings);
}
public void CancelEdit()
{
Settings = editingClone;
}
public void EndEdit()
{
plugin.SavePluginSettings(Settings);
}
public bool VerifySettings(out List<string> errors)
{
errors = new List<string>();
return true;
}
}
}