Skip to content

Commit 8b60f4b

Browse files
authored
Refactor first run notice to show on any firtst execution, not just without args. (#232)
Fixes #229.
1 parent 56fccf8 commit 8b60f4b

3 files changed

Lines changed: 15 additions & 4 deletions

File tree

src/winapp-CLI/WinApp.Cli/Program.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,18 @@ static async Task<int> Main(string[] args)
6262
using var serviceProvider = services.BuildServiceProvider();
6363

6464
var firstRunService = serviceProvider.GetRequiredService<IFirstRunService>();
65-
firstRunService.CheckAndDisplayFirstRunNotice();
65+
var didShowFirstRunNotice = firstRunService.CheckAndDisplayFirstRunNotice();
6666

6767
var rootCommand = serviceProvider.GetRequiredService<WinAppRootCommand>();
6868

6969
// If no arguments provided, display banner and show help
7070
if (args.Length == 0)
7171
{
72-
BannerHelper.DisplayBanner();
72+
if (!didShowFirstRunNotice)
73+
{
74+
BannerHelper.DisplayBanner();
75+
}
76+
7377
// Show help by invoking with --help
7478
await rootCommand.Parse(["--help"]).InvokeAsync();
7579
return 0;

src/winapp-CLI/WinApp.Cli/Services/FirstRunService.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33

44
using Microsoft.Extensions.Logging;
5+
using WinApp.Cli.Helpers;
56

67
namespace WinApp.Cli.Services;
78

@@ -18,11 +19,13 @@ public FirstRunService(IWinappDirectoryService directoryService, ILogger<FirstRu
1819
_logger = logger;
1920
}
2021

21-
public void CheckAndDisplayFirstRunNotice()
22+
public bool CheckAndDisplayFirstRunNotice()
2223
{
2324
_firstRunMarkerFile.Refresh();
2425
if (!_firstRunMarkerFile.Exists)
2526
{
27+
BannerHelper.DisplayBanner();
28+
2629
_logger.LogInformation("Welcome to the Windows App Development CLI! By using this tool, you agree to the collection of anonymous usage data to help improve the product. You can read the full privacy policy at https://go.microsoft.com/fwlink/?LinkId=521839");
2730
_logger.LogInformation("You can opt out of telemetry by setting the WINAPP_CLI_TELEMETRY_OPTOUT environment variable to '1'.");
2831
_logger.LogInformation("For more information, please visit: https://aka.ms/winappcli-telemetry-optout{NewLine}", Environment.NewLine);
@@ -37,6 +40,10 @@ public void CheckAndDisplayFirstRunNotice()
3740
{
3841
_logger.LogWarning("Failed to create first run marker file: {ErrorMessage}", ex.Message);
3942
}
43+
44+
return true;
4045
}
46+
47+
return false;
4148
}
4249
}

src/winapp-CLI/WinApp.Cli/Services/IFirstRunService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ namespace WinApp.Cli.Services;
55

66
internal interface IFirstRunService
77
{
8-
public void CheckAndDisplayFirstRunNotice();
8+
public bool CheckAndDisplayFirstRunNotice();
99
}

0 commit comments

Comments
 (0)