This repository has been archived by the owner on Dec 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathApp.xaml.cs
134 lines (119 loc) · 4.51 KB
/
App.xaml.cs
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Coolapk_UWP.Pages;
using Coolapk_UWP.ViewModels;
using Windows.ApplicationModel.Core;
using Windows.UI.ViewManagement;
using Windows.UI;
using System.Threading.Tasks;
using Coolapk_UWP.Other;
using Windows.ApplicationModel.Background;
namespace Coolapk_UWP
{
sealed partial class App : Application
{
public static AppViewModel AppViewModel;
public App()
{
this.InitializeComponent();
EmojisUtil.LoadEmojisResw();
this.Suspending += OnSuspending;
App.AppViewModel = new AppViewModel();
}
private void HandleActivation(IActivatedEventArgs e)
{
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame == null)
{
rootFrame = new Frame();
rootFrame.NavigationFailed += OnNavigationFailed;
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
//TODO: Load state from previously suspended application
}
Window.Current.Content = rootFrame;
}
var launch = e as LaunchActivatedEventArgs;
if (launch != null && launch.PrelaunchActivated == false)
{
if (rootFrame.Content == null)
{
rootFrame.Navigate(typeof(Home), launch.Arguments);
}
Window.Current.Activate();
}
else
{
if (rootFrame.Content == null)
{
rootFrame.Navigate(typeof(Home));
}
Window.Current.Activate();
}
BackgroundTask.RegisterBackgroundTask(typeof(BackgroundTask), "msgNotify", new TimeTrigger(15, false), null).ContinueWith((r) =>
{
if (r.Status == TaskStatus.RanToCompletion)
{
// TODO sth
}
});
}
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
HandleActivation(e);
}
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
{
throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
}
private void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
deferral.Complete();
}
protected override void OnActivated(IActivatedEventArgs args)
{
base.OnActivated(args);
HandleActivation(args);
if (args.Kind == ActivationKind.Protocol)
switch (args)
{
case ProtocolActivatedEventArgs args1:
if (args1.Uri.Scheme == "coolmarket")
{
switch (args1.Uri.Host)
{
case "feed": // 动态
var feedId = args1.Uri.Segments[1];
if (feedId != null)
{
// 跳转到动态
if (AppViewModel.HomeContentFrame == null) App.AppViewModel.HomeContentFrameLoadedEvent += new AppViewModel.HomeContentFrameLoadedHandler(async homeContentFrame =>
{
await Task.Delay(200);
homeContentFrame.Navigate(typeof(Coolapk_UWP.Pages.FeedDetail), uint.Parse(feedId));
});
else AppViewModel.HomeContentFrame.Navigate(typeof(Coolapk_UWP.Pages.FeedDetail), uint.Parse(feedId));
}
break;
}
}
break;
}
}
}
}