refactor(core): remove init scripts related to plugin APIs (#6975)

This commit is contained in:
Lucas Fernandes Nogueira 2023-05-16 07:46:32 -07:00 committed by GitHub
parent 59db76af4c
commit e5bd34cb34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 1 additions and 166 deletions

View File

@ -85,73 +85,4 @@
}
})
}
// open <a href="..."> links with the Tauri API
function __openLinks() {
document.querySelector('body').addEventListener(
'click',
function (e) {
var target = e.target
while (target != null) {
if (target.matches('a')) {
if (
target.href &&
(['http://', 'https://', 'mailto:', 'tel:'].some(v => target.href.startsWith(v))) &&
target.target === '_blank'
) {
window.__TAURI_INVOKE__('tauri', {
__tauriModule: 'Shell',
message: {
cmd: 'open',
path: target.href
}
})
e.preventDefault()
}
break
}
target = target.parentElement
}
}
)
}
if (
document.readyState === 'complete' ||
document.readyState === 'interactive'
) {
__openLinks()
} else {
window.addEventListener(
'DOMContentLoaded',
function () {
__openLinks()
},
true
)
}
// drag region
document.addEventListener('mousedown', (e) => {
if (e.target.hasAttribute('data-tauri-drag-region') && e.buttons === 1) {
// prevents text cursor
e.preventDefault()
// fix #2549: double click on drag region edge causes content to maximize without window sizing change
// https://github.com/tauri-apps/tauri/issues/2549#issuecomment-1250036908
e.stopImmediatePropagation()
// start dragging if the element has a `tauri-drag-region` data attribute and maximize on double-clicking it
window.__TAURI_INVOKE__('tauri', {
__tauriModule: 'Window',
message: {
cmd: 'manage',
data: {
cmd: {
type: e.detail === 2 ? '__toggleMaximize' : 'startDragging'
}
}
}
})
}
})
})()

View File

@ -5,10 +5,6 @@
; (function () {
__RAW_freeze_prototype__
; (function () {
__RAW_hotkeys__
})()
__RAW_pattern_script__
__RAW_ipc_script__
@ -20,11 +16,7 @@
__RAW_core_script__
__RAW_window_dialogs_script__
__RAW_window_print_script__
__RAW_event_initialization_script__
__RAW_event_initialization_script__
if (window.ipc) {
window.__TAURI_INVOKE__('__initialized', { url: window.location.href })

View File

@ -1,23 +0,0 @@
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
window.alert = function (message) {
window.__TAURI_INVOKE__('tauri', {
__tauriModule: 'Dialog',
message: {
cmd: 'messageDialog',
message: message.toString()
}
})
}
window.confirm = function (message) {
return window.__TAURI_INVOKE__('tauri', {
__tauriModule: 'Dialog',
message: {
cmd: 'confirmDialog',
message: message.toString()
}
})
}

View File

@ -1,17 +0,0 @@
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
window.print = function () {
return window.__TAURI_INVOKE__('tauri', {
__tauriModule: 'Window',
message: {
cmd: 'manage',
data: {
cmd: {
type: 'print'
}
}
}
})
}

View File

@ -1025,17 +1025,11 @@ impl<R: Runtime> WindowManager<R> {
#[raw]
core_script: &'a str,
#[raw]
window_dialogs_script: &'a str,
#[raw]
window_print_script: &'a str,
#[raw]
event_initialization_script: &'a str,
#[raw]
plugin_initialization_script: &'a str,
#[raw]
freeze_prototype: &'a str,
#[raw]
hotkeys: &'a str,
}
let bundle_script = if with_global_tauri {
@ -1050,34 +1044,6 @@ impl<R: Runtime> WindowManager<R> {
""
};
#[cfg(any(debug_assertions, feature = "devtools"))]
let hotkeys = &format!(
"
{};
window.hotkeys('{}', () => {{
window.__TAURI_INVOKE__('tauri', {{
__tauriModule: 'Window',
message: {{
cmd: 'manage',
data: {{
cmd: {{
type: '__toggleDevtools'
}}
}}
}}
}});
}});
",
include_str!("../scripts/hotkey.js"),
if cfg!(target_os = "macos") {
"command+option+i"
} else {
"ctrl+shift+i"
}
);
#[cfg(not(any(debug_assertions, feature = "devtools")))]
let hotkeys = "";
InitJavascript {
pattern_script,
ipc_script,
@ -1093,23 +1059,9 @@ impl<R: Runtime> WindowManager<R> {
)
),
core_script: include_str!("../scripts/core.js"),
// window.print works on Linux/Windows; need to use the API on macOS
#[cfg(any(target_os = "macos", target_os = "ios"))]
window_print_script: include_str!("../scripts/window_print.js"),
#[cfg(not(any(target_os = "macos", target_os = "ios")))]
window_print_script: "",
// dialogs are implemented natively on Android
#[cfg(not(target_os = "android"))]
window_dialogs_script: include_str!("../scripts/window_dialogs.js"),
#[cfg(target_os = "android")]
window_dialogs_script: "",
event_initialization_script: &self.event_initialization_script(),
plugin_initialization_script,
freeze_prototype,
hotkeys,
}
.render_default(&Default::default())
.map(|s| s.into_string())