Skip to content

Commit

Permalink
Documentation WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
guillemcordoba committed May 14, 2024
1 parent 0260043 commit d562269
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 34 deletions.
24 changes: 24 additions & 0 deletions crates/scaffold_tauri_app/fixture/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
description = "Template for Holochain app development";

inputs = {
versions.url = "github:holochain/holochain?dir=versions/0_3_rc";

holochain.url = "github:holochain/holochain";
holochain.inputs.versions.follows = "versions";

nixpkgs.follows = "holochain/nixpkgs";
flake-parts.follows = "holochain/flake-parts";

};

outputs = inputs:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
systems = builtins.attrNames inputs.holochain.devShells;
perSystem = { inputs', config, pkgs, system, ... }: {
devShells.default = pkgs.mkShell {
inputsFrom = [ inputs'.holochain.devShells.holonix ];
};
};
};
}
3 changes: 3 additions & 0 deletions crates/scaffold_tauri_app/fixture/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "root"
}
7 changes: 7 additions & 0 deletions crates/scaffold_tauri_app/fixture/workdir/web-happ.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
manifest_version: "1"
name: "myapp"
ui:
bundled: "../ui/dist.zip"
happ_manifest:
bundled: "./forum.happ"
2 changes: 0 additions & 2 deletions crates/scaffold_tauri_app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,6 @@ pub fn scaffold_tauri_app(
}
close += 2;

println!("{}", &flake_nix_content[open..close]);

// - Add an androidDev devshell by copying the default devShell, and adding the holochainTauriAndroidDev
let android_dev_shell = flake_nix_content[open..close]
.to_string()
Expand Down
26 changes: 23 additions & 3 deletions docs/android-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@
1. In the root folder of your repository, run:

```bash
::: code-group
```bash [npm]
npm run tauri android init
```

```bash [yarn]
yarn tauri android init
```

```bash [pnpm]
pnpm tauri android init
```
:::

This should initialize all the necessary android files for your app.

Expand Down Expand Up @@ -94,7 +104,7 @@ This is a replacement command for the usual `nix develop`, which includes `Andro
> [!WARNING]
> The first time this is run, it will take some time. This is because nix has to download and build all the necessary Android tooling. After the first time, it will be almost instant.
7. Inside your `androidDev` nix shell, run:
7. Inside your `androidDev` devShell, run:

```bash
adb devices
Expand All @@ -104,9 +114,19 @@ If all the previous steps were successful, you should see your device in the lis

8. Verify that everything is working by running the app for android with:

```bash
::: code-group
```bash [npm]
npm run tauri android dev
```

```bash [yarn]
yarn tauri android dev
```

```bash [pnpm]
pnpm tauri android dev
```
:::

---

Expand Down
50 changes: 45 additions & 5 deletions docs/getting-to-know-tauri.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,73 @@ Although it's still young, tauri already has a [wide ecosystem of plugins that e

You can learn more about it [in the official Tauri documentation](https://beta.tauri.app/concepts/).

## Backend

As we just learned, the backend for Tauri is written in rust. Let's understand how that backend works, so that you can edit its behavior to suit your needs, if necessary.

It's important that you take a look at the file `src-tauri/src/lib.rs`. This is now the main starting point for your hApp, which includes the `tauri-plugin-holochain` plugin. This plugin will run holochain under the hood, and converts the Tauri app in to a full holochain runtime.

Still in that file, take a closer look at the `.setup()` hook. This is the initialization code that will be run when your end-user app is executed. You can see that the scaffolded code already contains a simple initialization logic, that you can extend to any need you have to

Refer to the [rust documentation for the `tauri-plugin-holochain`](https://docs.rs/tauri-plugin-holochain) to learn all the commands that the plugin offers.

## CLI

Tauri includes a powerful CLI that allows us to execute the different commands we need in our development lifecycle:

- To start a development version of our app, run:

```bash
::: code-group
```bash [npm]
npm run tauri dev
```

```bash [yarn]
yarn tauri dev
```

```bash [pnpm]
pnpm tauri dev
```
:::

- To create a production build for the current platform, run:

```bash
::: code-group
```bash [npm]
npm run tauri build
```

```bash [yarn]
yarn tauri build
```

```bash [pnpm]
pnpm tauri build
```
:::

- See all the commands available to you with:
- See all the available CLI commands with:

::: code-group
```bash [npm]
npm run tauri
```

```bash [yarn]
yarn tauri
```

```bash
```bash [pnpm]
pnpm tauri
```
:::

And learn more about the CLI in the [official Tauri guide](https://beta.tauri.app/references/v2/cli/).

## Mobile

After the initial set up and scaffolding, the initial tauri app can only be built for desktop apps. To enable mobile support, there is a bit more work that needs to be done.
After the initial set up and scaffolding, our tauri app can only be built for desktop apps. To enable mobile support, there is a bit more work that needs to be done.

### Android

Expand Down
58 changes: 43 additions & 15 deletions docs/how-to-create-an-executable-happ.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,66 @@ We need a way to create end-users applications for mobile platforms to create si
> [!NOTE]
> If you already have a hApp that you want to convert to a tauri executable app, you can skip this step.
1. Run this command inside the repository of your web-app:
1. Run this command inside the repository of your web-hApp:

```bash
nix run github:darksoil-studio/tauri-plugin-holochain#scaffold-tauri-app
```

And follow along to answer all the necessary prompts.

This will execute all the required steps to convert your previously scaffolded hApp to an end-user executable tauri app. The command tries to guess as best as possible what's in your project.
This will execute all the required steps to convert your previously scaffolded hApp to an end-user executable tauri app.

2. Take a look into the files that the scaffold command edited, and adapt them if necessary:

- `flake.nix`: added the `tauri-plugin-holochain` input and its `devShells`.
- `package.json`: added set up scripts and some `devDependencies`.
- `src-tauri`: here is where the code for the backend of the tauri app lives.
- The tauri app will just use the UI that the scaffolding tool produced as its own UI.

> [!WARNING]
> The `scaffold-tauri-app` command assumes that you have scaffolded your app using the scaffolding tool.
>
> It also tries to make smart guesses about the structure of your project, but it can be tricky to support every repository structure. Please open an issue in the github repository if you find any bugs in it!
> [!WARNING]
> The `scaffold-tauri-app` command tries to make smart guesses about the structure of your project, but it can be tricky to support every repository structure. Please open an issue in the github repository if you find any bugs in it!

2. Take a look into the files that the scaffold command edited, and adapt them if necessary:
That's it! We now have a fully functional end-user executable hApp.

- `flake.nix`
- `package.json`
## Development Environment

---
The `scaffold-tauri-app` has added the necessary nix `devShells` to your `flake.nix` file so that you don't need to follow install anything to get the tauri or Android development environment.

That's it! We have created a fully functional executable hApp.
> [!NOTE]
> Nix `devShells` are packages that describe development environments, with all their dependencies and environment variables, so that the developer does not need to configure manually their setup.
It is in fact just a Tauri app that depends on `tauri-plugin-holochain`. As such, we should get to know Tauri a bit better to be comfortable while developing the app. Go to [Getting to know Tauri](./getting-to-know-tauri.md) to familiarize yourself with it.
As usual, run this command to enter the development environment:

### Android
```bash
nix develop
```

Continue to the [Android setup](./android-setup.md);
This can take a while while it builds all the required dependencies.

### iOS
Next, run these commands:

::: code-group
```bash [npm]
npm install
npm start
```

```bash [yarn]
yarn install
yarn start
```

```bash [pnpm]
pnpm install
pnpm start
```
:::

This will start two agents connected to each other.

Under the hood, these commands are running tauri CLI commands. As such, we should get to know Tauri a bit better to be comfortable while developing the app. Go to [Getting to know Tauri](./getting-to-know-tauri.md) to familiarize yourself with it.

> [!WARNING]
> Coming soon! Holochain working on iOS is blocked by wasmer having an interpreter wasm engine. Work is already in progress, so stay tuned! You can learn more by reading the [FAQs](/faqs).
4 changes: 0 additions & 4 deletions docs/troubleshooting.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@


- Uses clearTraffic = true in build.gradle.kts

### NixOS

#### Connect to devices
Expand Down
5 changes: 0 additions & 5 deletions examples/tauri-app/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@
# devShells.default = inputs'.tauriHolochain.devShells.holochainTauriDev;
devShells.default = pkgs.mkShell {
inputsFrom = [ inputs'.tauriHolochain.devShells.holochainTauriDev ];
packages = [
(pkgs.writeShellScriptBin "run-local-services" ''
${pkgs.unixtools.netstat}/bin/netstat
'')
];
};
devShells.androidDev =
inputs'.tauriHolochain.devShells.holochainTauriAndroidDev;
Expand Down

0 comments on commit d562269

Please sign in to comment.