-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve Hot Reload Integration (#851)
- Loading branch information
1 parent
e289c34
commit 0edc29e
Showing
17 changed files
with
188 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#nullable enable | ||
|
||
namespace Microsoft.Maui.Hosting | ||
{ | ||
public static class AppHost | ||
{ | ||
public static IAppHostBuilder CreateDefaultBuilder() | ||
{ | ||
var builder = new AppHostBuilder(); | ||
|
||
builder.UseMauiServiceProviderFactory(false); | ||
|
||
builder.UseMauiHandlers(); | ||
builder.ConfigureFonts(); | ||
|
||
return builder; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#nullable enable | ||
|
||
namespace Microsoft.Maui.Hosting.Internal | ||
{ | ||
class MauiHandlersCollection : MauiServiceCollection, IMauiHandlersCollection | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#nullable enable | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Maui.HotReload; | ||
|
||
namespace Microsoft.Maui.Hosting | ||
{ | ||
public static partial class AppHostBuilderExtensions | ||
{ | ||
public static IAppHostBuilder EnableHotReload(this IAppHostBuilder builder, string? ideIp = null, int idePort = 9988) | ||
{ | ||
builder.ConfigureServices<HotReloadBuilder>(hotReload => | ||
{ | ||
hotReload.IdeIp = ideIp; | ||
hotReload.IdePort = idePort; | ||
}); | ||
return builder; | ||
} | ||
|
||
class HotReloadBuilder : IMauiServiceBuilder | ||
{ | ||
public string? IdeIp { get; set; } | ||
|
||
public int IdePort { get; set; } = 9988; | ||
|
||
public void ConfigureServices(HostBuilderContext context, IServiceCollection services) | ||
{ | ||
} | ||
|
||
public async void Configure(HostBuilderContext context, IServiceProvider services) | ||
{ | ||
var handlers = services.GetRequiredService<IMauiHandlersServiceProvider>(); | ||
if (handlers is IHotReloadableHandlersServiceProvider hotReloadable) | ||
MauiHotReloadHelper.Init(hotReloadable.GetCollection()); | ||
else | ||
throw new NotSupportedException($"Hot Reload only works with a {nameof(IHotReloadableHandlersServiceProvider)}."); | ||
|
||
Reloadify.Reload.Instance.ReplaceType = (d) => | ||
{ | ||
MauiHotReloadHelper.RegisterReplacedView(d.ClassName, d.Type); | ||
}; | ||
|
||
Reloadify.Reload.Instance.FinishedReload = () => | ||
{ | ||
MauiHotReloadHelper.TriggerReload(); | ||
}; | ||
|
||
await Task.Run(async () => | ||
{ | ||
try | ||
{ | ||
var success = await Reloadify.Reload.Init(IdeIp, IdePort); | ||
Console.WriteLine($"HotReload Initialize: {success}"); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine(ex); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/Core/src/HotReload/IHotReloadableHandlersServiceProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#nullable enable | ||
using Microsoft.Maui.Hosting; | ||
|
||
namespace Microsoft.Maui.HotReload | ||
{ | ||
public interface IHotReloadableHandlersServiceProvider : IMauiHandlersServiceProvider | ||
{ | ||
IMauiHandlersCollection GetCollection(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.