Add support for Wasm, fonts, loading.

This commit is contained in:
Jérôme Laban 2019-05-15 11:26:44 -04:00
commit 8ae0af3e25
12 changed files with 307 additions and 181 deletions

Binary file not shown.

View file

@ -10,137 +10,142 @@ using System.Text;
namespace CalculationManager namespace CalculationManager
{ {
public static class NativeDispatch
{
[DllImport("CalcManager")]
public static extern int CalculatorManager_Create(ref CalculatorManager_CreateParams parms);
[DllImport("CalcManager")]
public static extern void CalculatorManager_SendCommand(int instance, Command command);
private delegate int GetCEngineStringFunc(int state, string id);
private delegate void BinaryOperatorReceivedFunc(int state);
private delegate void SetPrimaryDisplayCallbackFunc(int state, string displayStringValue, bool isError);
private delegate void SetIsInErrorCallbackFunc(int state, bool isError);
private delegate void SetParenthesisNumberCallbackFunc(int state, int parenthesisCount);
private delegate void MaxDigitsReachedCallbackFunc(int state);
private delegate void MemoryItemChangedCallbackFunc(int state, int indexOfMemory);
private delegate void OnHistoryItemAddedCallbackFunc(int state, int addedItemIndex);
private delegate void OnNoRightParenAddedCallbackFunc(int state);
private delegate void SetExpressionDisplayCallbackFunc(int state);
private delegate void SetMemorizedNumbersCallbackFunc(int state, string[] newMemorizedNumbers);
private static GetCEngineStringFunc _getCEngineStringCallback = GetCEngineStringCallback;
private static BinaryOperatorReceivedFunc _binaryOperatorReceivedCallback = BinaryOperatorReceivedCallback;
private static SetPrimaryDisplayCallbackFunc _setPrimaryDisplayCallback = SetPrimaryDisplayCallback;
private static SetIsInErrorCallbackFunc _setIsInErrorCallback = SetIsInErrorCallback;
private static SetParenthesisNumberCallbackFunc _setParenthesisNumberCallback = SetParenthesisNumberCallback;
private static MaxDigitsReachedCallbackFunc _maxDigitsReachedCallback = MaxDigitsReachedCallback;
private static MemoryItemChangedCallbackFunc _memoryItemChangedCallback = MemoryItemChangedCallback;
private static OnHistoryItemAddedCallbackFunc _onHistoryItemAddedCallback = OnHistoryItemAddedCallback;
private static OnNoRightParenAddedCallbackFunc _onNoRightParenAddedCallback = OnNoRightParenAddedCallback;
private static SetExpressionDisplayCallbackFunc _setExpressionDisplayCallback = SetExpressionDisplayCallback;
private static SetMemorizedNumbersCallbackFunc _setMemorizedNumbersCallback = SetMemorizedNumbersCallback;
public static void MaxDigitsReachedCallback(int state)
{
var manager = GCHandle.FromIntPtr((IntPtr)state).Target as CalculatorDisplay;
manager.MaxDigitsReached();
Debug.WriteLine($"CalculatorManager.MaxDigitsReachedCallback");
}
public static void MemoryItemChangedCallback(int state, int indexOfMemory)
{
var manager = GCHandle.FromIntPtr((IntPtr)state).Target as CalculatorDisplay;
manager.MemoryItemChanged(indexOfMemory);
Debug.WriteLine($"CalculatorManager.MemoryItemChangedCallback({indexOfMemory})");
}
public static void OnHistoryItemAddedCallback(int state, int addedItemIndex)
{
var manager = GCHandle.FromIntPtr((IntPtr)state).Target as CalculatorDisplay;
manager.OnHistoryItemAdded(addedItemIndex);
Debug.WriteLine($"CalculatorManager.OnHistoryItemAddedCallback({addedItemIndex})");
}
public static void OnNoRightParenAddedCallback(int state)
{
var manager = GCHandle.FromIntPtr((IntPtr)state).Target as CalculatorDisplay;
manager.OnNoRightParenAdded();
Debug.WriteLine($"CalculatorManager.OnNoRightParenAddedCallback");
}
public static void SetExpressionDisplayCallback(int state)
{
var manager = GCHandle.FromIntPtr((IntPtr)state).Target as CalculatorDisplay;
// manager.SetExpressionDisplay();
Debug.WriteLine($"CalculatorManager.SetExpressionDisplayCallback");
}
public static void SetMemorizedNumbersCallback(int state, string[] newMemorizedNumbers)
{
var manager = GCHandle.FromIntPtr((IntPtr)state).Target as CalculatorDisplay;
manager.SetMemorizedNumbers(newMemorizedNumbers.ToList());
Debug.WriteLine($"CalculatorManager.SetMemorizedNumbersCallback({string.Join(";", newMemorizedNumbers)})");
}
public static void SetParenthesisNumberCallback(int state, int parenthesisCount)
{
var manager = GCHandle.FromIntPtr((IntPtr)state).Target as CalculatorDisplay;
manager.SetParenthesisNumber(parenthesisCount);
Debug.WriteLine($"CalculatorManager.SetParenthesisNumberCallback({parenthesisCount})");
}
public static void BinaryOperatorReceivedCallback(int state)
{
var manager = GCHandle.FromIntPtr((IntPtr)state).Target as CalculatorDisplay;
manager.BinaryOperatorReceived();
Debug.WriteLine($"CalculatorManager.BinaryOperatorReceivedCallback");
}
public static void SetPrimaryDisplayCallback(int state, string displayStringValue, bool isError)
{
var manager = GCHandle.FromIntPtr((IntPtr)state).Target as CalculatorDisplay;
manager.SetPrimaryDisplay(displayStringValue, isError);
Debug.WriteLine($"CalculatorManager.SetPrimaryDisplayCallback({displayStringValue}, {isError})");
}
public static void SetIsInErrorCallback(int state, bool isError)
{
var manager = GCHandle.FromIntPtr((IntPtr)state).Target as CalculatorDisplay;
manager.SetIsInError(isError);
Debug.WriteLine($"CalculatorManager.SetIsInErrorCallback({isError})");
}
public static int GetCEngineStringCallback(int state, string resourceId)
{
var provider = GCHandle.FromIntPtr((IntPtr)state).Target as EngineResourceProvider;
var ret = provider.GetCEngineString(resourceId) ?? "";
var retBytes = Encoding.UTF8.GetBytes(ret);
var retPtr = Marshal.AllocHGlobal(retBytes.Length + 1);
Marshal.WriteByte(retPtr + retBytes.Length, 0);
Marshal.Copy(retBytes, 0, retPtr, retBytes.Length);
Debug.WriteLine($"CalculatorManager.GetCEngineStringCallback({resourceId},{ret})");
return (int)retPtr;
}
}
public partial class CalculatorManager : ICalcDisplay public partial class CalculatorManager : ICalcDisplay
{ {
[DllImport("CalcManager")]
public static extern IntPtr CalculatorManager_Create(ref CalculatorManager_CreateParams parms);
[DllImport("CalcManager")] private GCHandle _displayCallbackHandle;
public static extern void CalculatorManager_SendCommand(IntPtr instance, Command command); private GCHandle _resourceProviderHandle;
private readonly int _nativeManager;
private delegate IntPtr GetCEngineStringFunc(IntPtr state, string id); }
private delegate void BinaryOperatorReceivedFunc(IntPtr state);
private delegate void SetPrimaryDisplayCallbackFunc(IntPtr state, string displayStringValue, bool isError);
private delegate void SetIsInErrorCallbackFunc(IntPtr state, bool isError);
private delegate void SetParenthesisNumberCallbackFunc(IntPtr state, int parenthesisCount);
private delegate void MaxDigitsReachedCallbackFunc(IntPtr state);
private delegate void MemoryItemChangedCallbackFunc(IntPtr state, int indexOfMemory);
private delegate void OnHistoryItemAddedCallbackFunc(IntPtr state, int addedItemIndex);
private delegate void OnNoRightParenAddedCallbackFunc(IntPtr state);
private delegate void SetExpressionDisplayCallbackFunc(IntPtr state);
private delegate void SetMemorizedNumbersCallbackFunc(IntPtr state, string[] newMemorizedNumbers);
private static GetCEngineStringFunc _getCEngineStringCallback = GetCEngineStringCallback;
private static BinaryOperatorReceivedFunc _binaryOperatorReceivedCallback = BinaryOperatorReceivedCallback;
private static SetPrimaryDisplayCallbackFunc _setPrimaryDisplayCallback = SetPrimaryDisplayCallback;
private static SetIsInErrorCallbackFunc _setIsInErrorCallback = SetIsInErrorCallback;
private static SetParenthesisNumberCallbackFunc _setParenthesisNumberCallback = SetParenthesisNumberCallback;
private static MaxDigitsReachedCallbackFunc _maxDigitsReachedCallback = MaxDigitsReachedCallback;
private static MemoryItemChangedCallbackFunc _memoryItemChangedCallback = MemoryItemChangedCallback;
private static OnHistoryItemAddedCallbackFunc _onHistoryItemAddedCallback = OnHistoryItemAddedCallback;
private static OnNoRightParenAddedCallbackFunc _onNoRightParenAddedCallback = OnNoRightParenAddedCallback;
private static SetExpressionDisplayCallbackFunc _setExpressionDisplayCallback = SetExpressionDisplayCallback;
private static SetMemorizedNumbersCallbackFunc _setMemorizedNumbersCallback = SetMemorizedNumbersCallback;
private GCHandle _displayCallbackHandle;
private GCHandle _resourceProviderHandle;
private readonly IntPtr _nativeManager;
private static void MaxDigitsReachedCallback(IntPtr state)
{
var manager = GCHandle.FromIntPtr(state).Target as CalculatorDisplay;
manager.MaxDigitsReached();
Debug.WriteLine($"CalculatorManager.MaxDigitsReachedCallback");
}
private static void MemoryItemChangedCallback(IntPtr state, int indexOfMemory)
{
var manager = GCHandle.FromIntPtr(state).Target as CalculatorDisplay;
manager.MemoryItemChanged(indexOfMemory);
Debug.WriteLine($"CalculatorManager.MemoryItemChangedCallback({indexOfMemory})");
}
private static void OnHistoryItemAddedCallback(IntPtr state, int addedItemIndex)
{
var manager = GCHandle.FromIntPtr(state).Target as CalculatorDisplay;
manager.OnHistoryItemAdded(addedItemIndex);
Debug.WriteLine($"CalculatorManager.OnHistoryItemAddedCallback({addedItemIndex})");
}
private static void OnNoRightParenAddedCallback(IntPtr state)
{
var manager = GCHandle.FromIntPtr(state).Target as CalculatorDisplay;
manager.OnNoRightParenAdded();
Debug.WriteLine($"CalculatorManager.OnNoRightParenAddedCallback");
}
private static void SetExpressionDisplayCallback(IntPtr state)
{
var manager = GCHandle.FromIntPtr(state).Target as CalculatorDisplay;
// manager.SetExpressionDisplay();
Debug.WriteLine($"CalculatorManager.SetExpressionDisplayCallback");
}
private static void SetMemorizedNumbersCallback(IntPtr state, string[] newMemorizedNumbers)
{
var manager = GCHandle.FromIntPtr(state).Target as CalculatorDisplay;
manager.SetMemorizedNumbers(newMemorizedNumbers.ToList());
Debug.WriteLine($"CalculatorManager.SetMemorizedNumbersCallback({string.Join(";", newMemorizedNumbers)})");
}
private static void SetParenthesisNumberCallback(IntPtr state, int parenthesisCount)
{
var manager = GCHandle.FromIntPtr(state).Target as CalculatorDisplay;
manager.SetParenthesisNumber(parenthesisCount);
Debug.WriteLine($"CalculatorManager.SetParenthesisNumberCallback({parenthesisCount})");
}
private static void BinaryOperatorReceivedCallback(IntPtr state)
{
var manager = GCHandle.FromIntPtr(state).Target as CalculatorDisplay;
manager.BinaryOperatorReceived();
Debug.WriteLine($"CalculatorManager.BinaryOperatorReceivedCallback");
}
private static void SetPrimaryDisplayCallback(IntPtr state, string displayStringValue, bool isError)
{
var manager = GCHandle.FromIntPtr(state).Target as CalculatorDisplay;
manager.SetPrimaryDisplay(displayStringValue, isError);
Debug.WriteLine($"CalculatorManager.SetPrimaryDisplayCallback({displayStringValue}, {isError})");
}
private static void SetIsInErrorCallback(IntPtr state, bool isError)
{
var manager = GCHandle.FromIntPtr(state).Target as CalculatorDisplay;
manager.SetIsInError(isError);
Debug.WriteLine($"CalculatorManager.SetIsInErrorCallback({isError})");
}
private static IntPtr GetCEngineStringCallback(IntPtr state, string resourceId)
{
var provider = GCHandle.FromIntPtr(state).Target as EngineResourceProvider;
var ret = provider.GetCEngineString(resourceId) ?? "";
var retBytes = Encoding.UTF8.GetBytes(ret);
var retPtr = Marshal.AllocHGlobal(retBytes.Length+1);
Marshal.WriteByte(retPtr + retBytes.Length, 0);
Marshal.Copy(retBytes, 0, retPtr, retBytes.Length);
Debug.WriteLine($"CalculatorManager.GetCEngineStringCallback({resourceId},{ret})");
return retPtr;
}
}
} }

View file

@ -6,6 +6,8 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using Uno;
using Uno.Foundation;
namespace CalculationManager namespace CalculationManager
{ {
@ -100,13 +102,36 @@ namespace CalculationManager
public CalculatorManager(ref CalculatorDisplay displayCallback, ref EngineResourceProvider resourceProvider) public CalculatorManager(ref CalculatorDisplay displayCallback, ref EngineResourceProvider resourceProvider)
{ {
Debug.WriteLine($"new CalculatorManager"); Debug.WriteLine($"new CalculatorManager");
displayCallback = new CalculatorDisplay(); displayCallback = new CalculatorDisplay();
resourceProvider = new EngineResourceProvider(); resourceProvider = new EngineResourceProvider();
_displayCallbackHandle = GCHandle.Alloc(displayCallback); _displayCallbackHandle = GCHandle.Alloc(displayCallback);
_resourceProviderHandle = GCHandle.Alloc(resourceProvider); _resourceProviderHandle = GCHandle.Alloc(resourceProvider);
#if __WASM__
var rawPtrs = WebAssemblyRuntime.InvokeJS("CalcManager.registerCallbacks()");
var ptrs = rawPtrs.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
var p = new CalculatorManager_CreateParams
{
CalculatorState = GCHandle.ToIntPtr(_displayCallbackHandle),
ResourceState = GCHandle.ToIntPtr(_resourceProviderHandle),
GetCEngineString = (IntPtr)int.Parse(ptrs[0]),
BinaryOperatorReceived = (IntPtr)int.Parse(ptrs[1]),
SetPrimaryDisplay = (IntPtr)int.Parse(ptrs[2]),
SetIsInError = (IntPtr)int.Parse(ptrs[3]),
SetParenthesisNumber = (IntPtr)int.Parse(ptrs[4]),
MaxDigitsReached = (IntPtr)int.Parse(ptrs[5]),
MemoryItemChanged = (IntPtr)int.Parse(ptrs[6]),
OnHistoryItemAdded = (IntPtr)int.Parse(ptrs[7]),
OnNoRightParenAdded = (IntPtr)int.Parse(ptrs[8]),
SetExpressionDisplay = (IntPtr)int.Parse(ptrs[9]),
SetMemorizedNumbers = (IntPtr)int.Parse(ptrs[10]),
};
#else
var p = new CalculatorManager_CreateParams var p = new CalculatorManager_CreateParams
{ {
CalculatorState = GCHandle.ToIntPtr(_displayCallbackHandle), CalculatorState = GCHandle.ToIntPtr(_displayCallbackHandle),
@ -125,8 +150,11 @@ namespace CalculationManager
SetMemorizedNumbers = Marshal.GetFunctionPointerForDelegate(_setMemorizedNumbersCallback), SetMemorizedNumbers = Marshal.GetFunctionPointerForDelegate(_setMemorizedNumbersCallback),
}; };
_nativeManager = CalculatorManager_Create(ref p); #endif
} Debug.WriteLine($"-> CalculatorManager_Create");
_nativeManager = NativeDispatch.CalculatorManager_Create(ref p);
Debug.WriteLine($"<- CalculatorManager_Create");
}
public void Reset(bool clearMemory = true) => throw new NotImplementedException(); public void Reset(bool clearMemory = true) => throw new NotImplementedException();
public void SetStandardMode() => throw new NotImplementedException(); public void SetStandardMode() => throw new NotImplementedException();
@ -136,7 +164,7 @@ namespace CalculationManager
{ {
Debug.WriteLine($"CalculatorManager.SendCommand({command})"); Debug.WriteLine($"CalculatorManager.SendCommand({command})");
CalculatorManager_SendCommand(_nativeManager, command); NativeDispatch.CalculatorManager_SendCommand(_nativeManager, command);
} }
public List<char> SerializeCommands() => throw new NotImplementedException(); public List<char> SerializeCommands() => throw new NotImplementedException();

View file

@ -225,6 +225,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="$(MSBuildThisFileDirectory)Assets\CalcMDL2.ttf" /> <Content Include="$(MSBuildThisFileDirectory)Assets\CalcMDL2.ttf" />
<Content Include="$(MSBuildThisFileDirectory)Assets\CalcMDL2.woff" />
<Content Include="$(MSBuildThisFileDirectory)Assets\CalculatorAppList.targetsize-96.png" /> <Content Include="$(MSBuildThisFileDirectory)Assets\CalculatorAppList.targetsize-96.png" />
<Content Include="$(MSBuildThisFileDirectory)Assets\CalculatorLargeTile.contrast-white_scale-400.png" /> <Content Include="$(MSBuildThisFileDirectory)Assets\CalculatorLargeTile.contrast-white_scale-400.png" />
<Content Include="$(MSBuildThisFileDirectory)Assets\CalculatorMedTile.contrast-white_scale-400.png" /> <Content Include="$(MSBuildThisFileDirectory)Assets\CalculatorMedTile.contrast-white_scale-400.png" />

View file

@ -1,10 +1,13 @@
<ResourceDictionary <ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:xamarin="http://uno.ui/xamarin"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Controls="using:CalculatorApp.Controls" xmlns:Controls="using:CalculatorApp.Controls"
xmlns:common="using:CalculatorApp.Common" xmlns:common="using:CalculatorApp.Common"
xmlns:converters="using:CalculatorApp.Converters" xmlns:converters="using:CalculatorApp.Converters"
xmlns:local="using:CalculatorApp"> xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="using:CalculatorApp"
mc:Ignorable="xamarin">
<ResourceDictionary.MergedDictionaries> <ResourceDictionary.MergedDictionaries>
<!-- <!--
@ -254,7 +257,8 @@
<x:Double x:Key="AppMinWindowHeight">500</x:Double> <x:Double x:Key="AppMinWindowHeight">500</x:Double>
<x:Double x:Key="AppMinWindowWidth">320</x:Double> <x:Double x:Key="AppMinWindowWidth">320</x:Double>
<FontFamily x:Key="CalculatorFontFamily">ms-appx:///Assets/CalcMDL2.ttf#Calculator MDL2 Assets</FontFamily> <win:FontFamily x:Key="CalculatorFontFamily">ms-appx:///Assets/CalcMDL2.ttf#Calculator MDL2 Assets</win:FontFamily>
<xamarin:FontFamily x:Key="CalculatorFontFamily">Calculator MDL2 Assets</xamarin:FontFamily>
<x:Double x:Key="SplitViewOpenPaneLength">256</x:Double> <x:Double x:Key="SplitViewOpenPaneLength">256</x:Double>
<Thickness x:Key="PivotPortraitThemePadding">0,1,0,0</Thickness> <Thickness x:Key="PivotPortraitThemePadding">0,1,0,0</Thickness>

View file

@ -110,12 +110,15 @@ namespace CalculatorApp.ViewModel
try try
{ {
Console.WriteLine($"ApplicationViewModel.Mode1={mode}");
Mode = mode; Mode = mode;
} Console.WriteLine($"ApplicationViewModel.Mode2={Mode}");
catch (Exception e) }
catch (Exception e)
{ {
// TraceLogger.GetInstance().LogPlatformException(__FUNCTIONW__, e); Console.WriteLine($"ApplicationViewModel.Mode3={e}");
if (!TryRecoverFromNavigationModeFailure()) // TraceLogger.GetInstance().LogPlatformException(__FUNCTIONW__, e);
if (!TryRecoverFromNavigationModeFailure())
{ {
// Could not navigate to standard mode either. // Could not navigate to standard mode either.
// Throw the original exception so we have a good stack to debug. // Throw the original exception so we have a good stack to debug.
@ -152,6 +155,7 @@ namespace CalculatorApp.ViewModel
m_CalculatorViewModel = new StandardCalculatorViewModel(); m_CalculatorViewModel = new StandardCalculatorViewModel();
} }
m_CalculatorViewModel.SetCalculatorType(m_mode); m_CalculatorViewModel.SetCalculatorType(m_mode);
Console.WriteLine($"m_CalculatorViewMode = {m_CalculatorViewModel}");
} }
else if (NavCategory.IsDateCalculatorViewMode(m_mode)) else if (NavCategory.IsDateCalculatorViewMode(m_mode))
{ {

View file

@ -510,6 +510,8 @@ namespace CalculatorApp.ViewModel
public StandardCalculatorViewModel() public StandardCalculatorViewModel()
{ {
Console.WriteLine("new StandardCalculatorViewModel()");
m_DisplayValue = "0"; m_DisplayValue = "0";
m_DecimalDisplayValue = "0"; m_DecimalDisplayValue = "0";
m_HexDisplayValue = "0"; m_HexDisplayValue = "0";
@ -571,11 +573,13 @@ namespace CalculatorApp.ViewModel
m_decimalSeparator = LocalizationSettings.GetInstance().GetDecimalSeparator(); m_decimalSeparator = LocalizationSettings.GetInstance().GetDecimalSeparator();
if (CoreWindow.GetForCurrentThread() != null) #if !__WASM__
if (CoreWindow.GetForCurrentThread() != null)
{ {
// Must have a CoreWindow to access the resource context. // Must have a CoreWindow to access the resource context.
m_isRtlLanguage = LocalizationService.GetInstance().IsRtlLayout(); m_isRtlLanguage = LocalizationService.GetInstance().IsRtlLayout();
} }
#endif
IsEditingEnabled = false; IsEditingEnabled = false;
IsUnaryOperatorEnabled = true; IsUnaryOperatorEnabled = true;

View file

@ -75,7 +75,11 @@ namespace CalculatorApp
protected override void OnNavigatedTo(NavigationEventArgs e) protected override void OnNavigatedTo(NavigationEventArgs e)
{ {
if (m_model.CalculatorViewModel != null) initialized = true;
NavView.DataContext = m_model;
if (m_model.CalculatorViewModel != null)
{ {
m_model.CalculatorViewModel.HistoryVM.ClearHistory(); m_model.CalculatorViewModel.HistoryVM.ClearHistory();
} }
@ -101,8 +105,14 @@ namespace CalculatorApp
} }
} }
m_model.Initialize(initialMode); m_model.Initialize(initialMode);
}
EnsureCalculator();
m_calculator.DataContext = m_model.CalculatorViewModel;
Initialize();
}
void WindowSizeChanged(object sender, Windows.UI.Core.WindowSizeChangedEventArgs e) void WindowSizeChanged(object sender, Windows.UI.Core.WindowSizeChangedEventArgs e)
{ {
@ -229,34 +239,46 @@ namespace CalculatorApp
} }
void OnPageLoaded(object sender, RoutedEventArgs args) void OnPageLoaded(object sender, RoutedEventArgs args)
{ {
if (m_converter == null && m_calculator == null && m_dateCalculator == null) Initialize();
{ }
// We have just launched into our default mode (standard calc) so ensure calc is loaded
EnsureCalculator();
m_model.CalculatorViewModel.IsStandard = true;
}
Windows.UI.Xaml.Window.Current.SizeChanged += WindowSizeChanged; bool initialized = false;
UpdateViewState(); private void Initialize()
{
// UNO TODO Check for Initialized (Load/OnNavigatedTo order is different)
if (initialized)
{
if (m_converter == null && m_calculator == null && m_dateCalculator == null)
{
// We have just launched into our default mode (standard calc) so ensure calc is loaded
EnsureCalculator();
m_model.CalculatorViewModel.IsStandard = true;
}
SetHeaderAutomationName();
SetDefaultFocus();
// Delay load things later when we get a chance. Windows.UI.Xaml.Window.Current.SizeChanged += WindowSizeChanged;
this.Dispatcher.RunAsync( UpdateViewState();
CoreDispatcherPriority.Normal, () => {
// UNO TODO
//if (TraceLogger.GetInstance().UpdateWindowIdLog(ApplicationView.GetApplicationViewIdForWindow(CoreWindow.GetForCurrentThread())))
//{
// TraceLogger.GetInstance().LogAppLaunchComplete();
// AppLifecycleLogger.GetInstance().LaunchUIResponsive();
// AppLifecycleLogger.GetInstance().LaunchVisibleComplete();
//}
});
}
void SetDefaultFocus() SetHeaderAutomationName();
SetDefaultFocus();
// Delay load things later when we get a chance.
this.Dispatcher.RunAsync(
CoreDispatcherPriority.Normal, () =>
{
// UNO TODO
//if (TraceLogger.GetInstance().UpdateWindowIdLog(ApplicationView.GetApplicationViewIdForWindow(CoreWindow.GetForCurrentThread())))
//{
// TraceLogger.GetInstance().LogAppLaunchComplete();
// AppLifecycleLogger.GetInstance().LaunchUIResponsive();
// AppLifecycleLogger.GetInstance().LaunchVisibleComplete();
//}
});
}
}
void SetDefaultFocus()
{ {
if (m_calculator != null && m_calculator.Visibility == Visibility.Visible) if (m_calculator != null && m_calculator.Visibility == Visibility.Visible)
{ {
@ -281,7 +303,7 @@ namespace CalculatorApp
// delay load calculator. // delay load calculator.
m_calculator = new Calculator(); m_calculator = new Calculator();
m_calculator.Name = "Calculator"; m_calculator.Name = "Calculator";
m_calculator.DataContext = m_model.CalculatorViewModel; m_calculator.DataContext = m_model.CalculatorViewModel;
Binding isStandardBinding = new Binding(); Binding isStandardBinding = new Binding();
isStandardBinding.Path = new PropertyPath("IsStandard"); isStandardBinding.Path = new PropertyPath("IsStandard");
m_calculator.SetBinding(CalculatorApp.Calculator.IsStandardProperty, isStandardBinding); m_calculator.SetBinding(CalculatorApp.Calculator.IsStandardProperty, isStandardBinding);
@ -305,7 +327,7 @@ namespace CalculatorApp
ShowHideControls(this.Model.Mode); ShowHideControls(this.Model.Mode);
} }
if (m_dateCalculator != null) if (m_dateCalculator != null)
{ {
// UNO TODO // UNO TODO
// m_dateCalculator.CloseCalendarFlyout(); // m_dateCalculator.CloseCalendarFlyout();

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
@ -6,15 +6,18 @@
<WasmHead>true</WasmHead> <WasmHead>true</WasmHead>
<DefineConstants>$(DefineConstants);__WASM__</DefineConstants> <DefineConstants>$(DefineConstants);__WASM__</DefineConstants>
<NoWarn>NU1701</NoWarn> <NoWarn>NU1701</NoWarn>
<WasmShellGenerateCompressedFiles Condition="'$(Configuration)'=='DEBUG'">false</WasmShellGenerateCompressedFiles> <WasmShellGenerateCompressedFiles Condition="'$(Configuration)'=='Debug'">false</WasmShellGenerateCompressedFiles>
<!--<BuildingInsideUnoSourceGenerator>true</BuildingInsideUnoSourceGenerator>--> <!--<BuildingInsideUnoSourceGenerator>true</BuildingInsideUnoSourceGenerator>-->
</PropertyGroup> <MonoRuntimeDebuggerEnabled Condition="'$(Configuration)'=='Debug'">true</MonoRuntimeDebuggerEnabled>
<MonoWasmRuntimeConfiguration>release-dynamic</MonoWasmRuntimeConfiguration>
<MonoWasmSDKUri>C:\Users\jerome.laban\Downloads\mono-wasm-4d023b6bf84.zip</MonoWasmSDKUri>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<Content Include="..\Calculator.UWP\Assets\*.png" Link="Assets\%(FileName)%(Extension)" /> <Content Include="..\Calculator.UWP\Assets\*.png" Link="Assets\%(FileName)%(Extension)" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="WasmCSS\Fonts.css" /> <EmbeddedResource Include="WasmCSS\Fonts.css" />
<EmbeddedResource Include="WasmScripts\AppManifest.js" /> <EmbeddedResource Include="WasmScripts\*.js" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<LinkerDescriptor Include="LinkerConfig.xml" /> <LinkerDescriptor Include="LinkerConfig.xml" />
@ -27,6 +30,7 @@
You can safely remove this ItemGroup completely. You can safely remove this ItemGroup completely.
--> -->
<Compile Remove="Program.cs" /> <Compile Remove="Program.cs" />
<None Remove="WasmScripts\CalcManager.js" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Content Include="LinkerConfig.xml" /> <Content Include="LinkerConfig.xml" />
</ItemGroup> </ItemGroup>
@ -37,5 +41,8 @@
<PackageReference Include="Uno.Wasm.Bootstrap" Version="1.0.0-dev.269" /> <PackageReference Include="Uno.Wasm.Bootstrap" Version="1.0.0-dev.269" />
<DotNetCliToolReference Include="Uno.Wasm.Bootstrap.Cli" Version="1.0.0-dev.269" /> <DotNetCliToolReference Include="Uno.Wasm.Bootstrap.Cli" Version="1.0.0-dev.269" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Content Include="..\CalcManager\CalcManager.wasm" Link="CalcManager.wasm" />
</ItemGroup>
<Import Project="..\Calculator.Shared\Calculator.Shared.projitems" Label="Shared" Condition="Exists('..\Calculator.Shared\Calculator.Shared.projitems')" /> <Import Project="..\Calculator.Shared\Calculator.Shared.projitems" Label="Shared" Condition="Exists('..\Calculator.Shared\Calculator.Shared.projitems')" />
</Project> </Project>

View file

@ -11,8 +11,10 @@ namespace WindowsCalculator.Wasm
private static App _app; private static App _app;
static void Main(string[] args) static void Main(string[] args)
{ {
ConfigureFilters(LogExtensionPoint.AmbientLoggerFactory); Console.WriteLine("Program.Main");
ConfigureFilters(LogExtensionPoint.AmbientLoggerFactory);
Windows.UI.Xaml.Application.Start(_ => _app = new App()); Windows.UI.Xaml.Application.Start(_ => _app = new App());
} }

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,44 @@
class CalcManager {
static registerCallbacks() {
var _getCEngineStringCallback = Module.mono_bind_static_method("[Calculator.Wasm] CalculationManager.NativeDispatch:GetCEngineStringCallback");
var _binaryOperatorReceivedCallback = Module.mono_bind_static_method("[Calculator.Wasm] CalculationManager.NativeDispatch:BinaryOperatorReceivedCallback");
var _setPrimaryDisplayCallback = Module.mono_bind_static_method("[Calculator.Wasm] CalculationManager.NativeDispatch:SetPrimaryDisplayCallback");
var _setIsInErrorCallback = Module.mono_bind_static_method("[Calculator.Wasm] CalculationManager.NativeDispatch:SetIsInErrorCallback");
var _setParenthesisNumberCallback = Module.mono_bind_static_method("[Calculator.Wasm] CalculationManager.NativeDispatch:SetParenthesisNumberCallback");
var _maxDigitsReachedCallback = Module.mono_bind_static_method("[Calculator.Wasm] CalculationManager.NativeDispatch:MaxDigitsReachedCallback");
var _memoryItemChangedCallback = Module.mono_bind_static_method("[Calculator.Wasm] CalculationManager.NativeDispatch:MemoryItemChangedCallback");
var _onHistoryItemAddedCallback = Module.mono_bind_static_method("[Calculator.Wasm] CalculationManager.NativeDispatch:OnHistoryItemAddedCallback");
var _onNoRightParenAddedCallback = Module.mono_bind_static_method("[Calculator.Wasm] CalculationManager.NativeDispatch:OnNoRightParenAddedCallback");
var _setExpressionDisplayCallback = Module.mono_bind_static_method("[Calculator.Wasm] CalculationManager.NativeDispatch:SetExpressionDisplayCallback");
var _setMemorizedNumbersCallback = Module.mono_bind_static_method("[Calculator.Wasm] CalculationManager.NativeDispatch:SetMemorizedNumbersCallback");
var fGetCEngineStringCallback = Module.addFunction((state, id) => _getCEngineStringCallback(state, Module.UTF8ToString(id)), 'iii');
var fBinaryOperatorReceivedCallback = Module.addFunction((state) => _binaryOperatorReceivedCallback(state), 'vi');
var fSetPrimaryDisplayCallback = Module.addFunction((state, displayStringValue, isError) => _setPrimaryDisplayCallback(state, Module.UTF8ToString(displayStringValue), isError), 'viii');
var fSetIsInErrorCallback = Module.addFunction((state, isError) => _setIsInErrorCallback(state, isError), 'vii');
var fSetParenthesisNumberCallback = Module.addFunction((state, parenthesisCount) => _setParenthesisNumberCallback(state, parenthesisCount), 'vii');
var fMaxDigitsReachedCallback = Module.addFunction((state) => _maxDigitsReachedCallback(state), 'vii');
var fMemoryItemChangedCallback = Module.addFunction((state, indexOfMemory) => _memoryItemChangedCallback(state, indexOfMemory), 'vii');
var fOnHistoryItemAddedCallback = Module.addFunction((state, addedItemIndex) => _onHistoryItemAddedCallback(state, addedItemIndex), 'vii');
var fOnNoRightParenAddedCallback = Module.addFunction((state) => _onNoRightParenAddedCallback (state), 'vi');
var fSetExpressionDisplayCallback = Module.addFunction((state) => _setExpressionDisplayCallback (state), 'vi');
var fSetMemorizedNumbersCallback = Module.addFunction((state, numbers) => _setMemorizedNumbersCallback(state, numbers), 'vii');
var ret = `${fGetCEngineStringCallback};`
+ `${fBinaryOperatorReceivedCallback};`
+ `${fSetPrimaryDisplayCallback};`
+ `${fSetIsInErrorCallback};`
+ `${fSetParenthesisNumberCallback};`
+ `${fMaxDigitsReachedCallback};`
+ `${fMemoryItemChangedCallback};`
+ `${fOnHistoryItemAddedCallback};`
+ `${fOnNoRightParenAddedCallback};`
+ `${fSetExpressionDisplayCallback};`
+ `${fSetMemorizedNumbersCallback};`
;
return ret;
}
}