Skip to content

Commit a7c1733

Browse files
committed
refactor: use declarative window configuration; correct main window minimizable
1 parent a739e10 commit a7c1733

File tree

10 files changed

+84
-183
lines changed

10 files changed

+84
-183
lines changed

.github/CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ pnpm dev:tamagotchi
174174
> nr dev:tamagotchi
175175
> ```
176176
177+
If the command gets stuck, remove `cargo` component via `rustup` and re-install it.
178+
177179
### Stage Web (Browser version for [airi.moeru.ai](https://airi.moeru.ai))
178180
179181
```shell

apps/stage-tamagotchi/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"dev": "vite",
1313
"build": "vite build",
1414
"preview": "vite preview",
15-
"tauri": "tauri",
1615
"build:unpack": "tauri build --no-bundle",
1716
"rename-artifacts": "tsx scripts/rename-artifacts.ts",
1817
"name-of-artifacts": "tsx scripts/name-of-artifacts.ts"

apps/stage-tamagotchi/src-tauri/src/app/mod.rs

Lines changed: 0 additions & 2 deletions
This file was deleted.

apps/stage-tamagotchi/src-tauri/src/app/windows/chat.rs

Lines changed: 0 additions & 44 deletions
This file was deleted.

apps/stage-tamagotchi/src-tauri/src/app/windows/mod.rs

Lines changed: 0 additions & 3 deletions
This file was deleted.

apps/stage-tamagotchi/src-tauri/src/app/windows/onboarding.rs

Lines changed: 0 additions & 44 deletions
This file was deleted.

apps/stage-tamagotchi/src-tauri/src/app/windows/settings.rs

Lines changed: 0 additions & 44 deletions
This file was deleted.

apps/stage-tamagotchi/src-tauri/src/app/commands/mod.rs renamed to apps/stage-tamagotchi/src-tauri/src/commands/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use log::debug;
22
use tauri::Manager;
33

4-
use crate::app::windows::{chat, onboarding, settings};
5-
64
#[tauri::command]
75
pub async fn open_settings_window(app: tauri::AppHandle) -> Result<(), tauri::Error> {
86
let window = app.get_webview_window("settings");
@@ -11,7 +9,8 @@ pub async fn open_settings_window(app: tauri::AppHandle) -> Result<(), tauri::Er
119
return Ok(());
1210
}
1311

14-
settings::new_settings_window(&app, None)?;
12+
// Settings window should exist as it's declared in tauri.conf.json
13+
eprintln!("Settings window not found!");
1514
Ok(())
1615
}
1716

@@ -23,7 +22,8 @@ pub async fn open_chat_window(app: tauri::AppHandle) -> Result<(), tauri::Error>
2322
return Ok(());
2423
}
2524

26-
chat::new_chat_window(&app, None)?;
25+
// Chat window should exist as it's declared in tauri.conf.json
26+
eprintln!("Chat window not found!");
2727
Ok(())
2828
}
2929

@@ -35,7 +35,8 @@ pub async fn open_onboarding_window(app: tauri::AppHandle) -> Result<(), tauri::
3535
return Ok(());
3636
}
3737

38-
onboarding::new_onboarding_window(&app, None)?;
38+
// Onboarding window should exist as it's declared in tauri.conf.json
39+
eprintln!("Onboarding window not found!");
3940
Ok(())
4041
}
4142

apps/stage-tamagotchi/src-tauri/src/lib.rs

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use tauri::{
22
Emitter,
33
Manager,
4-
WebviewUrl,
5-
WebviewWindowBuilder,
64
menu::{Menu, MenuItem, Submenu},
75
tray::TrayIconBuilder,
86
};
@@ -11,9 +9,7 @@ use tauri_plugin_prevent_default::Flags;
119
use tauri_plugin_window_router_link::WindowMatcher;
1210
use tauri_plugin_window_state::{AppHandleExt, StateFlags};
1311

14-
mod app;
15-
16-
use app::windows::{chat, onboarding, settings};
12+
mod commands;
1713

1814
#[cfg_attr(mobile, tauri::mobile_entry_point)]
1915
pub fn run() {
@@ -36,44 +32,27 @@ pub fn run() {
3632
.plugin(tauri_plugin_rdev::init())
3733
.plugin(tauri_plugin_window_router_link::init(
3834
WindowMatcher::new()
39-
.register("chat", |app, on_page_load| {
40-
chat::new_chat_window(&app, on_page_load)
41-
.map_err(|e| e)
35+
.register("chat", |app, _| {
36+
Ok(app.get_webview_window("chat").unwrap())
4237
})
43-
.register("settings", |app, on_page_load| {
44-
settings::new_settings_window(&app, on_page_load)
45-
.map_err(|e| e)
38+
.register("settings", |app, _| {
39+
Ok(app.get_webview_window("settings").unwrap())
4640
})
47-
.register("onboarding", |app, on_page_load| {
48-
onboarding::new_onboarding_window(&app, on_page_load)
49-
.map_err(|e| e)
41+
.register("onboarding", |app, _| {
42+
Ok(app.get_webview_window("onboarding").unwrap())
5043
})
5144
))
5245
.setup(|app| {
53-
let mut builder = WebviewWindowBuilder::new(app, "main", WebviewUrl::default());
54-
55-
builder = builder.title("AIRI")
56-
.decorations(false)
57-
.inner_size(450.0, 600.0)
58-
.shadow(false)
59-
.transparent(true)
60-
.always_on_top(true);
61-
62-
#[cfg(target_os = "macos")]
63-
{
64-
builder = builder.title_bar_style(tauri::TitleBarStyle::Transparent);
65-
}
66-
67-
let window = builder.build().unwrap();
68-
#[cfg(debug_assertions)]
69-
window.open_devtools();
46+
// Main window is now created declaratively via tauri.conf.json
47+
let main_window = app.get_webview_window("main").unwrap();
7048

7149
#[cfg(target_os = "macos")]
7250
{
7351
app.set_activation_policy(tauri::ActivationPolicy::Accessory); // hide dock icon
7452
}
7553

7654
if cfg!(debug_assertions) {
55+
main_window.open_devtools();
7756
app.handle().plugin(
7857
tauri_plugin_log::Builder::default()
7958
.level(log::LevelFilter::Info)
@@ -133,8 +112,7 @@ pub fn run() {
133112
],
134113
)?;
135114

136-
#[cfg(debug_assertions)]
137-
{
115+
if cfg!(debug_assertions) {
138116
let show_devtools_item =
139117
MenuItem::with_id(app, "show-devtools", "Show Devtools", true, None::<&str>)?;
140118
menu.append_items(&[&show_devtools_item])?;
@@ -156,8 +134,8 @@ pub fn run() {
156134
let _ = window.show();
157135
return;
158136
}
159-
160-
app::windows::settings::new_settings_window(app, None).unwrap();
137+
// Settings window should exist as it's declared in tauri.conf.json
138+
eprintln!("Settings window not found!");
161139
}
162140
"window-mode.fade-on-hover" => {
163141
let window = app.get_webview_window("main");
@@ -226,10 +204,10 @@ pub fn run() {
226204
Ok(())
227205
})
228206
.invoke_handler(tauri::generate_handler![
229-
app::commands::open_settings_window,
230-
app::commands::open_chat_window,
231-
app::commands::open_onboarding_window,
232-
app::commands::debug_println,
207+
commands::open_settings_window,
208+
commands::open_chat_window,
209+
commands::open_onboarding_window,
210+
commands::debug_println,
233211
])
234212
.run(tauri::generate_context!())
235213
.expect("error while running tauri application");

apps/stage-tamagotchi/src-tauri/tauri.conf.json

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,65 @@
1313
"security": {
1414
"csp": null
1515
},
16-
"macOSPrivateApi": true
16+
"macOSPrivateApi": true,
17+
"windows": [
18+
{
19+
"label": "main",
20+
"title": "AIRI",
21+
"width": 450,
22+
"height": 600,
23+
"decorations": false,
24+
"transparent": true,
25+
"alwaysOnTop": true,
26+
"titleBarStyle": "Transparent",
27+
"minimizable": false
28+
},
29+
{
30+
"label": "chat",
31+
"title": "AIRI Chat",
32+
"url": "#/chat",
33+
"width": 600,
34+
"height": 800,
35+
"visible": false,
36+
"titleBarStyle": "Overlay",
37+
"hiddenTitle": true,
38+
"acceptFirstMouse": true,
39+
"trafficLightPosition": {
40+
"x": 14.0,
41+
"y": 20.0
42+
}
43+
},
44+
{
45+
"label": "settings",
46+
"title": "AIRI Settings",
47+
"url": "#/settings",
48+
"width": 550,
49+
"height": 900,
50+
"visible": false,
51+
"titleBarStyle": "Overlay",
52+
"hiddenTitle": true,
53+
"acceptFirstMouse": true,
54+
"trafficLightPosition": {
55+
"x": 14.0,
56+
"y": 20.0
57+
}
58+
},
59+
{
60+
"label": "onboarding",
61+
"title": "AIRI Onboarding",
62+
"url": "#/onboarding",
63+
"width": 800,
64+
"height": 600,
65+
"visible": false,
66+
"titleBarStyle": "Overlay",
67+
"hiddenTitle": true,
68+
"acceptFirstMouse": true,
69+
"trafficLightPosition": {
70+
"x": 14.0,
71+
"y": 20.0
72+
}
73+
}
74+
]
1775
},
1876
"bundle": {
1977
"active": true,

0 commit comments

Comments
 (0)