create-vidra-app 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +23 -7
- package/package.json +1 -1
- package/templates/react-vite/README.md +12 -2
- package/templates/react-vite/package.json +1 -0
- package/templates/react-vite/src/{{projectName}}.Host/MainPage.cs +6 -0
- package/templates/react-vite/src/{{projectName}}.Host/MauiProgram.cs +6 -3
- package/templates/react-vite/src/{{projectName}}.Host/Platforms/Android/AndroidManifest.xml +9 -0
- package/templates/react-vite/src/{{projectName}}.Host/Platforms/Android/MainActivity.cs +37 -0
- package/templates/react-vite/src/{{projectName}}.Host/Platforms/Android/MainApplication.cs +17 -0
- package/templates/react-vite/src/{{projectName}}.Host/Platforms/Android/Resources/drawable/vidra_notification.xml +10 -0
- package/templates/react-vite/src/{{projectName}}.Host/{{projectName}}.Host.csproj +9 -4
- package/templates/react-vite/ui/src/App.tsx +10 -4
- package/templates/react-vite/vidra.config.ts +21 -17
package/dist/index.js
CHANGED
|
@@ -201,6 +201,14 @@ var newestNet10Sdk = (listSdksOutput) => splitLines(listSdksOutput).map((line) =
|
|
|
201
201
|
(a, b) => a.localeCompare(b, void 0, { numeric: true, sensitivity: "base" })
|
|
202
202
|
).pop();
|
|
203
203
|
var outputMentionsMaui = (workloadListOutput) => MAUI_WORKLOAD.test(workloadListOutput);
|
|
204
|
+
var outputMentionsMauiTarget = (workloadListOutput, target) => {
|
|
205
|
+
if (!target) return outputMentionsMaui(workloadListOutput);
|
|
206
|
+
const targetWorkload = target === "macos" ? "maui-maccatalyst" : target === "windows" ? "maui-windows" : "maui-android";
|
|
207
|
+
return new RegExp(
|
|
208
|
+
`(?:\\[(?:maui|${targetWorkload})\\]|^\\s*(?:maui|${targetWorkload})\\s)`,
|
|
209
|
+
"m"
|
|
210
|
+
).test(workloadListOutput);
|
|
211
|
+
};
|
|
204
212
|
var checkDotnetSdk = () => {
|
|
205
213
|
const name = ".NET SDK";
|
|
206
214
|
const res = run(DOTNET, ["--list-sdks"]);
|
|
@@ -226,9 +234,13 @@ var checkDotnetSdk = () => {
|
|
|
226
234
|
fix: INSTALL_NET_10_FIX
|
|
227
235
|
};
|
|
228
236
|
};
|
|
229
|
-
var isMauiWorkloadInstalled = () =>
|
|
230
|
-
|
|
231
|
-
|
|
237
|
+
var isMauiWorkloadInstalled = (target) => outputMentionsMauiTarget(
|
|
238
|
+
run(DOTNET, ["workload", "list"]).stdout,
|
|
239
|
+
target
|
|
240
|
+
);
|
|
241
|
+
var mauiWorkloadFor = (target) => target === "android" ? "maui-android" : target === "windows" ? "maui-windows" : target === "macos" ? "maui-maccatalyst" : "maui";
|
|
242
|
+
var installWorkload = (csprojPath, target) => {
|
|
243
|
+
const args = target ? ["workload", "install", mauiWorkloadFor(target)] : csprojPath ? ["workload", "restore", csprojPath] : ["workload", "install", "maui"];
|
|
232
244
|
console.log();
|
|
233
245
|
console.log(
|
|
234
246
|
row({
|
|
@@ -255,7 +267,9 @@ var installWorkload = (csprojPath) => {
|
|
|
255
267
|
)
|
|
256
268
|
)
|
|
257
269
|
);
|
|
258
|
-
console.error(
|
|
270
|
+
console.error(
|
|
271
|
+
fixLine(`sudo dotnet workload install ${mauiWorkloadFor(target)}`)
|
|
272
|
+
);
|
|
259
273
|
console.error();
|
|
260
274
|
return false;
|
|
261
275
|
}
|
|
@@ -277,7 +291,7 @@ var ensureMauiWorkload = async (opts = {}) => {
|
|
|
277
291
|
return false;
|
|
278
292
|
}
|
|
279
293
|
if (dotnet.status === "unknown") return true;
|
|
280
|
-
if (isMauiWorkloadInstalled()) return true;
|
|
294
|
+
if (isMauiWorkloadInstalled(opts.target)) return true;
|
|
281
295
|
console.log();
|
|
282
296
|
console.log(
|
|
283
297
|
row({
|
|
@@ -301,7 +315,7 @@ var ensureMauiWorkload = async (opts = {}) => {
|
|
|
301
315
|
install = false;
|
|
302
316
|
}
|
|
303
317
|
if (install) {
|
|
304
|
-
if (installWorkload(opts.csprojPath) && isMauiWorkloadInstalled()) {
|
|
318
|
+
if (installWorkload(opts.csprojPath, opts.target) && isMauiWorkloadInstalled(opts.target)) {
|
|
305
319
|
console.log(
|
|
306
320
|
row({
|
|
307
321
|
glyph: "done",
|
|
@@ -314,7 +328,9 @@ var ensureMauiWorkload = async (opts = {}) => {
|
|
|
314
328
|
return false;
|
|
315
329
|
}
|
|
316
330
|
}
|
|
317
|
-
console.log(
|
|
331
|
+
console.log(
|
|
332
|
+
fixLine(`dotnet workload install ${mauiWorkloadFor(opts.target)}`, "run:")
|
|
333
|
+
);
|
|
318
334
|
console.log(fixLine(MAUI_DOCS, "docs:"));
|
|
319
335
|
return false;
|
|
320
336
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# {{appTitle}}
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A cross-platform application built with [Vidra](https://vidra.build): a React UI and a
|
|
4
4
|
C#/.NET native host.
|
|
5
5
|
|
|
6
6
|
## Requirements
|
|
@@ -9,8 +9,11 @@ C#/.NET native host.
|
|
|
9
9
|
- .NET MAUI workload: `dotnet workload install maui`
|
|
10
10
|
- [Node.js](https://nodejs.org/) 22 or newer
|
|
11
11
|
- Xcode for macOS builds
|
|
12
|
+
- JDK 17 and the Android SDK for Android builds
|
|
12
13
|
|
|
13
|
-
Windows targets must be built on Windows.
|
|
14
|
+
Windows targets must be built on Windows. Android targets can be built on
|
|
15
|
+
Windows, macOS, or Linux; connect an emulator/device and run
|
|
16
|
+
`npm run dev -- --target android`.
|
|
14
17
|
|
|
15
18
|
## Development
|
|
16
19
|
|
|
@@ -23,6 +26,13 @@ npm run dev
|
|
|
23
26
|
reload through Vite; supported C# changes reload through the .NET development
|
|
24
27
|
loop.
|
|
25
28
|
|
|
29
|
+
For Android, `vidra dev` selects the connected device (or `ANDROID_SERIAL`),
|
|
30
|
+
installs the app, and reads readiness from logcat. It prefers `adb reverse`,
|
|
31
|
+
then falls back to `10.0.2.2` on an emulator or the development machine's LAN
|
|
32
|
+
address on a physical device. Set `VIDRA_ANDROID_HOST` when automatic interface
|
|
33
|
+
selection picks a VPN or container network. The page respects system safe areas; hardware
|
|
34
|
+
Back navigates WebView history before exiting.
|
|
35
|
+
|
|
26
36
|
## Build
|
|
27
37
|
|
|
28
38
|
```bash
|
|
@@ -6,6 +6,12 @@ public class MainPage : VidraPage
|
|
|
6
6
|
{
|
|
7
7
|
public MainPage()
|
|
8
8
|
{
|
|
9
|
+
AppWebView.Navigated += OnFirstNavigated;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
private void OnFirstNavigated(object? sender, WebNavigatedEventArgs e)
|
|
13
|
+
{
|
|
14
|
+
AppWebView.Navigated -= OnFirstNavigated;
|
|
9
15
|
StartCounterTimer();
|
|
10
16
|
}
|
|
11
17
|
|
|
@@ -27,14 +27,17 @@ public static class MauiProgram
|
|
|
27
27
|
// A bundle only installs when its contract fingerprints match this build,
|
|
28
28
|
// so JS can never call a bridge the installed binary lacks.
|
|
29
29
|
//
|
|
30
|
-
// Whole app: native code included, via Velopack. Its other
|
|
31
|
-
// `VelopackApp` line in
|
|
32
|
-
// the UI framework starts.
|
|
30
|
+
// Whole app (desktop): native code included, via Velopack. Its other
|
|
31
|
+
// half is the `VelopackApp` line in the desktop Program.cs files, which
|
|
32
|
+
// has to run before the UI framework starts. Google Play owns Android
|
|
33
|
+
// app updates; only the web-bundle tier runs there.
|
|
33
34
|
builder
|
|
34
35
|
.UseMauiApp<App>()
|
|
35
36
|
.UseVidra()
|
|
36
37
|
.UseVidraUpdates()
|
|
38
|
+
#if !ANDROID
|
|
37
39
|
.UseVidraNativeUpdates()
|
|
40
|
+
#endif
|
|
38
41
|
.ConfigureFonts(fonts =>
|
|
39
42
|
{
|
|
40
43
|
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
3
|
+
<uses-permission android:name="android.permission.INTERNET" />
|
|
4
|
+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
|
5
|
+
<uses-permission android:name="android.permission.BATTERY_STATS" />
|
|
6
|
+
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
|
7
|
+
<application android:allowBackup="true"
|
|
8
|
+
android:supportsRtl="true" />
|
|
9
|
+
</manifest>
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
using Android.App;
|
|
2
|
+
using Android.Content.PM;
|
|
3
|
+
using Android.OS;
|
|
4
|
+
using Vidra.Hosting;
|
|
5
|
+
|
|
6
|
+
namespace {{projectName}};
|
|
7
|
+
|
|
8
|
+
[Activity(
|
|
9
|
+
Theme = "@style/Maui.SplashTheme",
|
|
10
|
+
MainLauncher = true,
|
|
11
|
+
LaunchMode = LaunchMode.SingleTop,
|
|
12
|
+
ConfigurationChanges = ConfigChanges.ScreenSize
|
|
13
|
+
| ConfigChanges.Orientation
|
|
14
|
+
| ConfigChanges.UiMode
|
|
15
|
+
| ConfigChanges.ScreenLayout
|
|
16
|
+
| ConfigChanges.SmallestScreenSize
|
|
17
|
+
| ConfigChanges.Density)]
|
|
18
|
+
public class MainActivity : MauiAppCompatActivity
|
|
19
|
+
{
|
|
20
|
+
protected override void OnCreate(Bundle? savedInstanceState)
|
|
21
|
+
{
|
|
22
|
+
ApplyDebugLaunchOverrides(Intent);
|
|
23
|
+
base.OnCreate(savedInstanceState);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
protected override void OnNewIntent(Android.Content.Intent? intent)
|
|
27
|
+
{
|
|
28
|
+
base.OnNewIntent(intent);
|
|
29
|
+
ApplyDebugLaunchOverrides(intent);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
private void ApplyDebugLaunchOverrides(Android.Content.Intent? intent)
|
|
33
|
+
{
|
|
34
|
+
if ((ApplicationInfo?.Flags & ApplicationInfoFlags.Debuggable) != 0)
|
|
35
|
+
VidraRuntimeSettings.ApplyAndroidIntentExtras(intent);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
using Android.App;
|
|
2
|
+
using Android.Runtime;
|
|
3
|
+
|
|
4
|
+
namespace {{projectName}};
|
|
5
|
+
|
|
6
|
+
#if DEBUG
|
|
7
|
+
[Application(UsesCleartextTraffic = true)]
|
|
8
|
+
#elif VIDRA_ANDROID_TEST_RUNTIME
|
|
9
|
+
[Application(Debuggable = true, UsesCleartextTraffic = true)]
|
|
10
|
+
#else
|
|
11
|
+
[Application]
|
|
12
|
+
#endif
|
|
13
|
+
public class MainApplication(nint handle, JniHandleOwnership ownership)
|
|
14
|
+
: MauiApplication(handle, ownership)
|
|
15
|
+
{
|
|
16
|
+
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
|
|
17
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
|
3
|
+
android:width="24dp"
|
|
4
|
+
android:height="24dp"
|
|
5
|
+
android:viewportWidth="24"
|
|
6
|
+
android:viewportHeight="24">
|
|
7
|
+
<path
|
|
8
|
+
android:fillColor="#FFFFFFFF"
|
|
9
|
+
android:pathData="M12,22a2.5,2.5 0,0 0,2.45 -2h-4.9A2.5,2.5 0,0 0,12 22zM19,17v-6a7,7 0,0 0,-5.5 -6.84V3a1.5,1.5 0,0 0,-3 0v1.16A7,7 0,0 0,5 11v6l-2,2h18z" />
|
|
10
|
+
</vector>
|
|
@@ -8,11 +8,14 @@
|
|
|
8
8
|
restore can read an assets file with no x64 target and fail with
|
|
9
9
|
NETSDK1047. Naming the set here makes every restore write both. -->
|
|
10
10
|
<RuntimeIdentifiers Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers>
|
|
11
|
-
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('osx'))">net10.0-maccatalyst</TargetFrameworks>
|
|
12
|
-
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">net10.0-windows10.0.19041.0</TargetFrameworks>
|
|
11
|
+
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('osx'))">net10.0-maccatalyst;net10.0-android</TargetFrameworks>
|
|
12
|
+
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">net10.0-windows10.0.19041.0;net10.0-android</TargetFrameworks>
|
|
13
|
+
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('linux'))">net10.0-android</TargetFrameworks>
|
|
13
14
|
<ValidateXcodeVersion>false</ValidateXcodeVersion>
|
|
14
15
|
<OutputType>Exe</OutputType>
|
|
15
16
|
<RootNamespace>{{projectName}}</RootNamespace>
|
|
17
|
+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
|
|
18
|
+
<DefineConstants Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android' And '$(VidraAndroidTestRuntime)' == 'true'">$(DefineConstants);VIDRA_ANDROID_TEST_RUNTIME</DefineConstants>
|
|
16
19
|
<UseMaui>true</UseMaui>
|
|
17
20
|
<SingleProject>true</SingleProject>
|
|
18
21
|
<ImplicitUsings>enable</ImplicitUsings>
|
|
@@ -48,7 +51,7 @@
|
|
|
48
51
|
-->
|
|
49
52
|
<CodesignEntitlements Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">Entitlements.plist</CodesignEntitlements>
|
|
50
53
|
|
|
51
|
-
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">
|
|
54
|
+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">17.0</SupportedOSPlatformVersion>
|
|
52
55
|
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
|
|
53
56
|
|
|
54
57
|
<!--
|
|
@@ -104,7 +107,9 @@
|
|
|
104
107
|
having to retrofit an entry point, a package reference and a builder call
|
|
105
108
|
into an app that has already shipped.
|
|
106
109
|
-->
|
|
107
|
-
<PackageReference Include="Vidra.Updates.Native"
|
|
110
|
+
<PackageReference Include="Vidra.Updates.Native"
|
|
111
|
+
Version="{{vidraVersion}}"
|
|
112
|
+
Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) != 'android'" />
|
|
108
113
|
</ItemGroup>
|
|
109
114
|
|
|
110
115
|
</Project>
|
|
@@ -42,6 +42,7 @@ const App = () => {
|
|
|
42
42
|
// Emitted by the native host when `vidra dev` hot reloads edited C#.
|
|
43
43
|
const unsubscribeHotReloaded = runtime.onHotReloaded(
|
|
44
44
|
(data) => {
|
|
45
|
+
(window as any).__vidraEventProof = true;
|
|
45
46
|
const typeName = data?.updatedTypes?.[0]?.split(".").pop();
|
|
46
47
|
setCsReloaded(typeName ? `C# reloaded · ${typeName}` : "C# reloaded");
|
|
47
48
|
window.clearTimeout(reloadFlashTimer.current);
|
|
@@ -63,6 +64,7 @@ const App = () => {
|
|
|
63
64
|
void appWindow
|
|
64
65
|
.getSupport()
|
|
65
66
|
.then((result: WindowSupport) => {
|
|
67
|
+
(window as any).__vidraNativeCallProof = true;
|
|
66
68
|
setWindowSupport(result);
|
|
67
69
|
})
|
|
68
70
|
.catch(() => {
|
|
@@ -268,8 +270,12 @@ const App = () => {
|
|
|
268
270
|
|
|
269
271
|
<div className="actions">
|
|
270
272
|
<button onClick={handleGetWindowInfo}>Get Window Info</button>
|
|
271
|
-
|
|
272
|
-
|
|
273
|
+
{windowSupport?.setTitle && (
|
|
274
|
+
<button onClick={handleRenameWindow}>Rename Window</button>
|
|
275
|
+
)}
|
|
276
|
+
{windowSupport?.configure && (
|
|
277
|
+
<button onClick={handleResizeWindow}>Resize Window</button>
|
|
278
|
+
)}
|
|
273
279
|
{windowSupport?.center && (
|
|
274
280
|
<button onClick={handleCenterWindow}>Center Window</button>
|
|
275
281
|
)}
|
|
@@ -288,9 +294,9 @@ const App = () => {
|
|
|
288
294
|
|
|
289
295
|
{!showsAdvancedWindowActions && windowSupport && (
|
|
290
296
|
<p className="note">
|
|
291
|
-
This runtime currently supports title and size updates only.
|
|
292
297
|
Unsupported window actions are hidden automatically based on native
|
|
293
|
-
support metadata.
|
|
298
|
+
support metadata. Android exposes current window information but no
|
|
299
|
+
desktop window controls.
|
|
294
300
|
</p>
|
|
295
301
|
)}
|
|
296
302
|
</section>
|
|
@@ -1,26 +1,30 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
defineConfig,
|
|
3
|
+
events as builtInEvents,
|
|
4
|
+
native as builtInNative,
|
|
5
|
+
} from "@vidra-dev/sdk/config";
|
|
2
6
|
|
|
3
7
|
export default defineConfig({
|
|
4
8
|
bridge: {
|
|
5
9
|
allow: [
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
builtInNative.app.getInfo,
|
|
11
|
+
builtInNative.appWindow.center,
|
|
12
|
+
builtInNative.appWindow.configure,
|
|
13
|
+
builtInNative.appWindow.getCurrent,
|
|
14
|
+
builtInNative.appWindow.getSupport,
|
|
15
|
+
builtInNative.appWindow.maximize,
|
|
16
|
+
builtInNative.appWindow.minimize,
|
|
17
|
+
builtInNative.appWindow.restore,
|
|
18
|
+
builtInNative.appWindow.setTitle,
|
|
19
|
+
builtInNative.browser.open,
|
|
20
|
+
builtInNative.clipboard.getText,
|
|
21
|
+
builtInNative.notifications.requestPermission,
|
|
22
|
+
builtInNative.notifications.show,
|
|
19
23
|
],
|
|
20
24
|
events: [
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
builtInEvents.appWindow.resized,
|
|
26
|
+
builtInEvents.appWindow.stateChanged,
|
|
27
|
+
builtInEvents.runtime.hotReloaded,
|
|
24
28
|
],
|
|
25
29
|
},
|
|
26
30
|
updates: {
|