Archived
1
0

Core refactoring (app doesn't work)

This commit is contained in:
Michael Gordeev
2020-05-09 23:16:19 +03:00
parent 2b1f06dd93
commit 2a987e33a2
35 changed files with 1135 additions and 817 deletions
+77
View File
@@ -0,0 +1,77 @@
using System;
using Microsoft.Services.Store.Engagement;
using Windows.System;
using Windows.UI.Xaml.Controls;
namespace FoxTube.Utils
{
public static class Feedback
{
public static bool HasFeedbackHub => StoreServicesFeedbackLauncher.IsSupported();
public static async void OpenFeedbackHub()
{
if (HasFeedbackHub)
await StoreServicesFeedbackLauncher.GetDefault().LaunchAsync();
else
await Launcher.LaunchUriAsync("mailto:feedback@xfox111.net".ToUri());
}
public static async void PromptFeedback()
{
if (!HasFeedbackHub)
{
Settings.PromptFeedback = false;
return;
}
ContentDialog dialog = new ContentDialog
{
Title = "Have some thoughts?",
PrimaryButtonText = "Sure!",
SecondaryButtonText = "Don't ask me anymore",
CloseButtonText = "Maybe later",
DefaultButton = ContentDialogButton.Primary,
Content = "Would you like to share something you like or dislike in the app? Or perhaps you have some ideas? Leave feedback!"
};
ContentDialogResult result = await dialog.ShowAsync();
if (result != ContentDialogResult.None)
Settings.PromptFeedback = false;
if (result == ContentDialogResult.Primary)
OpenFeedbackHub();
}
public static async void PromptReview()
{
ContentDialog dialog = new ContentDialog
{
Title = "Like our app?",
PrimaryButtonText = "Sure!",
SecondaryButtonText = "Don't ask me anymore",
CloseButtonText = "Maybe later",
DefaultButton = ContentDialogButton.Primary,
Content = new TextBlock
{
Text = "Could you leave a feedback on Microsfot Store page? It's very important for me :)"
}
};
ContentDialogResult result = await dialog.ShowAsync();
if (result != ContentDialogResult.None)
Settings.PromptReview = false;
if (result == ContentDialogResult.Primary)
StoreInterop.RequestReview();
}
}
}
+66
View File
@@ -0,0 +1,66 @@
using Microsoft.AppCenter;
using Microsoft.AppCenter.Analytics;
using Microsoft.AppCenter.Crashes;
using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using Windows.ApplicationModel;
using Windows.Storage;
namespace FoxTube.Utils
{
public static class Metrics
{
static readonly ApplicationDataContainer storage = ApplicationData.Current.RoamingSettings;
static readonly Stopwatch sw = new Stopwatch();
public static TimeSpan Uptime
{
get => (TimeSpan?)storage.Values["Metrics.SpentTime"] ?? TimeSpan.FromSeconds(0);
set => storage.Values["Metrics.SpentTime"] = value;
}
public static string CurrentVersion
{
get
{
PackageVersion v = Package.Current.Id.Version;
return $"{v.Major}.{v.Minor}.{v.Revision}.{v.Build}";
}
}
static Metrics()
{
sw.Start();
if (!Settings.AllowAnalytics)
return;
AppCenter.Start("45774462-9ea7-438a-96fc-03982666f39e", typeof(Analytics), typeof(Crashes));
AppCenter.SetCountryCode(Settings.Region);
AppCenter.LogLevel = LogLevel.Verbose;
}
public static void EndSession()
{
sw.Stop();
Uptime += sw.Elapsed;
AddEvent("Session closed",
("Duration", sw.Elapsed.ToString()),
("Spend time total", Uptime.ToString()));
}
public static void AddEvent(string eventName, params (string key, string value)[] details) =>
Analytics.TrackEvent(eventName,
details.Length < 1 ? null :
details.Select(i => new KeyValuePair<string, string>(i.key, i.value)) as Dictionary<string, string>);
public static void SendReport(Exception exception, ErrorAttachmentLog[] logs = null, params (string key, string value)[] details)
{
Crashes.TrackError(exception,
details.Length < 1 ? null :
details.Select(i => new KeyValuePair<string, string>(i.key, i.value)) as Dictionary<string, string>,
logs);
}
}
}
+61
View File
@@ -0,0 +1,61 @@
using Microsoft.Advertising.WinRT.UI;
using Microsoft.AppCenter.Crashes;
using System;
using System.Threading.Tasks;
using Windows.Services.Store;
namespace FoxTube.Utils
{
public static class StoreInterop
{
public static bool AdsDisabled { get; private set; } = true;
public static string Price { get; private set; }
private static bool UseTestAds => true;
private static string ApplicationId => UseTestAds ? "d25517cb-12d4-4699-8bdc-52040c712cab" : "9ncqqxjtdlfh";
private static string AdsId => UseTestAds ? "test" : "1100044398";
private static string ProProductId => "9NP1QK556625";
public static NativeAdsManagerV2 AdsManager => new NativeAdsManagerV2(ApplicationId, AdsId);
public static async Task UpdateStoreState()
{
StoreProductQueryResult requset = await StoreContext.GetDefault().GetAssociatedStoreProductsAsync(new[] { "Durable" });
if (requset.Products[ProProductId].IsInUserCollection)
return;
Price = requset.Products[ProProductId].Price.FormattedPrice;
AdsDisabled = false;
}
public static async Task<bool> PurchaseApp()
{
StorePurchaseResult request = await StoreContext.GetDefault().RequestPurchaseAsync(ProProductId);
switch (request.Status)
{
case StorePurchaseStatus.AlreadyPurchased:
case StorePurchaseStatus.Succeeded:
AdsDisabled = true;
return true;
default:
return false;
}
}
public static async void RequestReview()
{
StoreRateAndReviewResult result = await StoreContext.GetDefault().RequestRateAndReviewAppAsync();
if (result.Status == StoreRateAndReviewStatus.Error)
Metrics.SendReport(result.ExtendedError, new[] { ErrorAttachmentLog.AttachmentWithText(result.ExtendedJsonData, "extendedJsonData.json") },
("Status", result.Status.ToString()),
("WasReviewUpdated", result.WasUpdated.ToString()));
Metrics.AddEvent("Store review request has been recieved");
}
}
}
+38
View File
@@ -0,0 +1,38 @@
using System;
using Windows.ApplicationModel.Core;
using Windows.Security.Credentials;
namespace FoxTube.Utils
{
public static class Utils
{
/// <summary>
/// Terminates current application session
/// </summary>
public static void CloseApp() =>
CoreApplication.Exit();
/// <summary>
/// Restarts application
/// </summary>
public static void RestartApp() =>
RestartApp(null);
/// <summary>
/// Restarts application with specified parameters
/// </summary>
/// <param name="args">Parameters which will be provided to new application instance</param>
public static async void RestartApp(string args) =>
await CoreApplication.RequestRestartAsync(args ?? "");
public static void InitializeFailsafeProtocol()
{
Metrics.AddEvent("Failsafe protocol initiated");
Settings.ResetSettings();
PasswordVault passwordVault = new PasswordVault();
foreach (PasswordCredential credential in passwordVault.RetrieveAll())
passwordVault.Remove(credential);
RestartApp();
}
}
}