-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add the UWP app launch References: #347 * refactor: split common and platform-specific code References: #347 * fix: fix async unhandled exception References: #347
- Loading branch information
Showing
9 changed files
with
245 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,18 @@ | ||
using System; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
|
||
using Tuvi.App.Shared.Models; | ||
using Tuvi.App.Shared.Services; | ||
using Tuvi.App.ViewModels.Services; | ||
using Tuvi.Core; | ||
using Tuvi.OAuth2; | ||
using Windows.Globalization; | ||
using Windows.Storage; | ||
|
||
#if WINDOWS_UWP | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Controls; | ||
#else | ||
using Microsoft.UI.Xaml; | ||
#endif | ||
|
@@ -15,9 +24,133 @@ namespace Eppie.App.Shared | |
/// </summary> | ||
public partial class App : Application | ||
{ | ||
private static readonly string DataBaseFileName = "TuviMail.db"; | ||
|
||
private static readonly string DataFolder = ApplicationData.Current.LocalFolder.Path; | ||
|
||
public INavigationService NavigationService { get; private set; } | ||
public ITuviMail Core { get; private set; } | ||
public ILocalSettingsService LocalSettingsService { get; private set; } | ||
public AuthorizationProvider AuthProvider { get; private set; } | ||
private NotificationManager _notificationManager { get; set; } | ||
|
||
private ErrorHandler _errorHandler; | ||
|
||
|
||
/// <summary> | ||
/// Initializes the singleton application object. This is the first line of authored code | ||
/// executed, and as such is the logical equivalent of main() or WinMain(). | ||
/// </summary> | ||
public App() | ||
{ | ||
InitializeLogging(); | ||
InitializeComponent(); | ||
SubscribeToEvents(); | ||
ConfigureServices(); | ||
} | ||
|
||
private static void InitializeLogging() | ||
{ | ||
// ToDo: Add logging | ||
} | ||
|
||
private void SubscribeToEvents() | ||
{ | ||
SubscribeToPlatformSpecificEvents(); | ||
|
||
UnhandledException += CurrentApp_UnhandledException; | ||
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException; | ||
} | ||
|
||
private void ConfigureServices() | ||
{ | ||
CreateAuth(); | ||
CreateCore(); | ||
|
||
LocalSettingsService = new LocalSettingsService(); | ||
ApplicationLanguages.PrimaryLanguageOverride = LocalSettingsService.Language; | ||
} | ||
|
||
private void CreateAuth() | ||
{ | ||
AuthProvider = AuthorizationFactory.GetAuthorizationProvider(Tuvi.App.Shared.Authorization.AuthConfig.GetAuthorizationConfiguration()); | ||
} | ||
|
||
private void CreateCore() | ||
{ | ||
var tokenRefresher = AuthorizationFactory.GetTokenRefresher(AuthProvider); | ||
Core = ComponentBuilder.Components.CreateTuviMailCore(Path.Combine(DataFolder, DataBaseFileName), new Tuvi.Core.ImplementationDetailsProvider("Tuvi seed", "Tuvi.Package", "[email protected]"), tokenRefresher); | ||
_notificationManager = new NotificationManager(Core, OnError); | ||
Core.WipeAllDataNeeded += OnWipeAllDataNeeded; | ||
} | ||
|
||
private void DisposeCore() | ||
{ | ||
Core.WipeAllDataNeeded -= OnWipeAllDataNeeded; | ||
if (Core is IDisposable d) | ||
{ | ||
d.Dispose(); | ||
} | ||
} | ||
|
||
private async void OnWipeAllDataNeeded(object sender, EventArgs e) | ||
{ | ||
try | ||
{ | ||
// Dispose should be before await method | ||
DisposeCore(); | ||
CreateCore(); | ||
await RemoveTempFilesAsync().ConfigureAwait(true); | ||
} | ||
catch (Exception ex) | ||
{ | ||
OnError(ex); | ||
} | ||
} | ||
|
||
private async Task RemoveTempFilesAsync() | ||
{ | ||
var tempFolder = ApplicationData.Current.TemporaryFolder; | ||
foreach (var item in await tempFolder.GetItemsAsync()) | ||
{ | ||
try | ||
{ | ||
await item.DeleteAsync(StorageDeleteOption.PermanentDelete); | ||
} | ||
catch (Exception e) | ||
{ | ||
OnError(e); | ||
} | ||
} | ||
} | ||
|
||
#if WINDOWS_UWP | ||
private void CurrentApp_UnhandledException(object sender, Windows.UI.Xaml.UnhandledExceptionEventArgs e) | ||
#else | ||
private void CurrentApp_UnhandledException(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e) | ||
#endif | ||
{ | ||
try | ||
{ | ||
e.Handled = true; | ||
OnError(e.Exception); | ||
} | ||
catch { } | ||
} | ||
|
||
private void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e) | ||
{ | ||
try | ||
{ | ||
e.SetObserved(); | ||
OnError(e.Exception); | ||
} | ||
catch { } | ||
} | ||
|
||
private void OnError(Exception exception) | ||
{ | ||
_errorHandler?.OnError(exception, false); | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
source/Eppie.App/Eppie.App.Shared/Authorization/AuthConfig.Uno.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#if !WINDOWS_UWP | ||
|
||
using System; | ||
using Finebits.Authorization.OAuth2.Google; | ||
using Finebits.Authorization.OAuth2.Outlook; | ||
using Tuvi.OAuth2; | ||
|
||
namespace Tuvi.App.Shared.Authorization | ||
{ | ||
internal static partial class AuthConfig | ||
{ | ||
public static AuthorizationConfiguration GetAuthorizationConfiguration() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} | ||
|
||
#endif |
Oops, something went wrong.