Skip to content

Commit fb10b87

Browse files
feat: move app plugin back to core (#8039)
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
1 parent 1490567 commit fb10b87

File tree

20 files changed

+303
-207
lines changed

20 files changed

+303
-207
lines changed

.changes/api-app.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@tauri-apps/api": 'minor:feat'
3+
---
4+
5+
Add the `app` module back.

.changes/api-window.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"@tauri-apps/api": 'minor:feat'
33
---
44

5-
Add the `window` module back
5+
Add the `window` module back.

.changes/app-plugin-core.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'tauri': patch:changes
3+
---
4+
5+
Added the `app` plugin back into core.

.changes/window-plugin-core.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
"tauri": patch:changes
2+
'tauri': patch:changes
33
---
44

55
Added the `window` plugin back into core.

core/tauri/scripts/bundle.global.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/tauri/src/app.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ use crate::runtime::RuntimeHandle;
5656
#[cfg(target_os = "macos")]
5757
use crate::ActivationPolicy;
5858

59+
pub(crate) mod plugin;
60+
5961
#[cfg(desktop)]
6062
pub(crate) type GlobalMenuEventListener<T> = Box<dyn Fn(&T, crate::menu::MenuEvent) + Send + Sync>;
6163
#[cfg(all(desktop, feature = "tray-icon"))]
@@ -808,6 +810,7 @@ impl<R: Runtime> App<R> {
808810
self.handle.plugin(crate::path::init())?;
809811
self.handle.plugin(crate::event::init())?;
810812
self.handle.plugin(crate::window::plugin::init())?;
813+
self.handle.plugin(crate::app::plugin::init())?;
811814
Ok(())
812815
}
813816

core/tauri/src/app/plugin.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
2+
// SPDX-License-Identifier: Apache-2.0
3+
// SPDX-License-Identifier: MIT
4+
5+
use crate::{
6+
command,
7+
plugin::{Builder, TauriPlugin},
8+
AppHandle, Runtime,
9+
};
10+
11+
#[command(root = "crate")]
12+
pub fn version<R: Runtime>(app: AppHandle<R>) -> String {
13+
app.package_info().version.to_string()
14+
}
15+
16+
#[command(root = "crate")]
17+
pub fn name<R: Runtime>(app: AppHandle<R>) -> String {
18+
app.package_info().name.clone()
19+
}
20+
21+
#[command(root = "crate")]
22+
pub fn tauri_version() -> &'static str {
23+
crate::VERSION
24+
}
25+
26+
#[command(root = "crate")]
27+
#[allow(unused_variables)]
28+
pub fn app_show<R: Runtime>(app: AppHandle<R>) -> crate::Result<()> {
29+
#[cfg(target_os = "macos")]
30+
app.show()?;
31+
Ok(())
32+
}
33+
34+
#[command(root = "crate")]
35+
#[allow(unused_variables)]
36+
pub fn app_hide<R: Runtime>(app: AppHandle<R>) -> crate::Result<()> {
37+
#[cfg(target_os = "macos")]
38+
app.hide()?;
39+
Ok(())
40+
}
41+
42+
pub fn init<R: Runtime>() -> TauriPlugin<R> {
43+
Builder::new("app")
44+
.invoke_handler(crate::generate_handler![
45+
version,
46+
name,
47+
tauri_version,
48+
app_show,
49+
app_hide
50+
])
51+
.build()
52+
}

core/tauri/src/window/scripts/drag.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
// SPDX-License-Identifier: Apache-2.0
33
// SPDX-License-Identifier: MIT
44

5-
document.addEventListener("mousedown", (e) => {
6-
if (e.target.hasAttribute("data-tauri-drag-region") && e.button === 0) {
5+
document.addEventListener('mousedown', (e) => {
6+
if (e.target.hasAttribute('data-tauri-drag-region') && e.button === 0) {
77
// prevents text cursor
8-
e.preventDefault();
8+
e.preventDefault()
99
// fix #2549: double click on drag region edge causes content to maximize without window sizing change
1010
// https://github.com/tauri-apps/tauri/issues/2549#issuecomment-1250036908
11-
e.stopImmediatePropagation();
11+
e.stopImmediatePropagation()
1212

1313
// start dragging if the element has a `tauri-drag-region` data attribute and maximize on double-clicking it
14-
const cmd = e.detail === 2 ? "internal_toggle_maximize" : "start_dragging";
15-
window.__TAURI_INVOKE__("plugin:window|" + cmd);
14+
const cmd = e.detail === 2 ? 'internal_toggle_maximize' : 'start_dragging'
15+
window.__TAURI_INTERNALS__.invoke('plugin:window|' + cmd)
1616
}
17-
});
17+
})

core/tauri/src/window/scripts/print.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
// SPDX-License-Identifier: MIT
44

55
window.print = function () {
6-
return window.__TAURI_INVOKE__("plugin:window|print");
7-
};
6+
return window.__TAURI_INTERNALS__.invoke('plugin:window|print')
7+
}

core/tauri/src/window/scripts/toggle-devtools.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

1414
document.addEventListener('keydown', (event) => {
1515
if (isHotkey(event)) {
16-
window.__TAURI_INVOKE__('plugin:window|internal_toggle_devtools')
16+
window.__TAURI_INTERNALS__.invoke(
17+
'plugin:window|internal_toggle_devtools'
18+
)
1719
}
1820
})
1921
}

0 commit comments

Comments
 (0)