Skip to content

Commit

Permalink
chore: run pnpm format on the repo
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Feb 3, 2024
1 parent 88a1dd1 commit ab57f95
Show file tree
Hide file tree
Showing 22 changed files with 448 additions and 398 deletions.
4 changes: 1 addition & 3 deletions .changes/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,7 @@
"tauri-plugin": {
"path": "./core/tauri-plugin",
"manager": "rust",
"dependencies": [
"tauri-utils"
],
"dependencies": ["tauri-utils"],
"postversion": "node ../../.scripts/covector/sync-cli-metadata.js ${ pkg.pkg } ${ release.type }"
},
"tauri-build": {
Expand Down
1 change: 1 addition & 0 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ To do this, open your project with VS Code and run **Remote-Containers: Clone Re
Docker Desktop provides facilities for [allowing the development container to connect to a service on the Docker host](https://docs.docker.com/desktop/windows/networking/#i-want-to-connect-from-a-container-to-a-service-on-the-host). So long as you have an X window server running on your Docker host, the devcontainer can connect to it and expose your Tauri GUI via an X window.

**Export the `DISPLAY` variable within the devcontainer terminal you launch your Tauri application from to expose your GUI outside of the devcontainer**.

```bash
export DISPLAY="host.docker.internal:0"
```
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ dist
/tooling/cli/schema.json
/core/tauri-config-schema/schema.json
CHANGELOG.md
*.wxs
**/reference.md
*schema.json
3 changes: 2 additions & 1 deletion .scripts/covector/package-latest-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ https.get(url, options, (response) => {
response.on('end', function () {
const data = JSON.parse(chunks.join(''))
if (kind === 'cargo') {
const versions = data.versions?.filter((v) => v.num.startsWith(target)) ?? []
const versions =
data.versions?.filter((v) => v.num.startsWith(target)) ?? []
console.log(versions.length ? versions[0].num : '0.0.0')
} else if (kind === 'npm') {
const versions = Object.keys(data.versions).filter((v) =>
Expand Down
41 changes: 38 additions & 3 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
@@ -1,103 +1,132 @@
# The Tauri Architecture

https://tauri.app

https://github.com/tauri-apps/tauri

## Introduction

Tauri is a polyglot and generic toolkit that is very composable and allows engineers to make a wide variety of applications. It is used for building applications for Desktop Computers using a combination of Rust tools and HTML rendered in a Webview. Apps built with Tauri can ship with any number of pieces of an optional JS API / Rust API so that webviews can control the system via message passing. In fact, developers can extend the default API with their own functionality and bridge the Webview and Rust-based backend easily.

Tauri apps can have custom menus and have tray-type interfaces. They can be updated, and are managed by the user's operating system as expected. They are very small, because they use the OS's webview. They do not ship a runtime, since the final binary is compiled from Rust. This makes the reversing of Tauri apps not a trivial task.

## What Tauri is NOT

- Tauri is not a lightweight kernel wrapper...instead it directly uses [WRY](#wry) and [TAO](#tao) to do the heavy-lifting in making system calls to the OS.
- Tauri is not a VM or virtualized environment...instead it is an application toolkit that allows making Webview OS applications.

## Major Components

The following section briefly describes the roles of the various parts of Tauri.

### Tauri Core [STABLE RUST]

#### [tauri](https://github.com/tauri-apps/tauri/tree/dev/core/tauri)

This is the major crate that holds everything together. It brings the runtimes, macros, utilities and API into one final product. It reads the `tauri.conf.json` file at compile time in order to bring in features and undertake actual configuration of the app (and even the `Cargo.toml` file in the project's folder). It handles script injection (for polyfills / prototype revision) at runtime, hosts the API for systems interaction, and even manages updating.

#### [tauri-build](https://github.com/tauri-apps/tauri/tree/dev/core/tauri-build)

Apply the macros at build-time in order to rig some special features needed by `cargo`.

#### [tauri-codegen](https://github.com/tauri-apps/tauri/tree/dev/core/tauri-codegen)

- Embed, hash, and compress assets, including icons for the app as well as the system-tray.
- Parse `tauri.conf.json` at compile time and generate the Config struct.

#### [tauri-macros](https://github.com/tauri-apps/tauri/tree/dev/core/tauri-macros)

Create macros for the context, handler, and commands by leveraging the `tauri-codegen` crate.

#### [tauri-runtime](https://github.com/tauri-apps/tauri/tree/dev/core/tauri-runtime)

This is the glue layer between tauri itself and lower level webview libraries.

#### [tauri-runtime-wry](https://github.com/tauri-apps/tauri/tree/dev/core/tauri-runtime-wry)

This crate opens up direct systems-level interactions specifically for WRY, such as printing, monitor detection, and other windowing related tasks. `tauri-runtime` implementation for WRY.

#### [tauri-utils](https://github.com/tauri-apps/tauri/tree/dev/core/tauri-utils)
This is common code that is reused in many places and offers useful utilities like parsing configuration files, detecting platform triples, injecting the CSP, and managing assets.

This is common code that is reused in many places and offers useful utilities like parsing configuration files, detecting platform triples, injecting the CSP, and managing assets.

### Tauri Tooling

#### [@tauri-apps/api](https://github.com/tauri-apps/tauri/tree/dev/tooling/api) [TS -> JS]

A TypeScript library that creates `cjs` and `esm` JavaScript endpoints for you to import into your Frontend framework so that the Webview can call and listen to backend activity. We also ship the pure TypeScript, because for some frameworks this is more optimal. It uses the message passing of webviews to their hosts.

#### [bundler](https://github.com/tauri-apps/tauri/tree/dev/tooling/bundler) [RUST / SHELL]

The bundler is a library that builds a Tauri App for the platform triple it detects / is told. At the moment it currently supports macOS, Windows and Linux - but in the near future will support mobile platforms as well. May be used outside of Tauri projects.

#### [@tauri-apps/cli](https://github.com/tauri-apps/tauri/tree/dev/tooling/cli/node) [JS]

It is a wrapper around [tauri-cli](https://github.com/tauri-apps/tauri/blob/dev/tooling/cli) using [napi-rs](https://github.com/napi-rs/napi-rs) to produce NPM packages for each platform.

#### [tauri-cli](https://github.com/tauri-apps/tauri/tree/dev/tooling/cli) [RUST]

This rust executable provides the full interface to all of the required activities for which the CLI is required. It will run on macOS, Windows, and Linux.

#### [create-tauri-app](https://github.com/tauri-apps/create-tauri-app) [JS]

This is a toolkit that will enable engineering teams to rapidly scaffold out a new tauri-apps project using the frontend framework of their choice (as long as it has been configured).

# External Crates

The Tauri-Apps organisation maintains two "upstream" crates from Tauri, namely TAO for creating and managing application windows, and WRY for interfacing with the Webview that lives within the window.

## [TAO](https://github.com/tauri-apps/tao)
Cross-platform application window creation library in Rust that supports all major platforms like Windows, macOS, Linux, iOS and Android. Written in Rust, it is a fork of [winit](https://github.com/rust-windowing/winit) that we have extended for our own needs like menu bar and system tray.

Cross-platform application window creation library in Rust that supports all major platforms like Windows, macOS, Linux, iOS and Android. Written in Rust, it is a fork of [winit](https://github.com/rust-windowing/winit) that we have extended for our own needs like menu bar and system tray.

## [WRY](https://github.com/tauri-apps/wry)

WRY is a cross-platform WebView rendering library in Rust that supports all major desktop platforms like Windows, macOS, and Linux.
Tauri uses WRY as the abstract layer responsible to determine which webview is used (and how interactions are made).

# Additional tooling

## [tauri-action](https://github.com/tauri-apps/tauri-action)

This is a github workflow that builds tauri binaries for all platforms. It is not the fastest out there, but it gets the job done and is highly configurable. Even allowing you to create a (very basic) tauri app even if tauri is not setup.

## [create-pull-request](https://github.com/tauri-apps/create-pull-request)

Because this is a very risky (potentially destructive) github action, we forked it in order to have strong guarantees that the code we think is running is actually the code that is running.

## [vue-cli-plugin-tauri](https://github.com/tauri-apps/vue-cli-plugin-tauri)

This plugin allows you to very quickly install tauri in a vue-cli project.

## [tauri-vscode](https://github.com/tauri-apps/tauri-vscode)

This project enhances the VS Code interface with several nice-to-have features.

# Tauri Plugins [documentation](https://tauri.app/v1/guides/features/plugin/)

Generally speaking, plugins are authored by third parties (even though there may be official, supported plugins). A plugin generally does 3 things:

1. It provides rust code to do "something".
2. It provides interface glue to make it easy to integrate into an app.
3. It provides a JS API for interfacing with the rust code.

Here are several examples of Tauri Plugins:

- https://github.com/tauri-apps/tauri-plugin-sql
- https://github.com/tauri-apps/tauri-plugin-stronghold
- https://github.com/tauri-apps/tauri-plugin-authenticator

# Workflows

## What does the Development flow look like?

A developer must first install the prerequisite toolchains for creating a Tauri app. At the very least this will entail installing rust & cargo, and most likely also a modern version of node.js and potentially another package manager. Some platforms may also require other tooling and libraries, but this has been documented carefully in the respective platform docs.

Because of the many ways to build front-ends, we will stick with a common node.js based approach for development. (Note: Tauri does not by default ship a node.js runtime.)

The easiest way to do this is to run the following:

```
npx create-tauri-app
```
Expand All @@ -107,12 +136,15 @@ Which will ask you a bunch of questions about the framework you want to install
> If you don't use this process, you will have to manually install the tauri cli, initialise tauri and manually configure the `tauri.conf.json` file.
Once everything is installed, you can run:

```
yarn tauri dev
-or-
npm run tauri dev
```

This will do several things:

1. start the JS Framework devserver
2. begin the long process of downloading and compiling the rust libraries
3. open an application window with devtools enabled
Expand All @@ -128,29 +160,32 @@ If you need to get deeper insight into your current project, or triage requires
yarn tauri info
```


## What does the Release flow look like?

The release flow begins with proper configuration in the `tauri.conf.json` file. In this file, the developer can configure not only the basic behaviour of the application (like window size and decoration), they can also provide settings for signing and updating.

Depending upon the operating system that the developer (or CI) is building the application on, there will be an app built for them for that system. (Cross compilation is not currently available, however there is an official [GitHub Action](https://github.com/tauri-apps/tauri-action) that can be used to build for all platforms.)

To kick off this process, just:

```
yarn tauri build
```

After some time, the process will end and you can see the results in the `./src-tauri/target/release` folder.

## What does the End-User flow look like?

End users will be provided with binaries in ways that are appropriate for their systems. Whether macOS, Linux, or Windows, direct download or store installations - they will be able to follow procedures for installing and removing that they are used to.

## What does the Updating flow look like?

When a new version is ready, the developer publishes the new signed artifacts to a server (that they have configured within `tauri.conf.json`).

The application can poll this server to see if there is a new release. When there is a new release, the user is prompted to update. The application update is downloaded, verified (checksum & signature), updated, closed, and restarted.

## License

Tauri itself is licensed under MIT or Apache-2.0. If you repackage it and modify any source code, it is your responsibility to verify that you are complying with all upstream licenses. Tauri is provided AS-IS with no explicit claim for suitability for any purpose.

Here you may peruse our [Software Bill of Materials](https://app.fossa.com/projects/git%2Bgithub.com%2Ftauri-apps%2Ftauri).
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ Additionally, we may ask you to independently verify our patch, which will be av

Depending on your decision to accept or deny credit for the vulnerability, you will be publicly attributed to the vulnerability and may be mentioned in our announcements.

At the current time we do not have the financial ability to reward bounties,
At the current time we do not have the financial ability to reward bounties,
but in extreme cases will at our discretion consider a reward.
12 changes: 9 additions & 3 deletions core/tauri-runtime-wry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,32 @@
[![https://good-labs.github.io/greater-good-affirmation/assets/images/badge.svg](https://good-labs.github.io/greater-good-affirmation/assets/images/badge.svg)](https://good-labs.github.io/greater-good-affirmation)
[![support](https://img.shields.io/badge/sponsor-Opencollective-blue.svg)](https://opencollective.com/tauri)

| Component | Version |
| --------- | ------------------------------------------- |
| tauri-runtime-wry | [![](https://img.shields.io/crates/v/tauri-runtime-wry?style=flat-square)](https://crates.io/crates/tauri-runtime-wry) |
| Component | Version |
| ----------------- | ---------------------------------------------------------------------------------------------------------------------- |
| tauri-runtime-wry | [![](https://img.shields.io/crates/v/tauri-runtime-wry?style=flat-square)](https://crates.io/crates/tauri-runtime-wry) |

## About Tauri

Tauri is a polyglot and generic system that is very composable and allows engineers to make a wide variety of applications. It is used for building applications for Desktop Computers using a combination of Rust tools and HTML rendered in a Webview. Apps built with Tauri can ship with any number of pieces of an optional JS API / Rust API so that webviews can control the system via message passing. In fact, developers can extend the default API with their own functionality and bridge the Webview and Rust-based backend easily.

Tauri apps can have custom menus and have tray-type interfaces. They can be updated, and are managed by the user's operating system as expected. They are very small, because they use the system's webview. They do not ship a runtime, since the final binary is compiled from rust. This makes the reversing of Tauri apps not a trivial task.

## This module

This crate opens up direct systems-level interactions specifically for WRY, such as printing, monitor detection, and other windowing related tasks. `tauri-runtime` implementation for WRY.

To learn more about the details of how all of these pieces fit together, please consult this [ARCHITECTURE.md](https://github.com/tauri-apps/tauri/blob/dev/ARCHITECTURE.md) document.

## Semver

**tauri** is following [Semantic Versioning 2.0](https://semver.org/).

## Licenses

Code: (c) 2021 - The Tauri Programme within The Commons Conservancy.

MIT or MIT/Apache 2.0 where applicable.

Logo: CC-BY-NC-ND

- Original Tauri Logo Designs by [Daniel Thompson-Yvetot](https://github.com/nothingismagick) and [Guillaume Chau](https://github.com/akryum)
2 changes: 1 addition & 1 deletion core/tauri/scripts/process-ipc-message-fn.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// this is a function and not an iife so use it carefully

(function (message) {
;(function (message) {
if (
message instanceof ArrayBuffer ||
ArrayBuffer.isView(message) ||
Expand Down
17 changes: 10 additions & 7 deletions core/tauri/src/window/scripts/drag.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
// while macOS macos maximization should be on mouseup and if the mouse
// moves after the double click, it should be cancelled (see https://github.com/tauri-apps/tauri/issues/8306)
//-----------------------//
const TAURI_DRAG_REGION_ATTR = 'data-tauri-drag-region';
let x = 0, y = 0;
const TAURI_DRAG_REGION_ATTR = 'data-tauri-drag-region'
let x = 0,
y = 0
document.addEventListener('mousedown', (e) => {
if (
// element has the magic data attribute
Expand All @@ -20,8 +21,7 @@
e.button === 0 &&
// and was normal click to drag or double click to maximize
(e.detail === 1 || e.detail === 2)
) {

) {
// macOS maximization happens on `mouseup`,
// so we save needed state and early return
if (osName === 'macos' && e.detail == 2) {
Expand All @@ -44,7 +44,7 @@
})
// on macOS we maximze on mouseup instead, to match the system behavior where maximization can be canceled
// if the mouse moves outside the data-tauri-drag-region
if (osName === "macos") {
if (osName === 'macos') {
document.addEventListener('mouseup', (e) => {
if (
// element has the magic data attribute
Expand All @@ -54,9 +54,12 @@
// and was double click
e.detail === 2 &&
// and the cursor hasn't moved from initial mousedown
e.clientX === x && e.clientY === y
e.clientX === x &&
e.clientY === y
) {
window.__TAURI_INTERNALS__.invoke('plugin:window|internal_toggle_maximize')
window.__TAURI_INTERNALS__.invoke(
'plugin:window|internal_toggle_maximize'
)
}
})
}
Expand Down
6 changes: 2 additions & 4 deletions core/tests/acl/fixtures/capabilities/scope-extended/cap.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{
"identifier": "run-app",
"description": "app capability",
"windows": [
"main"
],
"windows": ["main"],
"permissions": [
{
"identifier": "fs:read",
Expand Down Expand Up @@ -38,4 +36,4 @@
},
"fs:read-download-dir"
]
}
}
7 changes: 2 additions & 5 deletions examples/api/src-tauri/capabilities/run-app.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
"$schema": "./schemas/desktop-schema.json",
"identifier": "run-app",
"description": "permissions to run the app",
"windows": [
"main",
"main-*"
],
"windows": ["main", "main-*"],
"permissions": [
"sample:allow-ping-scoped",
"sample:global-scope",
Expand Down Expand Up @@ -88,4 +85,4 @@
"tray:allow-set-icon-as-template",
"tray:allow-set-show-menu-on-left-click"
]
}
}
Loading

0 comments on commit ab57f95

Please sign in to comment.