diff --git a/.gitignore b/.gitignore index c3d36edb4..ea122132a 100644 --- a/.gitignore +++ b/.gitignore @@ -100,3 +100,4 @@ fabric.properties # Maui generated code src/GWallet.Frontend.Maui/WelcomePage.xaml src/GWallet.Frontend.Maui/WelcomePage2.xaml +src/GWallet.Frontend.Maui/LoadingPage.xaml diff --git a/scripts/make.fsx b/scripts/make.fsx index eb128587a..2021850d1 100644 --- a/scripts/make.fsx +++ b/scripts/make.fsx @@ -260,7 +260,7 @@ let BuildSolutionOrProject // TODO: we have to change this function to be the other way around (i.e. copy from Maui to XF) once we // have a finished version of Maui and we consider XF as legacy. let CopyXamlFiles() = - let files = [| "WelcomePage.xaml"; "WelcomePage2.xaml" |] + let files = [| "WelcomePage.xaml"; "WelcomePage2.xaml"; "LoadingPage.xaml" |] for file in files do let sourcePath = Path.Combine("src", "GWallet.Frontend.XF", file) let destPath = Path.Combine("src", "GWallet.Frontend.Maui", file) diff --git a/src/GWallet.Frontend.Maui/GWallet.Frontend.Maui.fsproj b/src/GWallet.Frontend.Maui/GWallet.Frontend.Maui.fsproj index d5c95c7b5..d63f18626 100644 --- a/src/GWallet.Frontend.Maui/GWallet.Frontend.Maui.fsproj +++ b/src/GWallet.Frontend.Maui/GWallet.Frontend.Maui.fsproj @@ -65,10 +65,14 @@ + + + LoadingPage.xaml + WelcomePage2.xaml diff --git a/src/GWallet.Frontend.XF/FrontendHelpers.fs b/src/GWallet.Frontend.XF/FrontendHelpers.fs index 85e643f6a..2a1ab8ac1 100644 --- a/src/GWallet.Frontend.XF/FrontendHelpers.fs +++ b/src/GWallet.Frontend.XF/FrontendHelpers.fs @@ -434,7 +434,7 @@ module FrontendHelpers = ), UseNativeScanning = true ) - +#endif let GetImageSource name = let thisAssembly = typeof.Assembly let thisAssemblyName = thisAssembly.GetName().Name @@ -463,5 +463,14 @@ module FrontendHelpers = let imageSource = CreateCurrencyImageSource currency readOnly size let currencyLogoImg = Image(Source = imageSource, IsVisible = true) currencyLogoImg + + let StartTimer(interval: TimeSpan, action: unit -> bool) = +#if XAMARIN + Device.StartTimer(interval, Func action) +#else + let timer = Application.Current.Dispatcher.CreateTimer(Interval = interval, IsRepeating = true) + timer.Tick.Add(fun _ -> + if not <| action() then timer.Stop() ) + timer.Start() #endif let DefaultDesktopWindowSize = 500, 1000 diff --git a/src/GWallet.Frontend.XF/Initialization.fs b/src/GWallet.Frontend.XF/Initialization.fs index b4d153b0f..cbc3c64e3 100644 --- a/src/GWallet.Frontend.XF/Initialization.fs +++ b/src/GWallet.Frontend.XF/Initialization.fs @@ -25,18 +25,12 @@ module Initialization = let internal LandingPage(): NavigationPage = GlobalInit () -#if XAMARIN let accounts = Account.GetAllActiveAccounts() -#endif let landingPage:Page = -#if XAMARIN if not (accounts.Any()) then (WelcomePage GlobalState) :> Page else (LoadingPage (GlobalState, true)) :> Page -#else - (WelcomePage GlobalState) :> Page -#endif let navPage = NavigationPage landingPage NavigationPage.SetHasNavigationBar(landingPage, false) diff --git a/src/GWallet.Frontend.XF/LoadingPage.xaml.fs b/src/GWallet.Frontend.XF/LoadingPage.xaml.fs index 787f4d3aa..66788afcb 100644 --- a/src/GWallet.Frontend.XF/LoadingPage.xaml.fs +++ b/src/GWallet.Frontend.XF/LoadingPage.xaml.fs @@ -1,11 +1,23 @@ -namespace GWallet.Frontend.XF +#if XAMARIN +namespace GWallet.Frontend.XF +#else +namespace GWallet.Frontend.Maui +#endif open System open System.Linq +#if !XAMARIN +open Microsoft.Maui +open Microsoft.Maui.Controls +open Microsoft.Maui.Controls.Xaml +open Microsoft.Maui.ApplicationModel +open Microsoft.Maui.Devices +#else open Xamarin.Forms open Xamarin.Forms.Xaml open Xamarin.Essentials +#endif open Fsdk open GWallet.Backend @@ -14,7 +26,11 @@ open GWallet.Backend /// true if just the logo should be shown first, and title text and loading text after some seconds, /// false if title text and loading text should be shown immediatly. /// +#if XAMARIN type LoadingPage(state: FrontendHelpers.IGlobalAppState, showLogoFirst: bool) as self = +#else +type LoadingPage(_state: FrontendHelpers.IGlobalAppState, showLogoFirst: bool) as self = +#endif inherit ContentPage() let _ = base.LoadFromXaml(typeof) @@ -26,6 +42,7 @@ type LoadingPage(state: FrontendHelpers.IGlobalAppState, showLogoFirst: bool) as let dotsMaxCount = 3 let loadingTextNoDots = loadingLabel.Text +#if XAMARIN let allAccounts = Account.GetAllActiveAccounts() let normalAccounts = allAccounts.OfType() |> List.ofSeq |> List.map (fun account -> account :> IAccount) @@ -50,8 +67,10 @@ type LoadingPage(state: FrontendHelpers.IGlobalAppState, showLogoFirst: bool) as } let PreLoadCurrencyImages(): Map = GetAllImages() |> Map.ofSeq - - let logoImageSource = FrontendHelpers.GetSizedImageSource "logo" 512 +#endif + + let logoImageSizeInPixels= 512 + let logoImageSource = FrontendHelpers.GetSizedImageSource "logo" logoImageSizeInPixels let logoImg = Image(Source = logoImageSource, IsVisible = true) let mutable keepAnimationTimerActive = true @@ -80,7 +99,7 @@ type LoadingPage(state: FrontendHelpers.IGlobalAppState, showLogoFirst: bool) as ) let dotsAnimationLength = TimeSpan.FromMilliseconds 500. - Device.StartTimer(dotsAnimationLength, Func UpdateDotsLabel) + FrontendHelpers.StartTimer(dotsAnimationLength, UpdateDotsLabel) do self.Init() @@ -88,6 +107,7 @@ type LoadingPage(state: FrontendHelpers.IGlobalAppState, showLogoFirst: bool) as new() = LoadingPage(DummyPageConstructorHelper.GlobalFuncToRaiseExceptionIfUsedAtRuntime(),false) member self.Transition(): unit = +#if XAMARIN let currencyImages = PreLoadCurrencyImages() let normalAccountsBalances = FrontendHelpers.CreateWidgetsForAccounts normalAccounts currencyImages false @@ -116,6 +136,11 @@ type LoadingPage(state: FrontendHelpers.IGlobalAppState, showLogoFirst: bool) as :> Page FrontendHelpers.SwitchToNewPageDiscardingCurrentOne self balancesPage } +#else + async { + () + } +#endif |> FrontendHelpers.DoubleCheckCompletionAsync false () @@ -123,12 +148,16 @@ type LoadingPage(state: FrontendHelpers.IGlobalAppState, showLogoFirst: bool) as member self.Init (): unit = if showLogoFirst then MainThread.BeginInvokeOnMainThread(fun _ -> +#if !XAMARIN && GTK + logoImg.WidthRequest <- float(logoImageSizeInPixels) / 2.0 + logoImg.HeightRequest <- float(logoImageSizeInPixels) / 2.0 +#endif mainLayout.Children.Add logoImg ) self.Transition() - Device.StartTimer(TimeSpan.FromSeconds 5.0, fun _ -> + FrontendHelpers.StartTimer(TimeSpan.FromSeconds 5.0, fun _ -> ShowLoadingText() false // do not run timer again diff --git a/src/GWallet.Frontend.XF/WelcomePage2.xaml.fs b/src/GWallet.Frontend.XF/WelcomePage2.xaml.fs index 3a8d9b748..d59aea8ac 100644 --- a/src/GWallet.Frontend.XF/WelcomePage2.xaml.fs +++ b/src/GWallet.Frontend.XF/WelcomePage2.xaml.fs @@ -19,12 +19,7 @@ open Xamarin.Essentials open GWallet.Backend -#if !XAMARIN -// state and masterPrivateKeyGenerationTask are unused for now in MAUI until LoadingPage is ported -type WelcomePage2(_state: FrontendHelpers.IGlobalAppState, _masterPrivateKeyGenerationTask: Task>) = -#else type WelcomePage2(state: FrontendHelpers.IGlobalAppState, masterPrivateKeyGenerationTask: Task>) = -#endif inherit ContentPage() let _ = base.LoadFromXaml(typeof) @@ -68,16 +63,12 @@ type WelcomePage2(state: FrontendHelpers.IGlobalAppState, masterPrivateKeyGenera ToggleInputWidgetsEnabledOrDisabled false async { -#if XAMARIN let! privateKeyBytes = Async.AwaitTask masterPrivateKeyGenerationTask do! Account.CreateAllAccounts privateKeyBytes password.Text let loadingPage () = LoadingPage (state, false) :> Page FrontendHelpers.SwitchToNewPageDiscardingCurrentOne self loadingPage -#else - () -#endif } |> FrontendHelpers.DoubleCheckCompletionAsync false member __.OnPasswordTextChanged(_sender: Object, _args: EventArgs) =