create-basicjs 0.1.5 → 0.1.7
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/README.md +12 -0
- package/bin/create-basicjs.js +49 -4
- package/package.json +1 -1
- package/payload/projects/tauri/.github/workflows/build.yml +86 -0
- package/payload/projects/tauri/.github/workflows/tests.yml +87 -0
- package/payload/projects/tauri/AGENTS.md +128 -0
- package/payload/projects/tauri/CLAUDE.md +1 -0
- package/payload/projects/tauri/LICENSE +201 -0
- package/payload/projects/tauri/NOTICE +8 -0
- package/payload/projects/tauri/README.md +269 -0
- package/payload/projects/tauri/checks/window-check.js +189 -0
- package/payload/projects/tauri/gitignore +8 -0
- package/payload/projects/tauri/handbook/01-getting-started.md +188 -0
- package/payload/projects/tauri/handbook/02-the-project.md +264 -0
- package/payload/projects/tauri/handbook/03-the-page.md +260 -0
- package/payload/projects/tauri/handbook/04-commands.md +265 -0
- package/payload/projects/tauri/handbook/05-events-and-state.md +275 -0
- package/payload/projects/tauri/handbook/06-plugins.md +282 -0
- package/payload/projects/tauri/handbook/07-the-window-and-the-app.md +431 -0
- package/payload/projects/tauri/handbook/08-security.md +374 -0
- package/payload/projects/tauri/handbook/09-tests-and-checks.md +266 -0
- package/payload/projects/tauri/handbook/10-building-and-releasing.md +238 -0
- package/payload/projects/tauri/handbook/11-troubleshooting.md +259 -0
- package/payload/projects/tauri/handbook/README.md +125 -0
- package/payload/projects/tauri/handbook/turkce/01-getting-started.md +193 -0
- package/payload/projects/tauri/handbook/turkce/02-the-project.md +272 -0
- package/payload/projects/tauri/handbook/turkce/03-the-page.md +272 -0
- package/payload/projects/tauri/handbook/turkce/04-commands.md +271 -0
- package/payload/projects/tauri/handbook/turkce/05-events-and-state.md +284 -0
- package/payload/projects/tauri/handbook/turkce/06-plugins.md +286 -0
- package/payload/projects/tauri/handbook/turkce/07-the-window-and-the-app.md +433 -0
- package/payload/projects/tauri/handbook/turkce/08-security.md +384 -0
- package/payload/projects/tauri/handbook/turkce/09-tests-and-checks.md +275 -0
- package/payload/projects/tauri/handbook/turkce/10-building-and-releasing.md +241 -0
- package/payload/projects/tauri/handbook/turkce/11-troubleshooting.md +264 -0
- package/payload/projects/tauri/handbook/turkce/README.md +128 -0
- package/payload/projects/tauri/images/app.png +0 -0
- package/payload/projects/tauri/src-tauri/Cargo.lock +4389 -0
- package/payload/projects/tauri/src-tauri/Cargo.toml +31 -0
- package/payload/projects/tauri/src-tauri/app-icon.svg +16 -0
- package/payload/projects/tauri/src-tauri/build.rs +15 -0
- package/payload/projects/tauri/src-tauri/capabilities/default.json +7 -0
- package/payload/projects/tauri/src-tauri/gitignore +5 -0
- package/payload/projects/tauri/src-tauri/icons/128x128.png +0 -0
- package/payload/projects/tauri/src-tauri/icons/128x128@2x.png +0 -0
- package/payload/projects/tauri/src-tauri/icons/32x32.png +0 -0
- package/payload/projects/tauri/src-tauri/icons/icon.icns +0 -0
- package/payload/projects/tauri/src-tauri/icons/icon.ico +0 -0
- package/payload/projects/tauri/src-tauri/src/check.rs +144 -0
- package/payload/projects/tauri/src-tauri/src/files.rs +255 -0
- package/payload/projects/tauri/src-tauri/src/main.rs +45 -0
- package/payload/projects/tauri/src-tauri/src/sizes.rs +214 -0
- package/payload/projects/tauri/src-tauri/tauri.conf.json +44 -0
- package/payload/projects/tauri/src-tauri/tests/project.rs +243 -0
- package/payload/projects/tauri/ui/app.js +459 -0
- package/payload/projects/tauri/ui/backend.js +196 -0
- package/payload/projects/tauri/ui/basic/LICENSE +14 -0
- package/payload/projects/tauri/ui/basic/basic.min.css +1 -0
- package/payload/projects/tauri/ui/basic/basic.min.js +78 -0
- package/payload/projects/tauri/ui/basic/font/open-sans/LICENSE.txt +206 -0
- package/payload/projects/tauri/ui/basic/font/open-sans/OpenSans-Bold.ttf +0 -0
- package/payload/projects/tauri/ui/basic/font/open-sans/OpenSans-Regular.ttf +0 -0
- package/payload/projects/tauri/ui/basic/scroll-bar.min.js +3 -0
- package/payload/projects/tauri/ui/comp/_sources.txt +9 -0
- package/payload/projects/tauri/ui/comp/components.min.js +21 -0
- package/payload/projects/tauri/ui/index.html +28 -0
- package/payload/projects/tauri/ui/sizes.js +104 -0
- package/payload/starter/_basic/VERSION +1 -1
- package/payload/starter/_basic/comp/bottom-bar.js +31 -3
- package/payload/starter/_basic/comp/code-editor.js +219 -1
- package/payload/starter/_basic/comp/context-menu.js +6 -1
- package/payload/starter/_basic/comp/markdown-view.js +4 -2
- package/payload/starter/_basic/comp/phone-field.js +13 -5
- package/payload/starter/_basic/comp/property-panel.js +1 -1
- package/payload/starter/_basic/comp/slider.js +27 -12
- package/payload/starter/_basic/comp/smart-button.js +5 -1
- package/payload/starter/_basic/comp/smart-table.js +8 -1
- package/payload/starter/_basic/comp/stepper.js +29 -3
- package/payload/starter/_basic/comp/toggle.js +2 -1
- package/payload/starter/_basic/docs/component-index.md +53 -53
- package/payload/starter/_basic/examples/code-editor.htm +48 -1
- package/payload/starter/_basic/examples/gallery-styled.htm +896 -0
- package/payload/starter/_basic/examples/search-input.htm +1 -1
- package/payload/starter/_basic/examples/select-box-2-item-view.htm +304 -0
- package/payload/starter/_basic/examples/{slider-2-classic.htm → slider-2-split.htm} +36 -2
- package/payload/starter/_basic/examples/stepper-2.htm +22 -6
- package/payload/starter/_basic/min/bottom-bar.min.js +1 -1
- package/payload/starter/_basic/min/code-editor.min.js +1 -1
- package/payload/starter/_basic/min/context-menu.min.js +1 -1
- package/payload/starter/_basic/min/markdown-view.min.js +1 -1
- package/payload/starter/_basic/min/phone-field.min.js +1 -1
- package/payload/starter/_basic/min/slider.min.js +1 -1
- package/payload/starter/_basic/min/smart-button.min.js +1 -1
- package/payload/starter/_basic/min/smart-table.min.js +1 -1
- package/payload/starter/_basic/min/stepper.min.js +1 -1
- package/payload/starter/_basic/min/toggle.min.js +1 -1
- package/payload/starter/_basic/tools/check.js +13 -2
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
# 7. The window and the app
|
|
2
|
+
|
|
3
|
+
*Türkçe: [7. Pencere ve uygulama](turkce/07-the-window-and-the-app.md)*
|
|
4
|
+
|
|
5
|
+
The window and what is around it: its settings, its changes from the page and the permission each one needs, a
|
|
6
|
+
question before it closes, a second window, the menu, the folders of the app, light and dark. Every sample was
|
|
7
|
+
compiled and run in a copy of the template on macOS (Apple Silicon, 2026-11-27).
|
|
8
|
+
|
|
9
|
+
## The window in tauri.conf.json
|
|
10
|
+
|
|
11
|
+
The template opens one window, written in `app.windows` of `src-tauri/tauri.conf.json`:
|
|
12
|
+
|
|
13
|
+
```json
|
|
14
|
+
{
|
|
15
|
+
"title": "Tauri Starter",
|
|
16
|
+
"width": 960,
|
|
17
|
+
"height": 640,
|
|
18
|
+
"minWidth": 760,
|
|
19
|
+
"minHeight": 420,
|
|
20
|
+
"theme": "Light"
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
The fields used most (the default is the value when the field is not written):
|
|
25
|
+
|
|
26
|
+
| Field | Default | What it does |
|
|
27
|
+
|---|---|---|
|
|
28
|
+
| `title` | `"Tauri App"` | the text of the title bar |
|
|
29
|
+
| `width`, `height` | 800, 600 | the size at the start, in the px of the page |
|
|
30
|
+
| `minWidth`, `minHeight`, `maxWidth`, `maxHeight` | none | the smallest and the largest size |
|
|
31
|
+
| `resizable` | `true` | the window can be made bigger and smaller |
|
|
32
|
+
| `center` | `false` | `true`: in the middle of the screen at the start |
|
|
33
|
+
| `maximized`, `fullscreen` | `false` | as large as the screen allows / the whole screen |
|
|
34
|
+
| `decorations` | `true` | `false`: no title bar and no border of the system |
|
|
35
|
+
| `theme` | the system | `"Light"` or `"Dark"` (below) |
|
|
36
|
+
| `label` | `"main"` | the name of the window for the code and for the capabilities |
|
|
37
|
+
|
|
38
|
+
- Tried: `"center": true` opened the window in the middle of the part of the screen under the menu bar of macOS.
|
|
39
|
+
- The file is compiled into the app: a change is seen when the app is compiled again.
|
|
40
|
+
- Every field: https://tauri.app/reference/config/ (the part `WindowConfig`).
|
|
41
|
+
|
|
42
|
+
## The window from the page
|
|
43
|
+
|
|
44
|
+
`window.__TAURI__.window.getCurrentWindow()` is the window of the page. `core:default` in
|
|
45
|
+
`src-tauri/capabilities/default.json` allows the questions, not the changes: each change needs a line of its own.
|
|
46
|
+
|
|
47
|
+
| In the page | What it does | Its line in `permissions` |
|
|
48
|
+
|---|---|---|
|
|
49
|
+
| `title()`, `innerSize()`, `scaleFactor()`, `isMaximized()`, `theme()` | questions | none (`core:default`) |
|
|
50
|
+
| `setTitle("Notes")` | the title | `"core:window:allow-set-title"` |
|
|
51
|
+
| `setSize(new window.__TAURI__.dpi.LogicalSize(900, 600))` | the size | `"core:window:allow-set-size"` |
|
|
52
|
+
| `minimize()` | into the Dock or the task bar | `"core:window:allow-minimize"` |
|
|
53
|
+
| `setTheme("light")` | the theme | `"core:window:allow-set-theme"` |
|
|
54
|
+
| `close()` | asks the window to close, as its close button does | `"core:window:allow-close"` |
|
|
55
|
+
| `destroy()` | closes it at once, with no question | `"core:window:allow-destroy"` |
|
|
56
|
+
|
|
57
|
+
Without its line the promise is rejected with a text that names the line. In a debug build (`cargo tauri dev`, the
|
|
58
|
+
window check), then in the built app (tried with a release build):
|
|
59
|
+
|
|
60
|
+
```text
|
|
61
|
+
window.set_title not allowed. Permissions associated with this command: core:window:allow-set-title
|
|
62
|
+
Command plugin:window|minimize not allowed by ACL
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
- `innerSize()` gives pixels of the screen: 1920 x 1280 for the window of 960 x 640 on a Retina screen, where
|
|
66
|
+
`scaleFactor()` is 2.
|
|
67
|
+
- `document.title` (`page.title` of basic.js) does not change the title bar (tried): use `setTitle()`.
|
|
68
|
+
- Every line of the core: https://tauri.app/reference/acl/core-permissions/
|
|
69
|
+
|
|
70
|
+
## The title that follows the folder
|
|
71
|
+
|
|
72
|
+
The title bar shows the name of the folder: "Documents - Tauri Starter". **1.** Add
|
|
73
|
+
`"core:window:allow-set-title"` to `permissions` in `src-tauri/capabilities/default.json`. **2.** A function in
|
|
74
|
+
`ui/backend.js` (in a browser it changes the title of the tab):
|
|
75
|
+
|
|
76
|
+
```js
|
|
77
|
+
// The title of the window (core:window:allow-set-title in capabilities/default.json). In a browser: the tab.
|
|
78
|
+
Backend.setWindowTitle = function (title) {
|
|
79
|
+
if (!Backend.isInApp()) {
|
|
80
|
+
page.title = title;
|
|
81
|
+
return Promise.resolve(null);
|
|
82
|
+
}
|
|
83
|
+
return window.__TAURI__.window.getCurrentWindow().setTitle(title);
|
|
84
|
+
};
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
**3.** In `ui/app.js`: a constant at the top (`const APP_NAME = "Tauri Starter";`), the line `showTitle(folder);` at
|
|
88
|
+
the end of `showFolder()`, and the function under it:
|
|
89
|
+
|
|
90
|
+
```js
|
|
91
|
+
// The title bar shows the folder: "Documents - Tauri Starter"
|
|
92
|
+
const showTitle = function (folder) {
|
|
93
|
+
const lastCrumb = folder.crumbs[folder.crumbs.length - 1];
|
|
94
|
+
Backend.setWindowTitle(lastCrumb.name + " - " + APP_NAME);
|
|
95
|
+
};
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
A step of the window check proves it (in `checks/window-check.js`, after the step "the table shows the entries"):
|
|
99
|
+
|
|
100
|
+
```js
|
|
101
|
+
const folderName = currentFolder.crumbs[currentFolder.crumbs.length - 1].name;
|
|
102
|
+
const title = await window.__TAURI__.window.getCurrentWindow().title();
|
|
103
|
+
WindowCheck.expect(title == folderName + " - Tauri Starter", "the title of the window follows the folder: " + title);
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Its line: `PASS the title of the window follows the folder: tauri-starter-check-49282 - Tauri Starter`.
|
|
107
|
+
|
|
108
|
+
## Before the window closes
|
|
109
|
+
|
|
110
|
+
`onCloseRequested(handler)` runs a function when the window is asked to close (its close button, or `close()`).
|
|
111
|
+
With such a function Tauri does not close the window itself: it waits for the function (which may give a promise),
|
|
112
|
+
then the page closes the window with `destroy()`, unless the function called `event.preventDefault()`.
|
|
113
|
+
**So it needs `"core:window:allow-destroy"`.** Without it the window does not close at all, and the console says:
|
|
114
|
+
|
|
115
|
+
```text
|
|
116
|
+
window.destroy not allowed. Permissions associated with this command: core:window:allow-destroy
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
A question while "Sizes" is measuring. In `ui/backend.js`:
|
|
120
|
+
|
|
121
|
+
```js
|
|
122
|
+
// handler(event) runs when the window is asked to close; event.preventDefault() keeps it open.
|
|
123
|
+
// handler may give a promise: the window waits for it. WHY core:window:allow-destroy: with a handler, Tauri does not
|
|
124
|
+
// close the window itself; the page closes it after the handler (destroy).
|
|
125
|
+
Backend.onCloseRequested = function (handler) {
|
|
126
|
+
if (!Backend.isInApp()) return;
|
|
127
|
+
window.__TAURI__.window.getCurrentWindow().onCloseRequested(handler);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// A question of the system with Yes and No (the dialog plugin): true for Yes
|
|
131
|
+
Backend.ask = function (question) {
|
|
132
|
+
if (!Backend.isInApp()) return Promise.resolve(window.confirm(question));
|
|
133
|
+
return window.__TAURI__.dialog.ask(question, { title: "Tauri Starter", kind: "warning" });
|
|
134
|
+
};
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
In `ui/app.js`, the line `Backend.onCloseRequested(onCloseRequested);` in `start()`, and the function:
|
|
138
|
+
|
|
139
|
+
```js
|
|
140
|
+
// The window is asked to close while Rust measures: a question first; "No" keeps the window open
|
|
141
|
+
const onCloseRequested = function (event) {
|
|
142
|
+
if (!Sizes.job) return;
|
|
143
|
+
return Backend.ask("Rust is still measuring the folders. Close the window?").then(function (isSure) {
|
|
144
|
+
if (!isSure) event.preventDefault();
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
- Two lines in `permissions`: `"core:window:allow-destroy"`, and `"dialog:allow-message"` for `ask()` (it is the
|
|
150
|
+
`message` command of the plugin; the template allows only `"dialog:allow-open"`: [6. Plugins](06-plugins.md)).
|
|
151
|
+
Without the second one the question is refused (tried):
|
|
152
|
+
|
|
153
|
+
```text
|
|
154
|
+
dialog.message not allowed. Permissions associated with this command: dialog:allow-ask, dialog:allow-confirm,
|
|
155
|
+
dialog:allow-message, dialog:default
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
- Tried with the close request that a close button sends (made by `close()` in Rust), the dialog replaced by an
|
|
159
|
+
answer of the code (a dialog waits for a person, so the window check can not open it): "No" kept the window open;
|
|
160
|
+
a handler that let the close go on closed the window (the second window below). Try the question yourself in
|
|
161
|
+
`cargo tauri dev`: "Sizes" on a big folder, then close the window.
|
|
162
|
+
- Quitting the whole app (Quit in the app menu of macOS) was not tried with it.
|
|
163
|
+
|
|
164
|
+
Rust hears the windows too, in `src-tauri/src/main.rs` (Ex: to stop a job of a window that is gone):
|
|
165
|
+
|
|
166
|
+
```rust
|
|
167
|
+
.on_window_event(|window, event| {
|
|
168
|
+
if let tauri::WindowEvent::Destroyed = event {
|
|
169
|
+
println!("the window {} is closed", window.label());
|
|
170
|
+
}
|
|
171
|
+
})
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## A second window
|
|
175
|
+
|
|
176
|
+
A small window with a page of its own: the keys of the app. **1. Rust** makes it, in a new file `windows.rs` in
|
|
177
|
+
`src-tauri/src/` (with the header of the other files), added with `mod windows;` in `main.rs` and
|
|
178
|
+
`windows::open_keys_window` in `generate_handler!`:
|
|
179
|
+
|
|
180
|
+
```rust
|
|
181
|
+
use tauri::{AppHandle, Manager, WebviewUrl, WebviewWindowBuilder};
|
|
182
|
+
|
|
183
|
+
const KEYS_LABEL: &str = "keys";
|
|
184
|
+
const KEYS_WIDTH: f64 = 420.0;
|
|
185
|
+
const KEYS_HEIGHT: f64 = 330.0;
|
|
186
|
+
|
|
187
|
+
/// Opens the window "keys", or brings it to the front when it is open
|
|
188
|
+
// WHY async: on Windows, a window made in a plain command or in an event handler stops the app (the "Known issues"
|
|
189
|
+
// of WebviewWindowBuilder::new)
|
|
190
|
+
#[tauri::command]
|
|
191
|
+
pub async fn open_keys_window(app: AppHandle) -> Result<(), String> {
|
|
192
|
+
if let Some(window) = app.get_webview_window(KEYS_LABEL) {
|
|
193
|
+
return window.set_focus().map_err(|error| error.to_string());
|
|
194
|
+
}
|
|
195
|
+
WebviewWindowBuilder::new(&app, KEYS_LABEL, WebviewUrl::App("keys.html".into()))
|
|
196
|
+
.title("Keys")
|
|
197
|
+
.inner_size(KEYS_WIDTH, KEYS_HEIGHT)
|
|
198
|
+
.resizable(false)
|
|
199
|
+
.build()
|
|
200
|
+
.map_err(|error| error.to_string())?;
|
|
201
|
+
Ok(())
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
The label (`"keys"`) is the name of the window: one window for one label, so a second call finds it and brings it
|
|
206
|
+
to the front. `WebviewUrl::App("keys.html")` is a file of `ui/`. **2. Its page**, `keys.html` in `ui/`: the
|
|
207
|
+
library, `backend.js` (the one place that calls Tauri) and `keys.js`:
|
|
208
|
+
|
|
209
|
+
```html
|
|
210
|
+
<!DOCTYPE html>
|
|
211
|
+
<html lang="en">
|
|
212
|
+
<head>
|
|
213
|
+
<title>Keys</title>
|
|
214
|
+
<meta charset="UTF-8">
|
|
215
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
216
|
+
<link rel="stylesheet" type="text/css" href="basic/basic.min.css">
|
|
217
|
+
<script src="basic/basic.min.js" type="text/javascript" charset="utf-8"></script>
|
|
218
|
+
<script src="backend.js" type="text/javascript" charset="utf-8"></script>
|
|
219
|
+
<script src="keys.js" type="text/javascript" charset="utf-8"></script>
|
|
220
|
+
</head>
|
|
221
|
+
<body></body>
|
|
222
|
+
</html>
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
`keys.js` in `ui/`:
|
|
226
|
+
|
|
227
|
+
```js
|
|
228
|
+
"use strict";
|
|
229
|
+
|
|
230
|
+
// The keys of the main window, one line each
|
|
231
|
+
const KEYS = [
|
|
232
|
+
"↑ ↓: the row above or below",
|
|
233
|
+
"Page Up / Page Down: a page of rows",
|
|
234
|
+
"Home / End: the first or the last row",
|
|
235
|
+
"Enter: opens the folder of the row",
|
|
236
|
+
"Cmd / Ctrl + ↑: the folder above",
|
|
237
|
+
"Cmd / Ctrl + O: Open... (the folder dialog)",
|
|
238
|
+
];
|
|
239
|
+
|
|
240
|
+
const start = function () {
|
|
241
|
+
|
|
242
|
+
page.color = "white";
|
|
243
|
+
|
|
244
|
+
// GROUP: The name of the app, then a line for every key
|
|
245
|
+
VGroup({ align: "left top", gap: 10, padding: 24 });
|
|
246
|
+
const lblName = Label({ text: "Tauri Starter", fontSize: 18, bold: 1 });
|
|
247
|
+
KEYS.forEach(function (key) {
|
|
248
|
+
Label({ text: key, fontSize: 14 });
|
|
249
|
+
});
|
|
250
|
+
endGroup();
|
|
251
|
+
|
|
252
|
+
Backend.getAppVersion().then(function (version) {
|
|
253
|
+
lblName.plainText = "Tauri Starter " + version;
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
};
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
**3. Two functions** in `ui/backend.js` (and `Backend.SAMPLE_VERSION = "0.1.0";` with the sample data):
|
|
260
|
+
|
|
261
|
+
```js
|
|
262
|
+
// The second window, with its own page: ui/keys.html (src-tauri/src/windows.rs)
|
|
263
|
+
Backend.openKeysWindow = function () {
|
|
264
|
+
if (!Backend.isInApp()) {
|
|
265
|
+
window.open("keys.html", "keys");
|
|
266
|
+
return Promise.resolve(null);
|
|
267
|
+
}
|
|
268
|
+
return window.__TAURI__.core.invoke("open_keys_window");
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
// The version of the app: the version of src-tauri/Cargo.toml
|
|
272
|
+
Backend.getAppVersion = function () {
|
|
273
|
+
if (!Backend.isInApp()) return Promise.resolve(Backend.SAMPLE_VERSION);
|
|
274
|
+
return window.__TAURI__.app.getVersion();
|
|
275
|
+
};
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
**4. Its permissions.** `capabilities/default.json` is for `"windows": ["main"]`. In a window that is in no list,
|
|
279
|
+
the commands of the app still answer (tried: `list_folder`), but nothing of Tauri does, not even `getVersion()`. The
|
|
280
|
+
window gets a file of its own, `keys.json` in `src-tauri/capabilities/`, with only what its page uses:
|
|
281
|
+
|
|
282
|
+
```json
|
|
283
|
+
{
|
|
284
|
+
"$schema": "../gen/schemas/desktop-schema.json",
|
|
285
|
+
"identifier": "keys",
|
|
286
|
+
"description": "The Keys window (ui/keys.html) only reads the version of the app.",
|
|
287
|
+
"windows": ["keys"],
|
|
288
|
+
"permissions": ["core:app:allow-version"]
|
|
289
|
+
}
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
- Tried: the version came; an event sent from that page was refused (`event.emit not allowed on window "keys"`, the
|
|
293
|
+
whole text in [8. Security](08-security.md)).
|
|
294
|
+
- A window can also be written in `app.windows` of `tauri.conf.json`, with its own `"label"` and `"url"`
|
|
295
|
+
(`"url": "keys.html"`): it opens with the app (tried).
|
|
296
|
+
- The main page closes it with `destroy()` of `Window.getByLabel("keys")` (`"core:window:allow-destroy"`).
|
|
297
|
+
|
|
298
|
+
## The menu of the app
|
|
299
|
+
|
|
300
|
+
On macOS Tauri gives the app a menu (read in the running app): the menu of the app (About, Services, Hide, Hide
|
|
301
|
+
Others, Quit), File (Close Window), Edit (Undo, Redo, Cut, Copy, Paste, Select All), View (Toggle Full Screen),
|
|
302
|
+
Window (Minimize, Zoom, Close Window) and an empty Help. On Windows and Linux the template has no menu (the code of
|
|
303
|
+
Tauri makes that menu only on macOS).
|
|
304
|
+
|
|
305
|
+
A menu of your own starts from it, so Quit and the Edit menu stay. A new file `app_menu.rs` in `src-tauri/src/`
|
|
306
|
+
(with the header of the other files):
|
|
307
|
+
|
|
308
|
+
```rust
|
|
309
|
+
use tauri::menu::{Menu, MenuEvent, MenuItemBuilder, SubmenuBuilder, HELP_SUBMENU_ID};
|
|
310
|
+
use tauri::{AppHandle, Emitter, Wry};
|
|
311
|
+
|
|
312
|
+
// The ids of the items the page does (ui/app.js: MENU_ACTIONS)
|
|
313
|
+
const PAGE_ITEMS: [&str; 2] = ["home", "keys"];
|
|
314
|
+
|
|
315
|
+
/// The menu of Tauri (on macOS: the app menu, File, Edit, View, Window, Help), with "Go" and an item in "Help"
|
|
316
|
+
pub fn create(app: &AppHandle) -> tauri::Result<Menu<Wry>> {
|
|
317
|
+
let menu = Menu::default(app)?;
|
|
318
|
+
|
|
319
|
+
let home = MenuItemBuilder::with_id("home", "Home Folder")
|
|
320
|
+
.accelerator("CmdOrCtrl+Shift+H")
|
|
321
|
+
.build(app)?;
|
|
322
|
+
let go = SubmenuBuilder::new(app, "Go").item(&home).build()?;
|
|
323
|
+
// WHY before the last two: Window and Help stay at the end, as in other apps
|
|
324
|
+
let place = menu.items()?.len() - 2;
|
|
325
|
+
menu.insert(&go, place)?;
|
|
326
|
+
|
|
327
|
+
let keys = MenuItemBuilder::with_id("keys", "Keys of Tauri Starter").build(app)?;
|
|
328
|
+
if let Some(help) = menu.get(HELP_SUBMENU_ID) {
|
|
329
|
+
if let Some(help) = help.as_submenu() {
|
|
330
|
+
help.append(&keys)?;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
Ok(menu)
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/// A click on an item of the menu
|
|
337
|
+
pub fn on_click(app: &AppHandle, event: MenuEvent) {
|
|
338
|
+
let id = event.id().as_ref();
|
|
339
|
+
if PAGE_ITEMS.contains(&id) {
|
|
340
|
+
let _ = app.emit("menu", id);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
In `src-tauri/src/main.rs`: `mod app_menu;`, and two lines on the builder (after `.manage(...)`):
|
|
346
|
+
|
|
347
|
+
```rust
|
|
348
|
+
.menu(app_menu::create)
|
|
349
|
+
.on_menu_event(app_menu::on_click)
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
A click sends the event `"menu"` with the id of the item; the page does it as a click on its own button. In
|
|
353
|
+
`ui/app.js`, the line `Backend.listen("menu", onMenuClick);` in `start()`, and:
|
|
354
|
+
|
|
355
|
+
```js
|
|
356
|
+
// The items of the menu (src-tauri/src/app_menu.rs): the id of the item -> what the page does
|
|
357
|
+
const MENU_ACTIONS = { home: openHome, keys: Backend.openKeysWindow };
|
|
358
|
+
|
|
359
|
+
const onMenuClick = function (itemId) {
|
|
360
|
+
const action = MENU_ACTIONS[itemId];
|
|
361
|
+
if (action) action();
|
|
362
|
+
};
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
- Why through the page: one place for what a button and its menu item do; and the Keys window is made by an `async`
|
|
366
|
+
command, not in the menu handler (the known issue of Windows above).
|
|
367
|
+
- Tried on macOS, the items clicked by a script: Go > Home Folder opened the home folder, Help > Keys of Tauri
|
|
368
|
+
Starter opened the second window.
|
|
369
|
+
- With `.menu(...)`, Tauri gives the menu to every window on Windows and Linux (a bar in the window): look at it
|
|
370
|
+
there before a release.
|
|
371
|
+
- A window check can not click a menu: it sends the event of the item itself,
|
|
372
|
+
`window.__TAURI__.event.emit("menu", "keys")`, then waits for the window `keys`.
|
|
373
|
+
- Check items, icons in a menu, a menu of one window: https://tauri.app/learn/window-menu/
|
|
374
|
+
|
|
375
|
+
## An icon in the menu bar
|
|
376
|
+
|
|
377
|
+
An icon of the app next to the clock (the tray), with a menu, is made in Rust with `tauri::tray::TrayIconBuilder` in
|
|
378
|
+
`.setup(...)` of the builder, and needs a feature of the crate `tauri` in `src-tauri/Cargo.toml`:
|
|
379
|
+
`tauri = { version = "2", features = ["tray-icon"] }` (`cargo tauri build` keeps the line: tried). Tauri gives the
|
|
380
|
+
clicks on its menu to the same `on_menu_event` as those of the menu above. The guide of Tauri:
|
|
381
|
+
https://tauri.app/learn/system-tray/
|
|
382
|
+
|
|
383
|
+
## The folders of the app
|
|
384
|
+
|
|
385
|
+
Each system has folders for the data of an app, named after its `identifier`. Rust asks `app.path()` (with
|
|
386
|
+
`use tauri::Manager;`), the page asks `window.__TAURI__.path` (allowed by `core:default`). On macOS (2026-11-27):
|
|
387
|
+
|
|
388
|
+
| Rust | The page | macOS |
|
|
389
|
+
|---|---|---|
|
|
390
|
+
| `app_config_dir()` | `appConfigDir()` | `~/Library/Application Support/io.github.bug7a.tauri-starter` |
|
|
391
|
+
| `app_data_dir()`, `app_local_data_dir()` | `appDataDir()`, `appLocalDataDir()` | the same folder |
|
|
392
|
+
| `app_cache_dir()` | `appCacheDir()` | `~/Library/Caches/io.github.bug7a.tauri-starter` |
|
|
393
|
+
| `app_log_dir()` | `appLogDir()` | `~/Library/Logs/io.github.bug7a.tauri-starter` |
|
|
394
|
+
| `home_dir()` | `homeDir()` | the home folder (`list_folder` opens it for an empty path) |
|
|
395
|
+
| `temp_dir()` | `tempDir()` | the temporary folder of the system |
|
|
396
|
+
|
|
397
|
+
- Change the `identifier` before the first release ([2. The project](02-the-project.md)): the data of the old one
|
|
398
|
+
stays in the folders of the old name.
|
|
399
|
+
- The folder may not be there yet: Rust makes it before the first file, `std::fs::create_dir_all(&folder)`.
|
|
400
|
+
- In Rust: `let data_folder = app.path().app_data_dir().map_err(|error| error.to_string())?;` (the command of
|
|
401
|
+
chapter 8 reads its notes from `data_folder.join("notes")`).
|
|
402
|
+
- Settings that the page keeps between two runs (the last folder, "Hidden files"): the store plugin keeps them in a
|
|
403
|
+
file of these folders, with no Rust ([6. Plugins](06-plugins.md)).
|
|
404
|
+
|
|
405
|
+
## Light and dark
|
|
406
|
+
|
|
407
|
+
The window takes the look of the system, and the page knows it. Tried on a Mac with the dark look:
|
|
408
|
+
|
|
409
|
+
| `theme` of the window | `theme()` | `matchMedia("(prefers-color-scheme: dark)").matches` |
|
|
410
|
+
|---|---|---|
|
|
411
|
+
| not written | `"dark"` | `true` |
|
|
412
|
+
| `"Light"` | `"light"` | `false` |
|
|
413
|
+
|
|
414
|
+
- The page of the template has only light colors, so its window has `"theme": "Light"` in `tauri.conf.json`: on a
|
|
415
|
+
dark system the window keeps the look of the page. A page with both looks leaves the field out.
|
|
416
|
+
- A page with both looks reads the media query in `start()` and gives the components their dark style packages
|
|
417
|
+
(`styleName`, in the header of each component).
|
|
418
|
+
- `setTheme()` from the page needs `"core:window:allow-set-theme"`.
|
|
419
|
+
|
|
420
|
+
## One copy at a time, the size between runs
|
|
421
|
+
|
|
422
|
+
Not tried in this handbook; both are plugins (the way of [6. Plugins](06-plugins.md)):
|
|
423
|
+
|
|
424
|
+
- One copy of the app at a time (a second start of the app runs a function of the first one instead):
|
|
425
|
+
https://tauri.app/plugin/single-instance/
|
|
426
|
+
- The size and the place of the window kept between two runs: https://tauri.app/plugin/window-state/
|
|
427
|
+
|
|
428
|
+
## Next
|
|
429
|
+
|
|
430
|
+
[8. Security](08-security.md): what the page may load and run, what each window may call, and commands that guard
|
|
431
|
+
themselves.
|