private async void UseActivatedArgs(IActivatedEventArgs args, INavigationService service) { if (service == null) { service = WindowContext.GetForCurrentView().NavigationServices.FirstOrDefault(); } if (service == null || args == null) { return; } if (args is ShareTargetActivatedEventArgs share) { var package = new DataPackage(); var operation = share.ShareOperation.Data; if (operation.AvailableFormats.Contains(StandardDataFormats.ApplicationLink)) { package.SetApplicationLink(await operation.GetApplicationLinkAsync()); } if (operation.AvailableFormats.Contains(StandardDataFormats.Bitmap)) { package.SetBitmap(await operation.GetBitmapAsync()); } //if (operation.Contains(StandardDataFormats.Html)) //{ // package.SetHtmlFormat(await operation.GetHtmlFormatAsync()); //} //if (operation.Contains(StandardDataFormats.Rtf)) //{ // package.SetRtf(await operation.GetRtfAsync()); //} if (operation.AvailableFormats.Contains(StandardDataFormats.StorageItems)) { package.SetStorageItems(await operation.GetStorageItemsAsync()); } if (operation.AvailableFormats.Contains(StandardDataFormats.Text)) { package.SetText(await operation.GetTextAsync()); } //if (operation.Contains(StandardDataFormats.Uri)) //{ // package.SetUri(await operation.GetUriAsync()); //} if (operation.AvailableFormats.Contains(StandardDataFormats.WebLink)) { package.SetWebLink(await operation.GetWebLinkAsync()); } var query = "tg://"; if (ApiInformation.IsPropertyPresent("Windows.ApplicationModel.DataTransfer.ShareTarget.ShareOperation", "Contacts")) { var contactId = await ContactsService.GetContactIdAsync(share.ShareOperation.Contacts.FirstOrDefault()); if (contactId is int userId) { var response = await _lifetime.ActiveItem.ProtoService.SendAsync(new CreatePrivateChat(userId, false)); if (response is Chat chat) { query = $"ms-contact-profile://meh?ContactRemoteIds=u" + userId; App.DataPackages[chat.Id] = package.GetView(); } else { App.DataPackages[0] = package.GetView(); } } else { App.DataPackages[0] = package.GetView(); } } else { App.DataPackages[0] = package.GetView(); } App.ShareOperation = share.ShareOperation; App.ShareWindow = _window; var options = new Windows.System.LauncherOptions(); options.TargetApplicationPackageFamilyName = Package.Current.Id.FamilyName; await Windows.System.Launcher.LaunchUriAsync(new Uri(query), options); } else if (args is VoiceCommandActivatedEventArgs voice) { SpeechRecognitionResult speechResult = voice.Result; string command = speechResult.RulePath[0]; if (command == "ShowAllDialogs") { service.NavigateToMain(null); } if (command == "ShowSpecificDialog") { //#TODO: Fix that this'll open a specific dialog service.NavigateToMain(null); } else { service.NavigateToMain(null); } } else if (args is ContactPanelActivatedEventArgs contact) { SetContactPanel(contact.ContactPanel); var backgroundBrush = Application.Current.Resources["PageHeaderBackgroundBrush"] as SolidColorBrush; contact.ContactPanel.HeaderColor = backgroundBrush.Color; var contactId = await ContactsService.GetContactIdAsync(contact.Contact.Id); if (contactId is int userId) { var response = await _lifetime.ActiveItem.ProtoService.SendAsync(new CreatePrivateChat(userId, false)); if (response is Chat chat) { service.NavigateToChat(chat); } else { ContactPanelFallback(service); } } else { ContactPanelFallback(service); } } else if (args is ProtocolActivatedEventArgs protocol) { if (service?.Frame?.Content is MainPage page) { page.Activate(protocol.Uri.ToString()); } else { service.NavigateToMain(protocol.Uri.ToString()); } if (App.ShareOperation != null) { App.ShareOperation.ReportCompleted(); App.ShareOperation = null; } if (App.ShareWindow != null) { try { await App.ShareWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { App.ShareWindow.Close(); App.ShareWindow = null; }); } catch { } } } else if (args is FileActivatedEventArgs file) { if (service?.Frame?.Content is MainPage page) { //page.Activate(launch); } else { service.NavigateToMain(string.Empty); } await new ThemePreviewPopup(file.Files[0].Path).ShowQueuedAsync(); } else { var activate = args as ToastNotificationActivatedEventArgs; var launched = args as LaunchActivatedEventArgs; var launch = activate?.Argument ?? launched?.Arguments; if (service?.Frame?.Content is MainPage page) { page.Activate(launch); } else { service.NavigateToMain(launch); } } }
//private static Dictionary<int, WindowContext> _windowContext = new Dictionary<int, WindowContext>(); //public static WindowContext GetForCurrentView() //{ // var id = Windows.UI.ViewManagement.ApplicationView.GetApplicationViewIdForWindow(Window.Current.CoreWindow); // if (_windowContext.TryGetValue(id, out WindowContext value)) // { // return value; // } // var context = new WindowContext(null, id); // _windowContext[id] = context; // return context; //} public static new TLWindowContext GetForCurrentView() { return(WindowContext.GetForCurrentView() as TLWindowContext); }
private async void UseActivatedArgs(IActivatedEventArgs args, INavigationService service) { if (service == null) { service = WindowContext.GetForCurrentView().NavigationServices.FirstOrDefault(); } if (service == null || args == null) { return; } if (args is ShareTargetActivatedEventArgs share) { var package = new DataPackage(); var operation = share.ShareOperation.Data; if (operation.Contains(StandardDataFormats.ApplicationLink)) { package.SetApplicationLink(await operation.GetApplicationLinkAsync()); } if (operation.Contains(StandardDataFormats.Bitmap)) { package.SetBitmap(await operation.GetBitmapAsync()); } //if (operation.Contains(StandardDataFormats.Html)) //{ // package.SetHtmlFormat(await operation.GetHtmlFormatAsync()); //} //if (operation.Contains(StandardDataFormats.Rtf)) //{ // package.SetRtf(await operation.GetRtfAsync()); //} if (operation.Contains(StandardDataFormats.StorageItems)) { package.SetStorageItems(await operation.GetStorageItemsAsync()); } if (operation.Contains(StandardDataFormats.Text)) { package.SetText(await operation.GetTextAsync()); } //if (operation.Contains(StandardDataFormats.Uri)) //{ // package.SetUri(await operation.GetUriAsync()); //} if (operation.Contains(StandardDataFormats.WebLink)) { package.SetWebLink(await operation.GetWebLinkAsync()); } App.ShareOperation = share.ShareOperation; App.DataPackage = package.GetView(); var options = new Windows.System.LauncherOptions(); options.TargetApplicationPackageFamilyName = Package.Current.Id.FamilyName; await Windows.System.Launcher.LaunchUriAsync(new Uri("tg://"), options); } else if (args is VoiceCommandActivatedEventArgs voice) { Execute.Initialize(); SpeechRecognitionResult speechResult = voice.Result; string command = speechResult.RulePath[0]; if (command == "ShowAllDialogs") { service.NavigateToMain(null); } if (command == "ShowSpecificDialog") { //#TODO: Fix that this'll open a specific dialog service.NavigateToMain(null); } else { service.NavigateToMain(null); } } else if (args is ContactPanelActivatedEventArgs contact) { SetContactPanel(contact.ContactPanel); var backgroundBrush = Application.Current.Resources["TelegramTitleBarBackgroundBrush"] as SolidColorBrush; contact.ContactPanel.HeaderColor = backgroundBrush.Color; var annotationStore = await ContactManager.RequestAnnotationStoreAsync(ContactAnnotationStoreAccessType.AppAnnotationsReadWrite); var store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite); if (store != null && annotationStore != null) { try { var full = await store.GetContactAsync(contact.Contact.Id); if (full == null) { ContactPanelFallback(service); } else { var annotations = await annotationStore.FindAnnotationsForContactAsync(full); var first = annotations.FirstOrDefault(); if (first == null) { ContactPanelFallback(service); } else { var remote = first.RemoteId; if (int.TryParse(remote.Substring(1), out int userId)) { var response = await _lifetime.ActiveItem.ProtoService.SendAsync(new CreatePrivateChat(userId, false)); if (response is Chat chat) { service.NavigateToChat(chat); } } else { ContactPanelFallback(service); } } } } catch (Exception ex) { if ((uint)ex.HResult == 0x80004004) { ContactPanelFallback(service); } } } else { ContactPanelFallback(service); } } else if (args is ProtocolActivatedEventArgs protocol) { Execute.Initialize(); if (App.ShareOperation != null) { App.ShareOperation.ReportCompleted(); App.ShareOperation = null; } if (service?.Frame?.Content is MainPage page) { page.Activate(protocol.Uri); } else { service.NavigateToMain(protocol.Uri.ToString()); } } //else if (args is CommandLineActivatedEventArgs commandLine && TryParseCommandLine(commandLine, out int id, out bool test)) //{ //} else { Execute.Initialize(); var activate = args as ToastNotificationActivatedEventArgs; var launched = args as LaunchActivatedEventArgs; var launch = activate?.Argument ?? launched?.Arguments; if (service?.Frame?.Content is MainPage page) { page.Activate(launch); } else { service.NavigateToMain(launch); } } }