Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAUI: first steps #241

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
uses: actions/[email protected]
with:
dotnet-version: '6.0.113'
- name: install maui workload
run: dotnet workload install maui
- name: configure
run: ./configure.sh
- name: build in DEBUG mode
Expand Down Expand Up @@ -96,7 +98,7 @@ jobs:
- name: Setup .NET SDK 6.0.x
uses: actions/[email protected]
with:
dotnet-version: '6.0.113'
dotnet-version: '6.0.x'
- name: configure
run: .\configure.bat
- name: build in DEBUG mode
Expand Down Expand Up @@ -182,10 +184,33 @@ jobs:

linux-github--dotnet-and-mono:
runs-on: ubuntu-22.04
env:
GtkSharpVersion: 3.24.24.95
DotnetVersion: 6.0.400
steps:
- uses: actions/checkout@v1
with:
submodules: false
submodules: true
- name: Setup .NET SDK ${{ env.DotnetVersion }}
uses: actions/[email protected]
with:
dotnet-version: ${{ env.DotnetVersion }}
- name: Install gtk workload
run: |
wget -O gtksharp.net.sdk.gtk.manifest-${{ env.DotnetVersion }}.nupkg https://globalcdn.nuget.org/packages/gtksharp.net.sdk.gtk.manifest-${{ env.DotnetVersion }}.$GtkSharpVersion.nupkg
DOTNET_DIR=/home/runner/.dotnet
WORKLOAD_MANIFEST_DIR=$DOTNET_DIR/sdk-manifests/${{ env.DotnetVersion }}/gtksharp.net.sdk.gtk
mkdir -p $WORKLOAD_MANIFEST_DIR/
unzip -j gtksharp.net.sdk.gtk.manifest-${{ env.DotnetVersion }}.nupkg "data/*" -d $WORKLOAD_MANIFEST_DIR/
rm gtksharp.net.sdk.gtk.manifest-${{ env.DotnetVersion }}.nupkg
# otherwise we get System.UnauthorizedAccessException: Access to the path '/home/runner/.dotnet/sdk-manifests/6.0.300/gtksharp.net.sdk.gtk/WorkloadManifest.json' is denied.
chmod 764 $WORKLOAD_MANIFEST_DIR/*
dotnet workload search
dotnet workload install gtk --skip-manifest-update
- name: Add Maui Nuget source
run: |
cd dependencies/maui
dotnet nuget add source --name nuget https://api.nuget.org/v3/index.json
- name: install missing dependencies
run: sudo apt install --yes fsharp nunit-console
- name: check mono version
Expand All @@ -194,6 +219,9 @@ jobs:
run: ./configure.sh
- name: build in DEBUG mode
run: make
- name: build Maui frontend
run: |
dotnet build src/GWallet.Frontend.Maui/GWallet.Frontend.Maui.fsproj --framework=net6.0-gtk
- name: sanity check
run: make sanitycheck
- name: unit tests
Expand Down
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,12 @@ fabric.properties
.fake
.ionide

# Maui generated code
src/GWallet.Frontend.Maui/WelcomePage.xaml
src/GWallet.Frontend.Maui/WelcomePage2.xaml
src/GWallet.Frontend.Maui/LoadingPage.xaml
src/GWallet.Frontend.Maui/BalancesPage.xaml
src/GWallet.Frontend.Maui/PairingFromPage.xaml
src/GWallet.Frontend.Maui/PairingToPage.xaml
src/GWallet.Frontend.Maui/SendPage.xaml
src/GWallet.Frontend.Maui/ReceivePage.xaml
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "scripts/fsx"]
path = scripts/fsx
url = https://github.com/nblockchain/fsx.git
[submodule "dependencies/maui"]
path = dependencies/maui
url = https://github.com/nblockchain/CrossMaui.git
1 change: 1 addition & 0 deletions dependencies/maui
Submodule maui added at bc8eb6
6 changes: 6 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"sdk": {
"version": "6.0.113",
"rollForward": "latestMinor"
}
}
33 changes: 33 additions & 0 deletions gwallet.maui.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31611.283
MinimumVisualStudioVersion = 10.0.40219.1
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "GWallet.Frontend.Maui", "src\GWallet.Frontend.Maui\GWallet.Frontend.Maui.fsproj", "{D6C1C0C8-FD57-476F-8A60-BA99D8346045}"
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "GWallet.Backend", "src\GWallet.Backend\GWallet.Backend.fsproj", "{DA2EFDCB-1A3B-4057-ADAE-3831DCFA4056}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D6C1C0C8-FD57-476F-8A60-BA99D8346045}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D6C1C0C8-FD57-476F-8A60-BA99D8346045}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D6C1C0C8-FD57-476F-8A60-BA99D8346045}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{D6C1C0C8-FD57-476F-8A60-BA99D8346045}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D6C1C0C8-FD57-476F-8A60-BA99D8346045}.Release|Any CPU.Build.0 = Release|Any CPU
{D6C1C0C8-FD57-476F-8A60-BA99D8346045}.Release|Any CPU.Deploy.0 = Release|Any CPU
{DA2EFDCB-1A3B-4057-ADAE-3831DCFA4056}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DA2EFDCB-1A3B-4057-ADAE-3831DCFA4056}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DA2EFDCB-1A3B-4057-ADAE-3831DCFA4056}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DA2EFDCB-1A3B-4057-ADAE-3831DCFA4056}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {61F7FB11-1E47-470C-91E2-47F8143E1572}
EndGlobalSection
EndGlobal
69 changes: 69 additions & 0 deletions scripts/make.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ open GWallet.Scripting
let UNIX_NAME = "geewallet"
let CONSOLE_FRONTEND = "GWallet.Frontend.Console"
let GTK_FRONTEND = "GWallet.Frontend.XF.Gtk"
let MAUI_PROJECT_FILE =
Path.Combine("src", "GWallet.Frontend.Maui", "GWallet.Frontend.Maui.fsproj")

type ProjectFile =
| XFFrontend
Expand Down Expand Up @@ -199,6 +201,11 @@ let BuildSolutionOrProject
Seq.append ["LEGACY_FRAMEWORK"] defineConstantsFromBuildConfig
else
defineConstantsFromBuildConfig
let defineConstantsSoFar =
if not(file.FullName.EndsWith "maui.sln") then
Seq.append ["XAMARIN"] defineConstantsSoFar
else
defineConstantsSoFar
let allDefineConstants =
match maybeConstant with
| Some constant -> Seq.append [constant] defineConstantsSoFar
Expand Down Expand Up @@ -247,6 +254,66 @@ let BuildSolutionOrProject
Environment.Exit 1
| _ -> ()

// 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"
"LoadingPage.xaml"
"BalancesPage.xaml"
"PairingFromPage.xaml"
"PairingToPage.xaml"
"ReceivePage.xaml"
"SendPage.xaml"
|]
for file in files do
let sourcePath = Path.Combine("src", "GWallet.Frontend.XF", file)
let destPath = Path.Combine("src", "GWallet.Frontend.Maui", file)

File.Copy(sourcePath, destPath, true)
let fileText = File.ReadAllText(destPath)
File.WriteAllText(
destPath,
fileText
.Replace("http://xamarin.com/schemas/2014/forms","http://schemas.microsoft.com/dotnet/2021/maui")
.Replace("clr-namespace:ZXing.Net.Mobile.Forms;assembly=ZXing.Net.Mobile.Forms","clr-namespace:ZXing.Net.Maui.Controls;assembly=ZXing.Net.MAUI.Controls")
.Replace("GWallet.Frontend.XF", "GWallet.Frontend.Maui")
.Replace("ZXingBarcodeImageView", "BarcodeGeneratorView")
)



let DotNetBuild
(solutionProjectFileName: string)
(binaryConfig: BinaryConfig)
(args: string)
(ignoreError: bool)
=
let configOption = sprintf "-c %s" (binaryConfig.ToString())
let buildArgs = (sprintf "build %s %s %s" configOption solutionProjectFileName args)
let buildProcess = Process.Execute ({ Command = "dotnet"; Arguments = buildArgs }, Echo.All)
match buildProcess.Result with
| Error _ ->
if not ignoreError then
Console.WriteLine()
Console.Error.WriteLine "dotnet build failed"
#if LEGACY_FRAMEWORK
PrintNugetVersion() |> ignore
#endif
Environment.Exit 1
else
()
| _ -> ()

// We have to build Maui project for android twice because the first time we get
// an error about Resource file not found. The second time it works.
// https://github.com/fabulous-dev/FSharp.Mobile.Templates/tree/55a1f3a0fd5cc397e48677ef4ff9241b360b0e84
let BuildMauiProject binaryConfig =
DotNetBuild MAUI_PROJECT_FILE binaryConfig "--framework net6.0-android" true
DotNetBuild MAUI_PROJECT_FILE binaryConfig "--framework net6.0-android" false

let JustBuild binaryConfig maybeConstant: Frontend*FileInfo =
let maybeBuildTool = Map.tryFind "BuildTool" buildConfigContents
let maybeLegacyBuildTool = Map.tryFind "LegacyBuildTool" buildConfigContents
Expand Down Expand Up @@ -310,6 +377,7 @@ let JustBuild binaryConfig maybeConstant: Frontend*FileInfo =
// somehow, msbuild doesn't restore the frontend dependencies (e.g. Xamarin.Forms) when targetting
// the {LINUX|MAC}_SOLUTION_FILE below, so we need this workaround. TODO: just finish migrating to MAUI(dotnet restore)
NugetRestore solution
CopyXamlFiles()
MSBuildRestoreAndBuild solution

Frontend.Console
Expand Down Expand Up @@ -409,6 +477,7 @@ let MakeAll (maybeConstant: Option<string>) =
#endif
let buildConfig = BinaryConfig.Debug
let frontend,_ = JustBuild buildConfig maybeConstant
CopyXamlFiles()
frontend,buildConfig

let RunFrontend (frontend: Frontend) (buildConfig: BinaryConfig) (maybeArgs: Option<string>) =
Expand Down
3 changes: 2 additions & 1 deletion scripts/sanitycheck.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ let FindOffendingPrintfUsage () =
"scripts{0}" +
"src{1}GWallet.Frontend.Console{0}" +
"src{1}GWallet.Backend.Tests{0}" +
"src{1}GWallet.Backend{1}FSharpUtil.fs",
"src{1}GWallet.Backend{1}FSharpUtil.fs{0}" +
"dependencies",
Path.PathSeparator,
Path.DirectorySeparatorChar
)
Expand Down
14 changes: 14 additions & 0 deletions src/GWallet.Frontend.Maui/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version = "1.0" encoding = "UTF-8" ?>
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:GWallet.Frontend.Maui"
x:Class="GWallet.Frontend.Maui.App">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
21 changes: 21 additions & 0 deletions src/GWallet.Frontend.Maui/App.xaml.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace GWallet.Frontend.Maui

open Microsoft.Maui
open Microsoft.Maui.Controls
open Microsoft.Maui.Controls.Xaml

type App() as this =
inherit Application()

do this.LoadFromXaml(typeof<App>) |> ignore
do this.MainPage <- Initialization.LandingPage()

#if GTK
override _.CreateWindow(activationState) =
let window = base.CreateWindow(activationState)
window.Created.Add(fun _ ->
let gtkWindow = MauiGtkApplication.Current.MainWindow
gtkWindow.Resize(500,1000)
)
window
#endif
Loading
Loading