using System.Reflection; using CDPShared; using CircleViewerMaui.Popups; using CommunityToolkit.Maui.Views; using Syncfusion.Maui.PdfViewer; namespace CircleViewerMaui; public partial class MainPage : ContentPage { int count = 0; // private CDPWorker _cdp; Timer _timer; Boolean _bConnected = false; public MainPage() { using (LogMethod.Log(MethodBase.GetCurrentMethod().ReflectedType.Name)) { InitializeComponent(); _timer = new Timer(IsReady, null, 250, 250); } } void IsReady(object state) { if (_bConnected != App.CDP.Ready) { _bConnected = App.CDP.Ready; OnReady(); _timer = null; } } void OnReady() { // Device.InvokeOnMainThreadAsync(() => { lblConnected.Text = "Connected"; }); } public async Task OpenCirFileAsync() { var fileTypes = new FilePickerFileType(new Dictionary> { { DevicePlatform.iOS, new[] { "public.cir" } }, { DevicePlatform.Android, new[] { "application/cir" } }, { DevicePlatform.WinUI, new[] { ".cir" } }, { DevicePlatform.macOS, new[] { ".cir" } } }); var options = new PickOptions { FileTypes = fileTypes, PickerTitle = "Open .cir File" }; var result = await FilePicker.PickAsync(options); if (result != null) { return result.FullPath; } return null; } async Task TestPopup() { var popup = new NewInvite("AS3RT3", "POEW"); popup.CanBeDismissedByTappingOutsideOfPopup = false; this.ShowPopup(popup); } private async void onOpenClicked(object sender, EventArgs e) { // await TestPopup(); var filePath = await OpenCirFileAsync(); if (filePath != null) { ViewFileAsync(filePath); } } async void ViewFileAsync(string fileToLoad) { using (LogMethod.Log(MethodBase.GetCurrentMethod().ReflectedType.Name)) { var result = await App.CDP.Decrypt(fileToLoad); if (result.Status.Result.GetValueOrDefault(false)) { byte[] buf = Convert.FromBase64String(result.DecryptedData); string ext = Path.GetExtension(result.FileName); PdfViewer.DocumentSource = new MemoryStream(buf); } } } }