-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathApp.xaml.cs
executable file
·418 lines (371 loc) · 18.1 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
//
// This is the source code of Telegram for Windows Phone v. 3.x.x.
// It is licensed under GNU GPL v. 2 or later.
// You should have received a copy of the license in this archive (see LICENSE).
//
// Copyright Evgeny Nadymov, 2013-present.
//
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using TelegramClient.Services;
using TelegramClient.ViewModels.Additional;
#if WP81
using Windows.ApplicationModel.DataTransfer.ShareTarget;
using Windows.ApplicationModel.Activation;
#endif
using Caliburn.Micro;
using Microsoft.Phone.Shell;
using TelegramClient.ViewModels.Dialogs;
using TelegramClient.ViewModels.Passport;
using TelegramClient.Views.Dialogs;
using TelegramClient.Views.Passport;
#if WP8
using Windows.Storage;
#endif
namespace TelegramClient
{
public partial class App : Application
{
/// <summary>
/// Provides easy access to the root frame of the Phone Application.
/// </summary>
/// <returns>The root frame of the Phone Application.</returns>
//public PhoneApplicationFrame RootFrame { get; private set; }
public static Stopwatch Timer = Stopwatch.StartNew();
public static Stopwatch StartupStimer = Stopwatch.StartNew();
public static void Log(string str)
{
Debug.WriteLine("{0} {1}", StartupStimer.Elapsed, str);
}
/// <summary>
/// Constructor for the Application object.
/// </summary>
public App()
{
Log("App start .ctor");
Telegram.Api.Helpers.Execute.IsForegroundApp = true;
//var color = Colors.Magenta;
//Resources.Remove("PhoneAccentColor");
//Resources.Add("PhoneAccentColor", color);
//((SolidColorBrush)Resources["PhoneAccentBrush"]).Color = color;
// Standard Silverlight initialization
InitializeComponent();
//RootVisual = new PhoneApplicationFrame();
Log("App start InitilizeComponent");
// Show graphics profiling information while debugging.
if (Debugger.IsAttached)
{
// Display the current frame rate counters.
// Show the areas of the app that are being redrawn in each frame.
//Application.Current.Host.Settings.EnableRedrawRegions = true;
// Enable non-production analysis visualization mode,
// which shows areas of a page that are handed off to GPU with a colored overlay.
//Application.Current.Host.Settings.EnableCacheVisualization = true;
// Disable the application idle detection by setting the UserIdleDetectionMode property of the
// application's PhoneApplicationService object to Disabled.
// Caution:- Use this under debug mode only. Application that disables user idle detection will continue to run
// and consume battery power when the user is not using the phone.
PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
}
//Current.Host.Settings.EnableRedrawRegions = true;
//Current.Host.Settings.EnableFrameRateCounter = true;
#if DEBUG
Current.Host.Settings.EnableFrameRateCounter = true;
//Current.Host.Settings.EnableRedrawRegions = true;
#endif
#if WP81
PhoneApplicationService.Current.Activated += OnActivated;
PhoneApplicationService.Current.ContractActivated += OnContractActivated;
#endif
//#if WP8
// ApplicationLifetimeObjects.Add(new XnaAsyncDispatcher(TimeSpan.FromMilliseconds(50)));
//#endif
Windows.ApplicationModel.Core.CoreApplication.UnhandledErrorDetected += (sender, args) =>
{
try
{
Telegram.Logs.Log.SyncWrite(args.UnhandledError.ToString());
#if DEBUG
Caliburn.Micro.Execute.OnUIThread(() => MessageBox.Show("UnhandledErrorDetected\n" + args.UnhandledError));
#endif
}
catch (Exception ex)
{
}
if (!args.UnhandledError.Handled)
{
try
{
args.UnhandledError.Propagate();
}
catch (Exception ex)
{
try
{
Telegram.Logs.Log.SyncWrite(args.UnhandledError.ToString());
#if DEBUG
Caliburn.Micro.Execute.OnUIThread(() => MessageBox.Show("UnhandledErrorDetected Propogate\n" + args.UnhandledError));
#endif
}
catch (Exception e)
{
}
}
}
//args.UnhandledError.Handled = true;
};
UnhandledException += (sender, args) =>
{
try
{
Telegram.Logs.Log.SyncWrite(args.ExceptionObject.ToString());
#if DEBUG
Caliburn.Micro.Execute.OnUIThread(() => MessageBox.Show(args.ExceptionObject.ToString()));
#endif
}
catch (Exception ex)
{
}
args.Handled = true;
};
Log("App stop .ctor");
}
public ChooseFileInfo ChooseFileInfo { get; set; }
#if WP81
public ShareOperation ShareOperation { get; set; }
#endif
private void OnActivated(object sender, ActivatedEventArgs e)
{
}
public bool Offline { get; set; }
#if WP8
public static IReadOnlyCollection<StorageFile> Photos { get; set; }
public static StorageFile Video { get; set; }
#endif
#if WP81
private void OnContractActivated(object sender, IActivatedEventArgs e)
{
var saveArgs = e as FileSavePickerContinuationEventArgs;
if (saveArgs != null)
{
object from;
if (saveArgs.ContinuationData != null
&& saveArgs.ContinuationData.TryGetValue("From", out from))
{
if (string.Equals(from, "DialogDetailsView"))
{
Telegram.Api.Helpers.Execute.BeginOnThreadPool(() => DialogDetailsViewModel.SaveFile(saveArgs.File));
return;
}
}
}
var args = e as FileOpenPickerContinuationEventArgs;
if (args != null)
{
object from;
if (args.ContinuationData != null
&& args.ContinuationData.TryGetValue("From", out from))
{
if (string.Equals(from, "DialogDetailsView"))
{
var contentControl = RootVisual as ContentControl;
if (contentControl != null)
{
var dialogDetailsView = contentControl.Content as DialogDetailsView;
if (dialogDetailsView != null)
{
var dialogDetailsViewModel = dialogDetailsView.DataContext as DialogDetailsViewModel;
if (dialogDetailsViewModel != null)
{
object type;
if (!args.ContinuationData.TryGetValue("Type", out type))
{
type = "Document";
}
if (string.Equals(type, "Video"))
{
var file = args.Files.FirstOrDefault();
Telegram.Api.Helpers.Execute.BeginOnThreadPool(() => dialogDetailsViewModel.SendVideo(file));
}
else if (string.Equals(type, "Image"))
{
var file = args.Files.FirstOrDefault();
if (file != null)
{
#if MULTIPLE_PHOTOS
Photos = args.Files;
return;
#endif
#if WP81
Telegram.Api.Helpers.Execute.BeginOnThreadPool(async () =>
{
var randomStream = await file.OpenReadAsync();
await ChooseAttachmentViewModel.Handle(IoC.Get<IStateService>(), randomStream, file.Name);
//MessageBox.Show("OnContractActivated after handle");
dialogDetailsViewModel.BackwardInAnimationComplete();
});
#else
Telegram.Api.Helpers.Execute.BeginOnThreadPool(async () =>
{
var randomStream = await file.OpenReadAsync();
var chosenPhoto = randomStream.AsStreamForRead();
//MessageBox.Show("OnContractActivated stream");
Telegram.Api.Helpers.Execute.BeginOnUIThread(() =>
{
ChooseAttachmentViewModel.Handle(IoC.Get<IStateService>(), chosenPhoto, file.Name);
//MessageBox.Show("OnContractActivated after handle");
dialogDetailsViewModel.BackwardInAnimationComplete();
});
});
#endif
}
}
else
{
var file = args.Files.FirstOrDefault();
Telegram.Api.Helpers.Execute.BeginOnThreadPool(() => dialogDetailsViewModel.SendDocument(file));
}
return;
}
}
}
}
else if (string.Equals(from, "SecretDialogDetailsView"))
{
var contentControl = RootVisual as ContentControl;
if (contentControl != null)
{
var dialogDetailsView = contentControl.Content as SecretDialogDetailsView;
if (dialogDetailsView != null)
{
var secretDialogDetailsViewModel = dialogDetailsView.DataContext as SecretDialogDetailsViewModel;
if (secretDialogDetailsViewModel != null)
{
object type;
if (!args.ContinuationData.TryGetValue("Type", out type))
{
type = "Document";
}
if (string.Equals(type, "Video"))
//{
// var file = args.Files.FirstOrDefault();
// Telegram.Api.Helpers.Execute.BeginOnThreadPool(() => dialogDetailsViewModel.EditVideo(file));
//}
//else
{
var file = args.Files.FirstOrDefault();
Telegram.Api.Helpers.Execute.BeginOnThreadPool(() => secretDialogDetailsViewModel.SendDocument(file));
}
else if (string.Equals(type, "Image"))
{
var file = args.Files.FirstOrDefault();
if (file != null)
{
#if MULTIPLE_PHOTOS
Photos = args.Files;
return;
#endif
#if WP81
Telegram.Api.Helpers.Execute.BeginOnThreadPool(async () =>
{
var randomStream = await file.OpenReadAsync();
await ChooseAttachmentViewModel.Handle(IoC.Get<IStateService>(), randomStream, file.Name);
secretDialogDetailsViewModel.OnBackwardInAnimationComplete();
});
#else
Telegram.Api.Helpers.Execute.BeginOnThreadPool(async () =>
{
var randomStream = await file.OpenReadAsync();
var chosenPhoto = randomStream.AsStreamForRead();
Telegram.Api.Helpers.Execute.BeginOnUIThread(() =>
{
ChooseAttachmentViewModel.Handle(IoC.Get<IStateService>(), chosenPhoto, file.Name);
});
});
#endif
}
}
else
{
var file = args.Files.FirstOrDefault();
Telegram.Api.Helpers.Execute.BeginOnThreadPool(() => secretDialogDetailsViewModel.SendDocument(file));
}
return;
}
}
}
}
else if (string.Equals(from, "ResidentialAddressView"))
{
var contentControl = RootVisual as ContentControl;
if (contentControl != null)
{
var view = contentControl.Content as ResidentialAddressView;
if (view != null)
{
object type;
if (!args.ContinuationData.TryGetValue("Type", out type))
{
type = "Document";
}
if (type is string)
{
var viewModel = view.DataContext as ResidentialAddressViewModel;
if (viewModel != null)
{
var file = args.Files.FirstOrDefault();
Telegram.Api.Helpers.Execute.BeginOnThreadPool(() => viewModel.SendDocument(type.ToString(), file));
return;
}
}
}
}
}
else if (string.Equals(from, "PersonalDetailsView"))
{
var contentControl = RootVisual as ContentControl;
if (contentControl != null)
{
object type;
if (!args.ContinuationData.TryGetValue("Type", out type))
{
type = "Document";
}
if (type is string)
{
var view = contentControl.Content as PersonalDetailsView;
if (view != null)
{
var viewModel = view.DataContext as PersonalDetailsViewModel;
if (viewModel != null)
{
var file = args.Files.FirstOrDefault();
Telegram.Api.Helpers.Execute.BeginOnThreadPool(() => viewModel.SendDocument(type.ToString(), file));
return;
}
}
}
}
}
}
}
}
#endif
#region Delayed Bugsense exceptions
private readonly object _bugsenseSyncRoot = new object();
public bool IsBugsenseInitialized { get; set; }
#endregion
}
public class ChooseFileInfo
{
public DateTime Time { get; set; }
public ChooseFileInfo(DateTime time)
{
Time = time;
}
}
}