From 9a4876ffd5f247b4c57506a99ebdeebee26363f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Seyyid=20Yi=C4=9Fit?= Date: Tue, 27 Feb 2024 11:20:41 +0300 Subject: [PATCH] Added Aptabase key area in appsettings.json, configure analytics and youtuberchannel parameter added main page load event. --- .github/workflows/ci-build.yml | 2 ++ src/MauiProgram.cs | 30 +++++++++++++++++++++++++----- src/Models/AppSettings.cs | 1 + src/Pages/MainPage.xaml.cs | 3 ++- src/appsettings.json | 5 +++-- 5 files changed, 33 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index 769358f..21d5220 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -18,6 +18,7 @@ env: DOTNET_NOLOGO: true # Disable the .NET logo DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true # Disable the .NET first time experience DOTNET_CLI_TELEMETRY_OPTOUT: true # Disable sending .NET CLI telemetry + APTABASE_KEY: ${{ secrets.APTABASE_KEY }} # Aptabase Key jobs: # MAUI Windows Build @@ -39,6 +40,7 @@ jobs: $jsonContent = Get-Content -Path $pathToJson -Raw | ConvertFrom-Json $jsonContent.Settings.SponsorGameAppId = "${{ vars.GAME_ID }}" $jsonContent.Settings.YoutuberChanneName = "${{ vars.YOUTUBE_CHANNEL }}" + $jsonContent.Settings.AptabaseKey = "$env:APTABASE_KEY" $jsonContent | ConvertTo-Json -Depth 100 | Set-Content -Path $pathToJson $jsonContent shell: pwsh diff --git a/src/MauiProgram.cs b/src/MauiProgram.cs index 5992e31..8525763 100644 --- a/src/MauiProgram.cs +++ b/src/MauiProgram.cs @@ -21,7 +21,6 @@ public static MauiApp CreateMauiApp() var builder = MauiApp.CreateBuilder(); builder .UseMauiApp() - // .UseAptabase("YOUR-CODE") // 👈 this is where you enter your App Key .UseMauiCommunityToolkit() .ConfigureSyncfusionCore() .UseLocalizationResourceManager(settings => @@ -31,6 +30,9 @@ public static MauiApp CreateMauiApp() }) .ConfigureFonts(ConfigureFonts); + builder.Logging.SetMinimumLevel(LogLevel.Debug); + + Microsoft.Maui.Handlers.WindowHandler.Mapper.AppendToMapping(nameof(IWindow), (handler, view) => { @@ -61,12 +63,12 @@ public static MauiApp CreateMauiApp() builder.Logging.AddDebug(); #endif builder.Services.ConfigureServices(); - // builder.Services.RegisterAnalyticsObservers(); // 👈 this is where we register the observers builder.RegisterViews(); builder.RegisterConfiguration(); + builder.CheckAndAddAnalyticsBeforeBuild(); var app = builder.Build(); - // app.Services.ConfigureAnalyticsSubject(); // 👈 this is where we configure the subject + app.CheckAndAddAnalyticsAfterBuild(); return app; } @@ -86,8 +88,6 @@ public static MauiAppBuilder RegisterViews(this MauiAppBuilder builder) } private static void ConfigureServices(this IServiceCollection services) { - services.Configure(x => x.ProjectOperationPath = Path.Combine(Path.GetTempPath(), "HuaweiHMSInstaller")); //configure value - services.Configure(x => x.VersionNumber = "0.0.1"); //configure value services.AddHttpClient(); services.AddScoped(); services.AddScoped(); @@ -151,4 +151,24 @@ private static void RegisterConfiguration(this MauiAppBuilder appBuilder) throw new FileNotFoundException($"Resource {resourceName} not found."); } } + private static void CheckAndAddAnalyticsBeforeBuild(this MauiAppBuilder appBuilder) + { + var settings = appBuilder.Configuration.GetSection("Settings").Get(); + if (string.IsNullOrWhiteSpace(settings?.AptabaseKey) == false) + { + appBuilder.UseAptabase(settings.AptabaseKey); + appBuilder.Services.RegisterAnalyticsObservers(); // 👈 this is where we register the observers + appBuilder.Services.RegisterAnalyticsObservers(); // 👈 this is where we register the observers + + } + + } + private static void CheckAndAddAnalyticsAfterBuild(this MauiApp app) + { + var settings = app.Configuration.GetSection("Settings").Get(); + if (string.IsNullOrWhiteSpace(settings?.AptabaseKey) == false) + { + app.Services.ConfigureAnalyticsSubject(); // 👈 this is where we configure the subject + } + } } \ No newline at end of file diff --git a/src/Models/AppSettings.cs b/src/Models/AppSettings.cs index 8c03dee..84b9d9c 100644 --- a/src/Models/AppSettings.cs +++ b/src/Models/AppSettings.cs @@ -12,5 +12,6 @@ public class AppSettings public string VersionNumber { get; set; } public string SponsorGameAppId { get; set; } = "C106234721"; //C104193349 public string YoutuberChanneName { get; set; } + public string AptabaseKey { get; set; } } } diff --git a/src/Pages/MainPage.xaml.cs b/src/Pages/MainPage.xaml.cs index cb1d36d..5653e97 100644 --- a/src/Pages/MainPage.xaml.cs +++ b/src/Pages/MainPage.xaml.cs @@ -166,7 +166,8 @@ await _analyticsSubject.NotifyAsync("Main Page Loaded", new Dictionary { { "SelectedGame", selectedGame.Name }, - { "SelectedGameId", selectedGame.AppId } + { "SelectedGameId", selectedGame.AppId }, + { "YoutuberChannel", _settings.YoutuberChanneName } } ); diff --git a/src/appsettings.json b/src/appsettings.json index c270953..236fabf 100644 --- a/src/appsettings.json +++ b/src/appsettings.json @@ -1,7 +1,8 @@ { "Settings": { - "VersionNumber": "0.0.0.1", + "VersionNumber": "0.0.1", "SponsorGameAppId": "C106234721", - "YoutuberChanneName": "Huawei" + "YoutuberChanneName": "Huawei", + "AptabaseKey": "" } } \ No newline at end of file