Put your app together.
Choose a frontend, package manager, Window host, and ViewModel library.
The command below creates exactly this project. It makes the same choices dnx Runic.Create asks for in your terminal.
The defaults, Runic Desktop and ReactiveUI, suit most apps. Choosing a host and MVVM library explains when to pick another.
Your command
For Runic SDK 0.23.0.
dnx Runic.Create@0.23.0 -- MyApp --frontend react --package-manager npm --host desktop --linux-gtk 3 --desktop-server native --view-models reactiveui dnx runs the creator without installing it. It installs Runic.Application.Templates and runs dotnet new runic-app, then prints these commands again.
Run dnx Runic.Create@0.23.0 to answer the questions in your
terminal instead.
Then run it
cd MyApp
dotnet tool restore
dotnet runic dev Add a View later
dotnet new runic-view --name Settings --view-models reactiveui
dotnet new runic-view --name Preferences --view-models reactiveui --window Run in the project directory. The runic-view item
template comes with Runic.Application.Templates and
adds a View, or with --window a Window, and its ViewModel;
the next build writes its typed client.
Preview
Selected files from the template, rendered for your choices.
using Microsoft.Extensions.DependencyInjection;
using Runic.Application.Views;
using Runic.Application.Views.Desktop;
using Runic.Desktop;
using Runic.Platform;
using MyApp;
await using var provider = new ServiceCollection().AddWorkspace().BuildServiceProvider(new ServiceProviderOptions
{
ValidateScopes = true,
ValidateOnBuild = true
});
var developing = string.Equals(Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT"), "Development", StringComparison.OrdinalIgnoreCase);
// In Development, View ▸ Developer Tools opens the Window's developer tools: WebView2's DevTools on Windows, WebKit's
// Web Inspector on Linux. macOS opens WKWebView's Web Inspector from Safari ▸ Develop instead, so it gets no item.
DesktopMenu[] menuBar = developing && !OperatingSystem.IsMacOS()
? [new DesktopMenu("View", [new DesktopMenuItem("Developer Tools", DesktopMenuItem.OpenDevToolsCommandId)])]
: [];
// Fallbacks and limitations, such as a missing WebKitGTK runtime, are written to standard error and to
// DiagnosticsLog.Path, since a Windows application has no console.
// Linux embeds WebKitGTK 4.1 through GTK 3. Windows uses WebView2 and macOS WKWebView.
var options = new DesktopHostOptions
{
Linux = new() { EmbeddedBackend = LinuxEmbeddedBackend.Gtk3WebKit41 },
DiagnosticSink = ReportDiagnostic,
MenuBar = menuBar,
};
// Outside Development, the Window's pages get a Content-Security-Policy: scripts and connections only from the
// application itself, no string evaluation, no plugins, no foreign <base> and no framing. The Views Bridge needs
// nothing more: its state arrives as data. Development (dotnet runic dev and its development server) sends none.
const string contentSecurityPolicy = "default-src 'self'; script-src 'self'; object-src 'none'; base-uri 'self'; frame-ancestors 'none'";
var hostOptions = new RunicDesktopHostOptions { ContentSecurityPolicy = developing ? null : contentSecurityPolicy };
// Opens Windows natively with the embedded WebView, falling back to an installed browser, on the event loop
// this platform and backend need. Call it before any await. RunicCsWebUiHost.Run(provider, RunAsync), from
// Runic.Application.Views.CsWebUi, runs the same application on CS-WebUI.
return RunicDesktopHost.Run(provider, options, hostOptions, RunAsync);
// The application is the same on every host: open the Window, then wait until it closes.
static async Task<int> RunAsync(IRunicWindowHost host)
{
await using var window = await host.OpenWindowAsync<WorkspaceWindow>(new RunicWindowOptions { Width = 1000, Height = 700 });
await window.WaitForCloseAsync();
return 0;
}
static void ReportDiagnostic(DesktopDiagnostic diagnostic) =>
DiagnosticsLog.Write($"{diagnostic.Severity} {diagnostic.Code}: {diagnostic.Message} {diagnostic.Remediation}".TrimEnd());
New to the Window and View model? Read Window and View or the getting-started guide.