-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsWindow.xaml.cs
More file actions
159 lines (142 loc) · 6.16 KB
/
Copy pathSettingsWindow.xaml.cs
File metadata and controls
159 lines (142 loc) · 6.16 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using AndroidWidget.Presentation.Media;
using AndroidWidget.Presentation.Screenshots;
using AndroidWidget.Services;
using Forms = System.Windows.Forms;
namespace AndroidWidget;
public partial class SettingsWindow : Window
{
private readonly ISettingsService _settings;
private readonly ScreenshotStorage _screenshots;
private readonly RecordingStorage _recordings;
private readonly PhotoImportService _photoImport;
private bool _loading = true;
public SettingsWindow(ISettingsService settings, ScreenshotStorage screenshots,
RecordingStorage recordings, PhotoImportService photoImport)
{
_settings = settings;
_screenshots = screenshots;
_recordings = recordings;
_photoImport = photoImport;
InitializeComponent();
var current = _settings.Current;
DarkThemeRadio.IsChecked = current.Theme == WidgetTheme.Dark;
LightThemeRadio.IsChecked = current.Theme == WidgetTheme.Light;
AutoStartToggle.IsChecked = current.AutoStart;
SmsBubblesToggle.IsChecked = current.ShowSmsBubbles;
SetNotificationDurationChoice(current.NotificationDisplaySeconds);
ScreenshotFolderText.Text = _screenshots.Folder;
_loading = false;
}
private void ThemeRadio_Checked(object sender, RoutedEventArgs e)
{
if (_loading)
return;
var theme = LightThemeRadio.IsChecked == true ? WidgetTheme.Light : WidgetTheme.Dark;
_settings.Update(settings => settings with { Theme = theme });
ThemeService.Apply(theme);
StatusText.Text = theme == WidgetTheme.Light ? "Включена светлая тема" : "Включена тёмная тема";
}
private void AutoStartToggle_Click(object sender, RoutedEventArgs e)
{
if (_loading)
return;
var enabled = AutoStartToggle.IsChecked == true;
var result = _settings.SetAutoStart(enabled);
if (result.IsSuccess)
{
StatusText.Foreground = (Brush)FindResource("TextSecondary");
StatusText.Text = enabled ? "Автозапуск включён" : "Автозапуск выключен";
return;
}
_loading = true;
AutoStartToggle.IsChecked = !enabled;
_loading = false;
StatusText.Foreground = (Brush)FindResource("DangerText");
StatusText.Text = $"Не удалось изменить автозапуск: {result.BestMessage}";
}
private void SmsBubblesToggle_Click(object sender, RoutedEventArgs e)
{
if (_loading)
return;
var enabled = SmsBubblesToggle.IsChecked == true;
_settings.Update(settings => settings with { ShowSmsBubbles = enabled });
StatusText.Foreground = (Brush)FindResource("TextSecondary");
StatusText.Text = enabled ? "Баблы уведомлений включены" : "Баблы уведомлений выключены";
}
private void NotificationDuration_Checked(object sender, RoutedEventArgs e)
{
if (_loading)
return;
var seconds = Duration5Radio.IsChecked == true ? 5
: Duration15Radio.IsChecked == true ? 15
: Duration30Radio.IsChecked == true ? 30
: Duration60Radio.IsChecked == true ? 60
: 10;
_settings.Update(settings => settings with { NotificationDisplaySeconds = seconds });
StatusText.Foreground = (Brush)FindResource("TextSecondary");
StatusText.Text = $"Уведомления будут показаны {seconds} секунд";
}
private void SetNotificationDurationChoice(int seconds)
{
var choice = new[] { 5, 10, 15, 30, 60 }
.OrderBy(value => Math.Abs(value - seconds))
.First();
Duration5Radio.IsChecked = choice == 5;
Duration10Radio.IsChecked = choice == 10;
Duration15Radio.IsChecked = choice == 15;
Duration30Radio.IsChecked = choice == 30;
Duration60Radio.IsChecked = choice == 60;
}
private void ScreenshotFolderButton_Click(object sender, RoutedEventArgs e)
{
using var dialog = new Forms.FolderBrowserDialog
{
Description = "Выберите папку для скриншотов Device Widget",
UseDescriptionForTitle = true,
SelectedPath = _screenshots.Folder,
ShowNewFolderButton = true
};
if (dialog.ShowDialog() != Forms.DialogResult.OK)
return;
try
{
_screenshots.SetFolder(dialog.SelectedPath);
ScreenshotFolderText.Text = _screenshots.Folder;
StatusText.Foreground = (Brush)FindResource("TextSecondary");
StatusText.Text = "Папка для скриншотов обновлена";
}
catch (Exception ex)
{
StatusText.Foreground = (Brush)FindResource("DangerText");
StatusText.Text = $"Не удалось использовать папку: {ex.Message}";
}
}
private void CloseButton_Click(object sender, RoutedEventArgs e) => Close();
private void MediaSettingsButton_Click(object sender, RoutedEventArgs e) =>
new MediaSettingsWindow(_settings, _recordings, _photoImport) { Owner = this }.ShowDialog();
private void LicensesButton_Click(object sender, RoutedEventArgs e)
{
var path = Path.Combine(AppContext.BaseDirectory, "THIRD_PARTY_NOTICES.md");
if (!File.Exists(path))
{
StatusText.Foreground = (Brush)FindResource("DangerText");
StatusText.Text = "Файл THIRD_PARTY_NOTICES.md не найден рядом с приложением.";
return;
}
try
{
using var process = System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(path)
{
UseShellExecute = true
});
}
catch (Exception ex)
{
StatusText.Foreground = (Brush)FindResource("DangerText");
StatusText.Text = $"Не удалось открыть лицензии: {ex.Message}";
}
}
}