-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from DreamEnderKing/dev
依赖关系注入优化。
- Loading branch information
Showing
16 changed files
with
199 additions
and
88 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 |
---|---|---|
@@ -1,31 +1,69 @@ | ||
using Microsoft.Extensions.Logging; | ||
using System.Reflection; | ||
using CommunityToolkit.Maui; | ||
using CommunityToolkit.Maui.Core; | ||
using CommunityToolkit.Maui.Storage; | ||
using installer.ViewModel; | ||
using System.Runtime.CompilerServices; | ||
using installer.Model; | ||
|
||
namespace installer | ||
{ | ||
public static class MauiProgram | ||
{ | ||
public static Model.Downloader Downloader = new Model.Downloader(); | ||
// public static Model.Logger logger = Model.LoggerProvider.FromFile(@"E:\bin\log\123.log"); | ||
public static bool ErrorTrigger_WhileDebug = true; | ||
public static bool RefreshLogs_WhileDebug = false; | ||
public static string SecretID = "***"; | ||
public static string SecretKey = "***"; | ||
public static MauiApp CreateMauiApp() | ||
{ | ||
var builder = MauiApp.CreateBuilder(); | ||
builder | ||
.UseMauiApp<App>() | ||
.UseMauiCommunityToolkitCore() | ||
.UseMauiCommunityToolkit() | ||
.ConfigureFonts(fonts => | ||
{ | ||
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); | ||
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); | ||
}); | ||
|
||
// 此处填写Secret ID和Secret Key | ||
Downloader.Cloud.UpdateSecret("***", "***"); | ||
var c = builder.Services.AddSingleton<Downloader>().First(); | ||
|
||
builder.Services.AddSingleton(FolderPicker.Default); | ||
|
||
|
||
AddViewModelService(builder); | ||
AddPageService(builder); | ||
#if DEBUG | ||
builder.Logging.AddDebug(); | ||
#endif | ||
|
||
return builder.Build(); | ||
} | ||
|
||
public static void AddViewModelService(MauiAppBuilder builder) | ||
{ | ||
var a = typeof(MauiProgram).Assembly; | ||
foreach (var t in a.GetTypes()) | ||
{ | ||
if ((t.FullName ?? string.Empty).StartsWith($"{a.GetName().Name}.ViewModel") && !t.IsAbstract) | ||
{ | ||
builder.Services.AddSingleton(t); | ||
} | ||
} | ||
} | ||
public static void AddPageService(MauiAppBuilder builder) | ||
{ | ||
var a = typeof(MauiProgram).Assembly; | ||
foreach (var t in a.GetTypes()) | ||
{ | ||
if ((t.FullName ?? string.Empty).StartsWith($"{a.GetName().Name}.Page") && !t.IsAbstract) | ||
{ | ||
builder.Services.AddSingleton(t); | ||
} | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,9 +1,13 @@ | ||
using CommunityToolkit.Maui.Storage; | ||
using installer.ViewModel; | ||
|
||
namespace installer.Page; | ||
|
||
public partial class InstallPage : ContentPage | ||
{ | ||
public InstallPage() | ||
public InstallPage(InstallViewModel viewModel) | ||
{ | ||
InitializeComponent(); | ||
BindingContext = viewModel; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,9 +1,12 @@ | ||
using installer.ViewModel; | ||
|
||
namespace installer.Page; | ||
|
||
public partial class LaunchPage : ContentPage | ||
{ | ||
public LaunchPage() | ||
public LaunchPage(LaunchViewModel viewModel) | ||
{ | ||
InitializeComponent(); | ||
BindingContext = viewModel; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,9 +1,12 @@ | ||
using installer.ViewModel; | ||
|
||
namespace installer.Page; | ||
|
||
public partial class LoginPage : ContentPage | ||
{ | ||
public LoginPage() | ||
public LoginPage(LoginViewModel viewModel) | ||
{ | ||
InitializeComponent(); | ||
BindingContext = viewModel; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application> | ||
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:supportsRtl="true"></application> | ||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
<uses-permission android:name="android.permission.INTERNET" /> | ||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> | ||
<uses-sdk /> | ||
</manifest> |
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.