Skip to content
This repository has been archived by the owner on Aug 17, 2020. It is now read-only.

Commit

Permalink
Fix #9
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-Apps committed Jul 31, 2016
1 parent 6d59ead commit 5916d85
Show file tree
Hide file tree
Showing 10 changed files with 22,440 additions and 10,856 deletions.
Binary file modified .vs/Pokemon Go Universal/v14/.suo
Binary file not shown.
30 changes: 25 additions & 5 deletions PokemonGo-UWP/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
using PokemonGo_UWP.Views;
using Template10.Common;
using System;
using Windows.System;
using Windows.System.Display;
using Windows.UI.Popups;

namespace PokemonGo_UWP
{
Expand All @@ -32,9 +34,13 @@ public App()
{
InitializeComponent();

// Init HockeySDK
if (!string.IsNullOrEmpty(ApplicationKeys.HockeyAppToken))
HockeyClient.Current.Configure(ApplicationKeys.HockeyAppToken);

// Forces the display to stay on while we play
DisplayRequest = new DisplayRequest();
DisplayRequest.RequestActive();
DisplayRequest.RequestActive();
}

public override async Task OnInitializeAsync(IActivatedEventArgs args)
Expand All @@ -51,17 +57,31 @@ public override async Task OnInitializeAsync(IActivatedEventArgs args)
}

public override async Task OnStartAsync(StartKind startKind, IActivatedEventArgs args)
{
// Init HockeySDK
if (!string.IsNullOrEmpty(ApplicationKeys.HockeyAppToken))
HockeyClient.Current.Configure(ApplicationKeys.HockeyAppToken);
{
await NavigationService.NavigateAsync(typeof(MainPage));
if (!string.IsNullOrEmpty(SettingsService.Instance.PtcAuthToken))
{
// We have a stored token, let's go to game page
NavigationService.Navigate(typeof(GameMapPage));
await ViewModelLocator.GameManagerViewModel.InitGame(true);
}

// Check for updates
var latestVersionUri = await UpdateManager.IsUpdateAvailable();
if (latestVersionUri != null)
{
var dialog = new MessageDialog(
$"An updated version is available on\n{latestVersionUri}\nDo you want to visit the link?");

dialog.Commands.Add(new UICommand("Yes") { Id = 0 });
dialog.Commands.Add(new UICommand("No") { Id = 1 });
dialog.DefaultCommandIndex = 0;
dialog.CancelCommandIndex = 1;

var result = await dialog.ShowAsyncQueue();
if ((int) result.Id != 0) return;
await Launcher.LaunchUriAsync(new Uri(latestVersionUri));
}
await Task.CompletedTask;
}
}
Expand Down
2 changes: 2 additions & 0 deletions PokemonGo-UWP/PokemonGo-UWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,10 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Utils\ApplicationKeys.cs" />
<Compile Include="Utils\Converters.cs" />
<Compile Include="Utils\MessageDialogExtensions.cs" />
<Compile Include="Utils\Settings.cs" />
<Compile Include="Utils\SettingsService.cs" />
<Compile Include="Utils\UpdateManager.cs" />
<Compile Include="ViewModels\GameManagerViewModel.cs" />
<Compile Include="ViewModels\ViewModelLocator.cs" />
<Compile Include="Views\CapturePokemonPage.xaml.cs">
Expand Down
49 changes: 49 additions & 0 deletions PokemonGo-UWP/Utils/MessageDialogExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Popups;
using Windows.UI.Xaml;

namespace PokemonGo_UWP.Utils
{
/// <summary>
/// MessageDialog extension methods
/// </summary>
public static class MessageDialogExtensions
{

private static TaskCompletionSource<MessageDialog> _currentDialogShowRequest;

/// <summary>
/// Begins an asynchronous operation showing a dialog.
/// If another dialog is already shown using
/// ShowAsyncQueueQueue or ShowAsyncQueueIfPossible method - it will wait
/// for that previous dialog to be dismissed before showing the new one.
/// </summary>
/// <param name="dialog">The dialog.</param>
/// <returns></returns>
/// <seealso cref="WinRTXamlToolkit.Controls.Extensions"/>
/// <exception cref="System.InvalidOperationException">This method can only be invoked from UI thread.</exception>
public static async Task<IUICommand> ShowAsyncQueue(this MessageDialog dialog)
{
if (!Window.Current.Dispatcher.HasThreadAccess)
{
throw new InvalidOperationException("This method can only be invoked from UI thread.");
}

while (_currentDialogShowRequest != null)
{
await _currentDialogShowRequest.Task;
}

var request = _currentDialogShowRequest = new TaskCompletionSource<MessageDialog>();
var result = await dialog.ShowAsync();
_currentDialogShowRequest = null;
request.SetResult(dialog);

return result;
}
}
}
38 changes: 38 additions & 0 deletions PokemonGo-UWP/Utils/UpdateManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.ApplicationModel;
using Octokit;

namespace PokemonGo_UWP.Utils
{
/// <summary>
/// Manager that checks if there's an updated version on GitHub
/// </summary>
public static class UpdateManager
{
/// <summary>
/// Client to access GitHub
/// </summary>
private static readonly GitHubClient GitHubClient = new GitHubClient(new ProductHeaderValue("PoGo-UWP"));

/// <summary>
/// Checks if we have an updated version and returns the URI
/// </summary>
/// <returns></returns>
public static async Task<string> IsUpdateAvailable()
{
var releases = await GitHubClient.Repository.Release.GetAll("ST-Apps", "PoGo-UWP");
var latestRelease = releases[0];
// We skip prereleases, only stable ones
if (latestRelease.Prerelease) return null;
// Check if version number matches
var currentVersion = Package.Current.Id.Version;
var version = $"{currentVersion.Major}.{currentVersion.Minor}.{currentVersion.Build}";
var tagVersion = latestRelease.TagName.Replace("v", "");
return !version.Equals(tagVersion) ? latestRelease.HtmlUrl : null;
}
}
}
16 changes: 8 additions & 8 deletions PokemonGo-UWP/ViewModels/GameManagerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ public async Task InitGame(bool hadAuthTokenStored = false)
{
// Login failed, show a message
await
new MessageDialog("Wrong username/password or offline server, please try again.").ShowAsync();
new MessageDialog("Wrong username/password or offline server, please try again.").ShowAsyncQueue();
}
else
{
Expand All @@ -380,7 +380,7 @@ public async Task InitGame(bool hadAuthTokenStored = false)
}
catch (Exception)
{
await new MessageDialog("PTC login is probably down, please retry later.").ShowAsync();
await new MessageDialog("PTC login is probably down, please retry later.").ShowAsyncQueue();
}
finally
{
Expand Down Expand Up @@ -437,7 +437,7 @@ private async void HandleException()
dialog.Commands.Add(new UICommand("No") {Id = 1});
dialog.DefaultCommandIndex = 0;
dialog.CancelCommandIndex = 1;
var result = await dialog.ShowAsync();
var result = await dialog.ShowAsyncQueue();
if ((int) result.Id == 0)
{
SettingsService.Instance.PtcAuthToken = null;
Expand Down Expand Up @@ -601,7 +601,7 @@ await Dispatcher.DispatchAsync(() =>
else
{
// Encounter failed, probably the Pokemon ran away
await new MessageDialog("Pokemon ran away, sorry :(").ShowAsync();
await new MessageDialog("Pokemon ran away, sorry :(").ShowAsyncQueue();
UpdateMapData();
}
}, pokemon => true)
Expand Down Expand Up @@ -662,14 +662,14 @@ private async Task ThrowPokeball()
case CatchPokemonResponse.Types.CatchStatus.CatchEscape:
Logger.Write($"{CurrentPokemon.PokemonId} escaped");
CatchEscape?.Invoke(this, null);
await new MessageDialog($"{CurrentPokemon.PokemonId} escaped").ShowAsync();
await new MessageDialog($"{CurrentPokemon.PokemonId} escaped").ShowAsyncQueue();
UpdateMapData();
UpdateInventory();
break;
case CatchPokemonResponse.Types.CatchStatus.CatchFlee:
Logger.Write($"{CurrentPokemon.PokemonId} escaped");
CatchEscape?.Invoke(this, null);
await new MessageDialog($"{CurrentPokemon.PokemonId} escaped").ShowAsync();
await new MessageDialog($"{CurrentPokemon.PokemonId} escaped").ShowAsyncQueue();
UpdateMapData();
UpdateInventory();
break;
Expand Down Expand Up @@ -754,7 +754,7 @@ public async Task ThrowBerry()
else
{
// Timeout is not expired yet, player can't get items from the fort
await new MessageDialog("This PokeStop is still on cooldown, please retry later.").ShowAsync();
await new MessageDialog("This PokeStop is still on cooldown, please retry later.").ShowAsyncQueue();
}
}, pokemon => true)
);
Expand Down Expand Up @@ -853,7 +853,7 @@ private async Task InitGps()
break;
default:
Logger.Write("Error during GPS activation");
await new MessageDialog("GPS error, sorry :(").ShowAsync();
await new MessageDialog("GPS error, sorry :(").ShowAsyncQueue();
BootStrapper.Current.Exit();
break;
}
Expand Down
37 changes: 19 additions & 18 deletions PokemonGo-UWP/project.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
{
"dependencies": {
"HockeySDK.UWP": "4.1.3",
"Microsoft.NETCore.UniversalWindowsPlatform": "5.1.0",
"Newtonsoft.Json": "9.0.1",
"Template10": "1.1.12-preview-160712",
"WinRTXamlToolkit.Controls.Gauge.UWP": "2.0.0"
},
"frameworks": {
"uap10.0": {}
},
"runtimes": {
"win10-arm": {},
"win10-arm-aot": {},
"win10-x86": {},
"win10-x86-aot": {},
"win10-x64": {},
"win10-x64-aot": {}
}
"dependencies": {
"HockeySDK.UWP": "4.1.3",
"Microsoft.NETCore.UniversalWindowsPlatform": "5.1.0",
"Newtonsoft.Json": "9.0.1",
"Octokit": "0.21.1",
"Template10": "1.1.12-preview-160712",
"WinRTXamlToolkit.Controls.Gauge.UWP": "2.0.0"
},
"frameworks": {
"uap10.0": {}
},
"runtimes": {
"win10-arm": {},
"win10-arm-aot": {},
"win10-x86": {},
"win10-x86-aot": {},
"win10-x64": {},
"win10-x64-aot": {}
}
}
Loading

0 comments on commit 5916d85

Please sign in to comment.