Repository navigation
Expand file tree
/
Copy pathApp.xaml.cs
More file actions
129 lines (114 loc) · 4.51 KB
/
Copy pathApp.xaml.cs
File metadata and controls
129 lines (114 loc) · 4.51 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
using System;
using LiveDrive.Services;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.Data.Xml.Dom;
using Windows.Storage;
using Windows.UI.Notifications;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
namespace LiveDrive
{
sealed partial class App : Application
{
private const string ThemeSettingKey = "AppTheme";
public App()
{
InitializeComponent();
RequestedTheme = ReadSavedTheme();
Services = new AppServices();
Suspending += OnSuspending;
Resuming += OnResuming;
}
public AppServices Services { get; }
public ApplicationTheme CurrentTheme => RequestedTheme;
public void SaveThemePreference(bool useDarkTheme)
{
var theme = useDarkTheme ? ApplicationTheme.Dark : ApplicationTheme.Light;
ApplicationData.Current.LocalSettings.Values[ThemeSettingKey] = theme.ToString();
}
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
var rootFrame = Window.Current.Content as Frame;
if (rootFrame == null)
{
rootFrame = new Frame();
rootFrame.NavigationFailed += OnNavigationFailed;
Window.Current.Content = rootFrame;
}
if (rootFrame.Content == null)
{
rootFrame.Navigate(typeof(MainPage), e.Arguments);
}
Window.Current.Activate();
_ = RestoreCameraBackupRegistrationAsync();
}
private async System.Threading.Tasks.Task RestoreCameraBackupRegistrationAsync()
{
try
{
await Services.CameraBackupScheduler.EnsureRegisteredAsync();
}
catch (System.Exception exception)
{
Services.CameraBackupState.SaveLastResult(
"Scheduled Camera Roll backup could not be restored: " + exception.Message);
}
}
public string SendCameraBackupToastDiagnostic()
{
return ShowCameraBackupToast(1, true);
}
private string ShowCameraBackupToast(int uploadedCount, bool isDiagnostic)
{
var notifier = ToastNotificationManager.CreateToastNotifier();
var notifierSetting = notifier.Setting.ToString();
try
{
var toastXml = new XmlDocument();
var message = isDiagnostic
? "Notification diagnostic test."
: "Uploaded " + uploadedCount + " new Camera Roll " +
(uploadedCount == 1 ? "item." : "items.");
toastXml.LoadXml("<toast><visual><binding template=\"ToastGeneric\"><text>LiveDrive</text><text>" +
message + "</text></binding></visual></toast>");
notifier.Show(new ToastNotification(toastXml));
var result = "Toast submitted at " + DateTimeOffset.Now.ToString("g") +
". Device setting: " + notifierSetting + ".";
Services.CameraBackupState.SaveToastDiagnostic(result);
return result;
}
catch (Exception exception)
{
var result = "Toast failed at " + DateTimeOffset.Now.ToString("g") +
". Device setting: " + notifierSetting + ". " + exception.Message;
Services.CameraBackupState.SaveToastDiagnostic(result);
throw;
}
}
private void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
{
throw new System.Exception("Failed to load page " + e.SourcePageType.FullName);
}
private void OnSuspending(object sender, SuspendingEventArgs e)
{
Services.Thumbnails.Suspend();
e.SuspendingOperation.GetDeferral().Complete();
}
private void OnResuming(object sender, object e)
{
Services.Thumbnails.Resume();
}
private static ApplicationTheme ReadSavedTheme()
{
object setting;
if (ApplicationData.Current.LocalSettings.Values.TryGetValue(ThemeSettingKey, out setting) &&
string.Equals(setting as string, ApplicationTheme.Dark.ToString(), System.StringComparison.OrdinalIgnoreCase))
{
return ApplicationTheme.Dark;
}
return ApplicationTheme.Light;
}
}
}