Skip to content

Commit

Permalink
Migrate to WinUI 3 (#38)
Browse files Browse the repository at this point in the history
* WinUI - part 1

* More namespace changes

* NEEDS BETTER FIX IF POSSIBLE

* Name changes

* temp

* Fixed file names

* remove Windows Mobile SDK Reference

* Fix more errors

* make it virtual

* Get rid of OnActivated

* Update deps

---------

Co-authored-by: Reza Talebi <[email protected]>
  • Loading branch information
RezaT4795 and Reza Talebi authored Sep 22, 2024
1 parent ec0db6c commit 2d5fbc0
Show file tree
Hide file tree
Showing 59 changed files with 263 additions and 314 deletions.
4 changes: 2 additions & 2 deletions Core/Device/Screen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public static void ConfigureSize(Func<float> widthProvider, Func<float> heightPr
WidthProvider = widthProvider;
HeightProvider = heightProvider;

#if UWP
#if WINUI
if (UIRuntime.IsDevMode && UIRuntime.Inspector.IsRotating)
{
Width = widthProvider();
Expand All @@ -172,7 +172,7 @@ internal static void UpdateLayout()
Width = newWidth;
Height = newHeight;

#if UWP
#if WINUI
var extra = UIRuntime.IsDevMode ? UIRuntime.Inspector.CurrentWidth : 0;
UIRuntime.RenderRoot.Size(Width + extra, Height);
#endif
Expand Down
4 changes: 2 additions & 2 deletions Core/Native/NativeRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace Zebble
using Android.Runtime;
using BaseNativeType = Android.Views.View;
[Preserve]
#elif UWP
using BaseNativeType = Windows.UI.Xaml.FrameworkElement;
#elif WINUI
using BaseNativeType = Microsoft.UI.Xaml.FrameworkElement;
#else
using BaseNativeType = object;
#endif
Expand Down
4 changes: 2 additions & 2 deletions Core/Native/Renderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace Zebble
using BaseNativeType = UIKit.UIView;
#elif ANDROID
using BaseNativeType = Android.Views.View;
#elif UWP
using BaseNativeType = Windows.UI.Xaml.FrameworkElement;
#elif WINUI
using BaseNativeType = Microsoft.UI.Xaml.FrameworkElement;
#elif MAUI_Windows
using BaseNativeType = object;
#endif
Expand Down
2 changes: 1 addition & 1 deletion Core/Services/Css/BatchUIChangeContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ internal void TrackCascade(Length length)
Log.For(this).Debug("");
}

#if UWP
#if WINUI
Device.App.ExitWithError("Detected cyclic dependency in layout settings. See the output log.");
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion Core/Services/Css/CssEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ static CssRule[] FindMatchedRules(View view)
static CssRule[] FindRules(View view)
{
var result = FindPossibleRules(view);
#if UWP
#if WINUI
if (UIRuntime.IsDevMode)
{
result = result.Where(x => x.Platform == null || x.Platform == Platform).ToList();
Expand Down
4 changes: 2 additions & 2 deletions Core/Services/Css/InheritanceDepth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ static void Reload()
{
var asses = AppDomain.CurrentDomain.GetAssemblies();
var assemblies = asses
#if UWP
// .NET Native (UWP) and other forms of Native AOT compilers don't support GetReferencedAssemblies
#if WINUI
// .NET Native (WinUI) and other forms of Native AOT compilers don't support GetReferencedAssemblies
.Where(c => c.GetName().Name.Contains("Zebble"))
#else
.Where(c => c.References(ZebbleAssembly) || c.GetName().Name.Contains("Zebble"))
Expand Down
2 changes: 1 addition & 1 deletion Core/Services/LayoutTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class LayoutTracker

public static void Track(ITrackable trackable, object value, [CallerMemberName] string caller = null)
{
#if UWP
#if WINUI
if (!UIRuntime.IsDevMode) return;
if (Tracking.None()) return;
if (Tracking.Lacks(GetTrackingRef(trackable))) return;
Expand Down
2 changes: 1 addition & 1 deletion Core/UI.Core/TextInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public SpellCheckingType SpellChecking
}

/// <summary>
/// Only needed for iOS. In Android and UWP this can achived by setting SpellChecking.
/// Only needed for iOS. In Android and WinUI this can achived by setting SpellChecking.
/// </summary>
public AutoCorrectionType AutoCorrection
{
Expand Down
4 changes: 2 additions & 2 deletions Core/UI.Core/View.Hierarchy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public Task RemoveAt(int childIndex, bool awaitNative = false)

public virtual async Task Remove(View view, bool awaitNative = false)
{
#if UWP
#if WINUI
if (UIRuntime.IsDevMode) UIRuntime.Inspector.DomUpdated(view).RunInParallel();
#endif

Expand Down Expand Up @@ -307,7 +307,7 @@ async Task DoAddToNativeParent()

UIWorkBatch.Publish(this, "[ADD]", null);

#if UWP
#if WINUI
if (UIRuntime.IsDevMode) await UIRuntime.Inspector.DomUpdated(this);
#endif
}
Expand Down
8 changes: 4 additions & 4 deletions Core/UI.Core/View.Positioning.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ public float NativeX

return Thread.UI.Run(() =>
{
#if UWP
return (float)Windows.UI.Xaml.Controls.Canvas.GetLeft((Windows.UI.Xaml.UIElement)native);
#if WINUI
return (float)Microsoft.UI.Xaml.Controls.Canvas.GetLeft((Microsoft.UI.Xaml.UIElement)native);
#elif IOS

var nativeLayer = (native as UIKit.UIView).Layer.PresentationLayer;
Expand All @@ -110,8 +110,8 @@ public float NativeY
var native = Native; if (native is null) return -1;
return Thread.UI.Run(() =>
{
#if UWP
return (float)Windows.UI.Xaml.Controls.Canvas.GetTop((Windows.UI.Xaml.UIElement)native);
#if WINUI
return (float)Microsoft.UI.Xaml.Controls.Canvas.GetTop((Microsoft.UI.Xaml.UIElement)native);
#elif IOS
var nativeLayer = (native as UIKit.UIView).Layer.PresentationLayer;
if (nativeLayer is null) return -1f;
Expand Down
4 changes: 2 additions & 2 deletions Core/UI.Core/ViewExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public static async Task<TView> MoveTo<TView>(this TView @this, View newParent,
return @this;
}

#if UWP
public static Windows.UI.Xaml.FrameworkElement Native(this View view) => (Windows.UI.Xaml.FrameworkElement)view.Native;
#if WINUI
public static Microsoft.UI.Xaml.FrameworkElement Native(this View view) => (Microsoft.UI.Xaml.FrameworkElement)view.Native;

#elif ANDROID
public static Android.Views.View Native(this View view) => (Android.Views.View)view.Native;
Expand Down
2 changes: 1 addition & 1 deletion Framework/Async/AsyncEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public Task RaiseOn(BaseThread thread)

var runner = thread.Run(() => Raise());

#if IOS || ANDROID || UWP
#if IOS || ANDROID || WINUI
if (Thread.UI.IsRunning() && thread == Thread.Pool)
return Task.CompletedTask;
#endif
Expand Down
2 changes: 1 addition & 1 deletion Framework/Common/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class AssemblyInfo
{
public static Assembly[] GetAssemblies()
{
#if UWP
#if WINUI
var assemblies = new List<Assembly>();
var files = Windows.ApplicationModel.Package.Current.InstalledLocation.GetFilesAsync().AsTask().AwaitResultWithoutContext();
if (files is null) return assemblies.ToArray();
Expand Down
2 changes: 1 addition & 1 deletion Framework/Common/ZebbleConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static IDictionary<string, string> LoadValues()
{
try
{
#if UWP || ANDROID || IOS
#if WINUI || ANDROID || IOS
var text = UIRuntime.GetEmbeddedResources()
.FirstOrDefault(x => x.Key.EndsWith("config.xml", StringComparison.OrdinalIgnoreCase))
.Value?.Invoke()?.ToString(Encoding.UTF8);
Expand Down
2 changes: 1 addition & 1 deletion Framework/Common/ZebbleLogging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
var message = formatter(state, exception);
if (message.IsEmpty()) return;

#if UWP || IOS
#if WINUI || IOS
System.Diagnostics.Debug.WriteLine(logLevel + ": " + Category + "> " + message);
#elif ANDROID
Android.Util.Log.Info("app", message);
Expand Down
6 changes: 3 additions & 3 deletions Framework/Device/IO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static string DocumentsFolder
{
get
{
#if UWP
#if WINUI
return Windows.Storage.KnownFolders.DocumentsLibrary.Path;
#else
return Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
Expand All @@ -34,7 +34,7 @@ public static string PersonalFolder
{
get
{
#if UWP
#if WINUI
return Windows.Storage.ApplicationData.Current.LocalFolder.Path;
#else
return Environment.GetFolderPath(Environment.SpecialFolder.Personal);
Expand Down Expand Up @@ -92,7 +92,7 @@ public static string AbsolutePath(string relative)
else
{
relative = NormalizePath(relative);
#if UWP
#if WINUI
relative = relative.Replace("/", "\\");
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion Framework/Services/System/SuspendGC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class SuspendGC : IDisposable
SuspendGC()
{
Original = GCSettings.LatencyMode;
#if UWP
#if WINUI
GCSettings.LatencyMode = GCLatencyMode.LowLatency;
#else
GCSettings.LatencyMode = GCLatencyMode.NoGCRegion;
Expand Down
2 changes: 1 addition & 1 deletion Framework/UIRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static void Initialize<TAnyAppType>(string appName, Action<IHostBuilder>
}
static IHostBuilder CreateHostBuilder<T>() where T : class
{
#if !UWP
#if !WINUI
return XamarinHost.CreateDefaultBuilder<T>();
#else
return Host.CreateDefaultBuilder();
Expand Down
2 changes: 1 addition & 1 deletion Mvvm/RenderAbstractions/Template.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal View GetOrCreate(ViewModel model)
if (View == null || View.IsDisposing)
{
View = (View)TemplateType.CreateInstance();
#if UWP || ANDROID || IOS
#if WINUI || ANDROID || IOS
View.SetViewModelValue(model);
View.RefreshBindings();
#endif
Expand Down
2 changes: 1 addition & 1 deletion SharedApp/ThreadPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public override Task<TResult> Run<TResult>(Func<Task<TResult>> task)
return task();
}

#if IOS || ANDROID || UWP
#if IOS || ANDROID || WINUI
public override bool IsRunning() => !Thread.UI.IsRunning();
#else
public override bool IsRunning() => true;
Expand Down
10 changes: 5 additions & 5 deletions Zebble.Build/Common/SolutionFixer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ void RenameSpecificPlatformsProjects(FileInfo solutionFile)
foreach (var token in new[] { "", $"{solutionFile.NameWithoutExtension()}\\" })
{
solutionText = solutionText.Replace(
oldValue: $"Project(\"{{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}}\") = \"UWP\", \"{token}Run\\UWP\\UWP.csproj\"",
newValue: $"Project(\"{{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}}\") = \"~UWP\", \"{token}Run\\UWP\\~UWP.csproj\""
oldValue: $"Project(\"{{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}}\") = \"WinUI\", \"{token}Run\\WinUI\\WinUI.csproj\"",
newValue: $"Project(\"{{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}}\") = \"~WinUI\", \"{token}Run\\WinUI\\~WinUI.csproj\""
);

solutionText = solutionText.Replace(
Expand Down Expand Up @@ -175,11 +175,11 @@ static void FixSolutionSettings(FileInfo solution)

var buildSettings = new List<string>();

var uwpGUID = "{51AEAFB7-E02B-4F51-8AB0-AA90E034E684}";
var winuiGUID = "{51AEAFB7-E02B-4F51-8AB0-AA90E034E684}";
foreach (var platform in new[] { "Any CPU", "iPhone", "iPhoneSimulator" })
{
buildSettings.Add($"{uwpGUID}.Debug|{platform}.Build.0 = Debug|x86");
buildSettings.Add($"{uwpGUID}.Debug|{platform}.Deploy.0 = Debug|x86");
buildSettings.Add($"{winuiGUID}.Debug|{platform}.Build.0 = Debug|x86");
buildSettings.Add($"{winuiGUID}.Debug|{platform}.Deploy.0 = Debug|x86");
}

var iosGUID = "{3B21A769-F17C-4219-A595-27A34955228F}";
Expand Down
2 changes: 1 addition & 1 deletion Zebble.Build/ConvertPlugin/PluginConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void MoveTo(string name)
MoveTo("Shared");
MoveTo("iOS");
MoveTo("Android");
MoveTo("UWP");
MoveTo("WinUI");
}

void RemoveOldFilesAndFolders()
Expand Down
2 changes: 1 addition & 1 deletion Zebble.Build/NavigationXml/NavXmlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class NavXmlGenerator : Builder

public NavXmlGenerator()
{
_navXmlFile = Path.Combine(DirectoryContext.UWPObjFolder.FullName, "zebble-nav.xml").AsFile();
_navXmlFile = Path.Combine(DirectoryContext.WinUIObjFolder.FullName, "zebble-nav.xml").AsFile();
Log($"Updated navigation info will be written into: {_navXmlFile.FullName}");
}

Expand Down
2 changes: 1 addition & 1 deletion Zebble.Build/Zebble.Build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Olive" Version="2.1.361" />
<PackageReference Include="Olive" Version="2.1.380" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\icon.png" Pack="true" PackagePath="" />
Expand Down
2 changes: 1 addition & 1 deletion Zebble.CompileZbl/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"Zebble.CompileZbl": {
"commandName": "Project",
"workingDirectory": "D:\\Geeks\\UWP\\fyioNew\\fyio.mobile"
"workingDirectory": "D:\\Geeks\\WinUI\\fyioNew\\fyio.mobile"
}
}
}
4 changes: 2 additions & 2 deletions Zebble.CompileZbl/Zebble.CompileZbl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Olive" Version="2.1.361" />
<PackageReference Include="SkiaSharp" Version="3.0.0-preview.2.1" />
<PackageReference Include="Olive" Version="2.1.380" />
<PackageReference Include="SkiaSharp" Version="3.0.0-preview.4.1" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\icon.png" Pack="true" PackagePath="" />
Expand Down
2 changes: 1 addition & 1 deletion Zebble.Css/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"Zebble.Css": {
"commandName": "Project",
"commandLineArgs": "generate",
"workingDirectory": "D:\\Geeks\\UWP\\fyioNew\\fyio.mobile"
"workingDirectory": "D:\\Geeks\\WinUI\\fyioNew\\fyio.mobile"
}
}
}
10 changes: 5 additions & 5 deletions Zebble.Css/Zebble.Css.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@
<None Include="Resources\icon.png" Pack="true" PackagePath="" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Olive" Version="2.1.361" />
<PackageReference Include="SkiaSharp" Version="3.0.0-preview.2.1" />
<PackageReference Include="Olive" Version="2.1.380" />
<PackageReference Include="SkiaSharp" Version="3.0.0-preview.4.1" />
<PackageReference Include="SourceMapToolkit" Version="1.1.4" />
<PackageReference Include="LibSassHost" Version="1.4.0" />
<PackageReference Include="LibSassHost.Native.osx-x64" Version="1.4.0" />
<PackageReference Include="LibSassHost.Native.win-x64" Version="1.4.0" />
<PackageReference Include="LibSassHost" Version="1.5.0" />
<PackageReference Include="LibSassHost.Native.osx-x64" Version="1.5.0" />
<PackageReference Include="LibSassHost.Native.win-x64" Version="1.5.0" />
</ItemGroup>
<Import Project="..\Zebble.Tooling\Zebble.Tooling.projitems" Label="Shared" />
<Import Project="..\Css\Css.projitems" Label="Shared" />
Expand Down
4 changes: 2 additions & 2 deletions Zebble.FormatZbl/Zebble.FormatZbl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
<None Remove="README.md" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Olive" Version="2.1.361" />
<PackageReference Include="SkiaSharp" Version="3.0.0-preview.2.1" />
<PackageReference Include="Olive" Version="2.1.380" />
<PackageReference Include="SkiaSharp" Version="3.0.0-preview.4.1" />
</ItemGroup>
<Import Project="..\Zebble.Tooling\Zebble.Tooling.projitems" Label="Shared" />
<Import Project="..\Abstractions\Abstractions.projitems" Label="Shared" />
Expand Down
Loading

0 comments on commit 2d5fbc0

Please sign in to comment.