From d4105725e486c46765723e215b851cfc862a48ab Mon Sep 17 00:00:00 2001 From: Bryan Lee <38807139+liby@users.noreply.github.com> Date: Sun, 23 Oct 2022 18:08:16 +0800 Subject: [PATCH] =?UTF-8?q?:technologist:=20=E5=B0=86=20JS=20=E5=92=8C=20C?= =?UTF-8?q?SS=20=E4=BB=A3=E7=A0=81=E6=8F=90=E5=8F=96=E5=88=B0=E5=8D=95?= =?UTF-8?q?=E7=8B=AC=E7=9A=84=E6=96=87=E4=BB=B6=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-tauri/src/main.rs | 103 +----------------------------------------- src-tauri/src/pake.js | 96 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 102 deletions(-) create mode 100644 src-tauri/src/pake.js diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 33d8380..8edf444 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -34,107 +34,6 @@ fn main() -> wry::Result<()> { menu_bar_menu.add_submenu("App", true, first_menu); - let script = r#" - (function () { - window.addEventListener('DOMContentLoaded', (event) => { - const style = document.createElement('style'); - style.innerHTML = ` - .panel.give_me .nav_view { - top: 154px !important; - } - - .columns .column #header{ - padding-top: 30px; - } - - #page .main_header { - padding-top: 20px; - } - - #page #footer-wrapper, - .drawing-board .toolbar .toolbar-action, - .c-swiper-container, - .download_entry, - .lang, .copyright { - display: none !important; - } - - .container-with-note #home, .container-with-note #switcher{ - top: 30px; - } - - .geist-page nav.dashboard_nav__PRmJv { - padding-top:10px; - } - - .geist-page .submenu button{ - margin-top:24px; - } - - #pack-top-dom:active { - cursor: grabbing; - cursor: -webkit-grabbing; - } - - #pack-top-dom{ - position:fixed; - background:transparent; - top:0; - width: 100%; - height: 20px; - cursor: move; - cursor: grab; - cursor: -webkit-grab; - } - `; - document.head.append(style); - const topDom = document.createElement("div"); - topDom.id = "pack-top-dom" - document.body.appendChild(topDom); - - const domEl = document.getElementById('pack-top-dom'); - - domEl.addEventListener('mousedown', (e) => { - if (e.buttons === 1 && e.detail !== 2) { - window.ipc.postMessage('drag_window'); - } - }) - - domEl.addEventListener('touchstart', (e) => { - window.ipc.postMessage('drag_window'); - }) - - domEl.addEventListener('dblclick', (e) => { - window.ipc.postMessage('fullscreen'); - }) - - document.addEventListener('keyup', function (event) { - if (event.key == "ArrowUp" && event.metaKey){ - scrollTo(0,0); - } - if (event.key == "ArrowDown" && event.metaKey){ - window.scrollTo(0, document.body.scrollHeight); - } - if (event.key == "[" && event.metaKey){ - window.history.go(-1); - } - if (event.key == "]" && event.metaKey){ - window.history.go(1); - } - if (event.key == "r" && event.metaKey){ - window.location.reload(); - } - }) - - const pakeLinks = document.links; - for (let linkIndex = 0; linkIndex < pakeLinks.length; linkIndex++) { - pakeLinks[linkIndex].target = '_self'; - } - - }); - })(); - "#; - let event_loop = EventLoop::new(); let window = WindowBuilder::new() .with_resizable(true) @@ -162,7 +61,7 @@ fn main() -> wry::Result<()> { let _webview = WebViewBuilder::new(window)? .with_url("https://hoppscotch.io/")? // .with_devtools(true) - .with_initialization_script(script) + .with_initialization_script(include_str!("pake.js")) .with_ipc_handler(handler) .build()?; diff --git a/src-tauri/src/pake.js b/src-tauri/src/pake.js new file mode 100644 index 0000000..cbd9fd8 --- /dev/null +++ b/src-tauri/src/pake.js @@ -0,0 +1,96 @@ +window.addEventListener('DOMContentLoaded', (_event) => { + const style = document.createElement('style'); + style.innerHTML = ` + .panel.give_me .nav_view { + top: 154px !important; + } + + .columns .column #header{ + padding-top: 30px; + } + + #page .main_header { + padding-top: 20px; + } + + #page #footer-wrapper, + .drawing-board .toolbar .toolbar-action, + .c-swiper-container, + .download_entry, + .lang, .copyright { + display: none !important; + } + + .container-with-note #home, .container-with-note #switcher{ + top: 30px; + } + + .geist-page nav.dashboard_nav__PRmJv { + padding-top:10px; + } + + .geist-page .submenu button{ + margin-top:24px; + } + + #pack-top-dom:active { + cursor: grabbing; + cursor: -webkit-grabbing; + } + + #pack-top-dom{ + position:fixed; + background:transparent; + top:0; + width: 100%; + height: 20px; + cursor: move; + cursor: grab; + cursor: -webkit-grab; + } + `; + document.head.append(style); + const topDom = document.createElement("div"); + topDom.id = "pack-top-dom" + document.body.appendChild(topDom); + + const domEl = document.getElementById('pack-top-dom'); + + domEl.addEventListener('mousedown', (e) => { + if (e.buttons === 1 && e.detail !== 2) { + window.ipc.postMessage('drag_window'); + } + }) + + domEl.addEventListener('touchstart', (e) => { + window.ipc.postMessage('drag_window'); + }) + + domEl.addEventListener('dblclick', (e) => { + window.ipc.postMessage('fullscreen'); + }) + + document.addEventListener('keyup', function (event) { + if (event.key === "ArrowUp" && event.metaKey){ + scrollTo(0,0); + } + if (event.key === "ArrowDown" && event.metaKey){ + window.scrollTo(0, document.body.scrollHeight); + } + if (event.key === "[" && event.metaKey){ + window.history.go(-1); + } + if (event.key === "]" && event.metaKey){ + window.history.go(1); + } + if (event.key === "r" && event.metaKey){ + window.location.reload(); + } + }) + + const pakeLinks = document.links; + for (let linkIndex = 0; linkIndex < pakeLinks.length; linkIndex++) { + pakeLinks[linkIndex].target = '_self'; + } + +}); \ No newline at end of file