Skip to content

Commit

Permalink
fix vnext app not starting
Browse files Browse the repository at this point in the history
  • Loading branch information
tareqimbasher committed Jan 30, 2025
1 parent ef58ff4 commit 7ecce86
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 19 deletions.
11 changes: 4 additions & 7 deletions .github/workflows/pack-tauri.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ on:

jobs:
create-release:
defaults:
run:
working-directory: ./src/Apps/NetPad.Apps.Shells.Tauri/TauriApp/src-tauri
permissions:
contents: write
runs-on: ubuntu-latest
Expand All @@ -33,7 +30,7 @@ jobs:
node-version: lts/*

- name: get version
run: echo "PACKAGE_VERSION=$(node -p "require('./tauri.conf.json5').version")" >> $GITHUB_ENV
run: echo "PACKAGE_VERSION=$(node -p "require('./src/Apps/NetPad.Apps.Shells.Tauri/TauriApp/src-tauri/tauri.conf.json5').version")" >> $GITHUB_ENV

- name: create release
id: create-release
Expand All @@ -44,7 +41,7 @@ jobs:
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: `app-v${process.env.PACKAGE_VERSION}`,
name: `Desktop App (Tauri) v${process.env.PACKAGE_VERSION}`,
name: `NetPad vNext v${process.env.PACKAGE_VERSION}`,
body: 'Take a look at the assets to download and install this app.',
draft: true,
prerelease: false
Expand All @@ -62,8 +59,8 @@ jobs:
fail-fast: false
matrix:
include:
#- platform: "macos-latest" # for Arm based macs (M1 and above).
# args: "--target aarch64-apple-darwi -c src-tauri/tauri.conf.mac-arm64.json5n"
- platform: "macos-latest" # for Arm based macs (M1 and above).
args: "--target aarch64-apple-darwi -c src-tauri/tauri.conf.mac-arm64.json5"
#- platform: "macos-latest" # for Intel based macs.
# args: "--target x86_64-apple-darwin -c src-tauri/tauri.conf.mac-x64.json5"
#- platform: "ubuntu-22.04"
Expand Down
18 changes: 15 additions & 3 deletions src/Apps/NetPad.Apps.App/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ public static async Task<int> Main(string[] rawArgs)
Shell?.ShowErrorDialog(
$"{AppIdentifier.AppName} Already Running",
$"{AppIdentifier.AppName} is already running. You cannot open multiple instances of {AppIdentifier.AppName}.");
result = ProgramExitCode.PortUnavailable;
result = ProgramExitCode.PortUnavailable;
}
catch (Exception ex)
{
Console.WriteLine($"Host terminated unexpectedly with error:\n{ex}");
Log.Fatal(ex, "Host terminated unexpectedly");
result = ProgramExitCode.UnexpectedError;
result = ProgramExitCode.UnexpectedError;
}
finally
{
Expand Down Expand Up @@ -128,7 +128,19 @@ private static void RunApp(ProgramArgs args)

private static IHostBuilder CreateHostBuilder(ProgramArgs args) =>
Host.CreateDefaultBuilder(args.Raw)
.ConfigureAppConfiguration(config => { config.AddJsonFile("appsettings.Local.json", true); })
.ConfigureAppConfiguration(config =>
{
if (args.ShellType == ShellType.Electron)
{
config.AddJsonFile("appsettings.Electron.json", false);
}
else if (args.ShellType == ShellType.Tauri)
{
config.AddJsonFile("appsettings.Tauri.json", false);
}

config.AddJsonFile("appsettings.Local.json", true);
})
.UseSerilog((ctx, config) => { ConfigureLogging(config, ctx.Configuration); })
.ConfigureWebHostDefaults(webBuilder =>
{
Expand Down
15 changes: 13 additions & 2 deletions src/Apps/NetPad.Apps.App/ProgramArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ public ProgramArgs(string[] args)
{
Raw = args;

ShellType = Raw.Any(a => a.ContainsIgnoreCase("/ELECTRONPORT"))
? ShellType.Electron
: Raw.Any(a => a.EqualsIgnoreCase("--tauri"))
? ShellType.Tauri
: ShellType.Web;

RunMode = args.Contains("--swagger") ? RunMode.SwaggerGen : RunMode.Normal;

var parentPidArg = Array.IndexOf(args, "--parent-pid");
Expand Down Expand Up @@ -44,14 +50,19 @@ public ProgramArgs(string[] args)
/// </summary>
public RunMode RunMode { get; }

/// <summary>
/// The shell the app is running in.
/// </summary>
public ShellType ShellType { get; }

public IShell CreateShell()
{
if (Raw.Any(a => a.ContainsIgnoreCase("/ELECTRONPORT")))
if (ShellType == ShellType.Electron)
{
return new ElectronShell();
}

if (Raw.Any(a => a.EqualsIgnoreCase("--tauri")))
if (ShellType == ShellType.Tauri)
{
return new TauriShell();
}
Expand Down
8 changes: 8 additions & 0 deletions src/Apps/NetPad.Apps.App/ShellType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace NetPad;

public enum ShellType
{
Web,
Electron,
Tauri
}
1 change: 0 additions & 1 deletion src/Apps/NetPad.Apps.App/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"Urls": "http://localhost:57940",
"Serilog": {
"MinimumLevel": {
"Default": "Debug",
Expand Down
3 changes: 3 additions & 0 deletions src/Apps/NetPad.Apps.App/appsettings.Electron.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Urls": "http://localhost:57930"
}
3 changes: 3 additions & 0 deletions src/Apps/NetPad.Apps.App/appsettings.Tauri.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Urls": "http://localhost:57950"
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,7 @@ pub fn create_window(

// Allow when loader/index.html reroutes to SPA app hosted by .NET server
if url.host_str() == Some("localhost") {
return if cfg!(dev) {
url.port() == Some(57940)
} else {
url.port() == Some(57950)
};
url.port() == Some(57950)
}

// Reroute other URLs to system browser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"script": "npm run start-web",
"cwd": "../../../NetPad.Apps.App/App"
},
"devUrl": "http://localhost:57940?shell=tauri",
"devUrl": "http://localhost:57950?shell=tauri",
"frontendDist": "./loader"
},
"app": {
Expand Down

0 comments on commit 7ecce86

Please sign in to comment.