🔥 Remove configuration menu settings
This commit is contained in:
@@ -47,16 +47,10 @@ pub type FunctionON = PlatformSpecific<bool>;
|
||||
pub struct PakeConfig {
|
||||
pub windows: Vec<WindowConfig>,
|
||||
pub user_agent: UserAgent,
|
||||
pub menu: FunctionON,
|
||||
pub system_tray: FunctionON,
|
||||
}
|
||||
|
||||
impl PakeConfig {
|
||||
pub fn show_menu(&self) -> bool {
|
||||
self.menu.copied()
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
pub fn show_system_tray(&self) -> bool {
|
||||
self.system_tray.copied()
|
||||
}
|
||||
|
||||
@@ -1,114 +1,30 @@
|
||||
use tauri::MenuItem;
|
||||
|
||||
use tauri::{CustomMenuItem, Menu, Submenu, WindowMenuEvent};
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
||||
use tauri::{Manager, SystemTray, SystemTrayEvent, SystemTrayMenu};
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
||||
use tauri::{CustomMenuItem,Manager, SystemTray, SystemTrayEvent, SystemTrayMenu};
|
||||
use tauri_plugin_window_state::{AppHandleExt, StateFlags};
|
||||
|
||||
pub fn get_menu() -> Menu {
|
||||
let close = CustomMenuItem::new("close".to_string(), "Close Window").accelerator("CmdOrCtrl+W");
|
||||
let goto_url_item = CustomMenuItem::new("goto_url".to_string(), "Go to URL...")
|
||||
.accelerator("CmdOrCtrl+Shift+L");
|
||||
let first_menu = Menu::new()
|
||||
.add_native_item(MenuItem::Copy)
|
||||
.add_native_item(MenuItem::Cut)
|
||||
.add_native_item(MenuItem::Paste)
|
||||
.add_native_item(MenuItem::Undo)
|
||||
.add_native_item(MenuItem::Redo)
|
||||
.add_native_item(MenuItem::SelectAll)
|
||||
.add_native_item(MenuItem::Separator)
|
||||
.add_item(goto_url_item)
|
||||
.add_native_item(MenuItem::Separator)
|
||||
.add_native_item(MenuItem::EnterFullScreen)
|
||||
.add_native_item(MenuItem::Minimize)
|
||||
.add_native_item(MenuItem::Hide)
|
||||
.add_native_item(MenuItem::HideOthers)
|
||||
.add_native_item(MenuItem::ShowAll)
|
||||
.add_native_item(MenuItem::Separator)
|
||||
.add_item(close)
|
||||
.add_native_item(MenuItem::Quit);
|
||||
|
||||
let app_menu = Submenu::new("File", first_menu);
|
||||
Menu::new().add_submenu(app_menu)
|
||||
}
|
||||
|
||||
pub fn menu_event_handle(event: WindowMenuEvent) {
|
||||
if event.menu_item_id() == "close" {
|
||||
event.window().minimize().expect("can't minimize window");
|
||||
}
|
||||
|
||||
if event.menu_item_id() == "goto_url" {
|
||||
let js_code = "showUrlModal();";
|
||||
event.window().eval(js_code).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
||||
pub fn get_system_tray(show_menu: bool) -> SystemTray {
|
||||
let hide_app = CustomMenuItem::new("hide_app".to_string(), "Hide App");
|
||||
let show_app = CustomMenuItem::new("show_app".to_string(), "Show App");
|
||||
pub fn get_system_tray() -> SystemTray {
|
||||
let hide_app = CustomMenuItem::new("hide_app".to_string(), "Hide");
|
||||
let show_app = CustomMenuItem::new("show_app".to_string(), "Show");
|
||||
let quit = CustomMenuItem::new("quit".to_string(), "Quit");
|
||||
let about = CustomMenuItem::new("about".to_string(), "About");
|
||||
let tray_menu = SystemTrayMenu::new().add_item(hide_app).add_item(show_app);
|
||||
if show_menu {
|
||||
let hide_menu = CustomMenuItem::new("hide_menu".to_string(), "Hide Menu");
|
||||
let show_menu = CustomMenuItem::new("show_menu".to_string(), "Show Menu");
|
||||
let tray_menu = tray_menu
|
||||
.add_item(hide_menu)
|
||||
.add_item(show_menu)
|
||||
.add_item(quit)
|
||||
.add_item(about);
|
||||
SystemTray::new().with_menu(tray_menu)
|
||||
} else {
|
||||
let tray_menu = tray_menu.add_item(quit).add_item(about);
|
||||
SystemTray::new().with_menu(tray_menu)
|
||||
}
|
||||
let tray_menu = SystemTrayMenu::new()
|
||||
.add_item(show_app)
|
||||
.add_item(hide_app)
|
||||
.add_item(quit);
|
||||
SystemTray::new().with_menu(tray_menu)
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
||||
pub fn system_tray_handle(app: &tauri::AppHandle, event: SystemTrayEvent) {
|
||||
if let SystemTrayEvent::MenuItemClick { tray_id: _, id, .. } = event {
|
||||
match id.as_str() {
|
||||
"hide_app" => {
|
||||
app.get_window("pake").unwrap().hide().unwrap();
|
||||
app.get_window("pake").unwrap().minimize().unwrap();
|
||||
}
|
||||
"show_app" => {
|
||||
app.get_window("pake").unwrap().show().unwrap();
|
||||
}
|
||||
"hide_menu" => {
|
||||
app.get_window("pake")
|
||||
.unwrap()
|
||||
.menu_handle()
|
||||
.hide()
|
||||
.unwrap();
|
||||
}
|
||||
"show_menu" => {
|
||||
app.get_window("pake")
|
||||
.unwrap()
|
||||
.menu_handle()
|
||||
.show()
|
||||
.unwrap();
|
||||
}
|
||||
"quit" => {
|
||||
let _res = app.save_window_state(StateFlags::all());
|
||||
std::process::exit(0);
|
||||
}
|
||||
// ignore about for now, because about_pake.html have be erased.
|
||||
// "about" => {
|
||||
// let _about_window = WindowBuilder::new(
|
||||
// app,
|
||||
// "about",
|
||||
// WindowUrl::App(std::path::PathBuf::from("about_pake.html")),
|
||||
// )
|
||||
// .resizable(true)
|
||||
// .title("About")
|
||||
// .inner_size(600.0, 400.0)
|
||||
// .build()
|
||||
// .expect("can't open about!");
|
||||
// }
|
||||
_ => {}
|
||||
}
|
||||
};
|
||||
|
||||
128
src-tauri/src/inject/component.js
vendored
128
src-tauri/src/inject/component.js
vendored
@@ -1,132 +1,4 @@
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
// Create a modal
|
||||
const modalHtml = `
|
||||
<div id="pakeUrlModal" class="pake-modal">
|
||||
<div class="pake-modal-container">
|
||||
<div class="pake-modal-content">
|
||||
<label for="pakeUrlInput">Enter URL to navigate anywhere</label>
|
||||
<input type="text" id="pakeUrlInput" />
|
||||
<button id="pakeUrlSubmit">Submit</button>
|
||||
<button id="pakeUrlClose">Close</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
const modalStyle = `
|
||||
.pake-modal {
|
||||
display: none;
|
||||
position: fixed;
|
||||
z-index: 1000;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: rgba(0, 0, 0, 0.4);
|
||||
}
|
||||
|
||||
.pake-modal-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.pake-modal-content {
|
||||
background-color: #fff;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
width: 80%;
|
||||
max-width: 400px;
|
||||
font-size:14px;
|
||||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1), 0 1px 3px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
.pake-modal-content label {
|
||||
display: block;
|
||||
color: #11182B;
|
||||
margin-bottom: 12px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.pake-modal-content input[type="text"] {
|
||||
width: 90%;
|
||||
padding: 8px;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 4px;
|
||||
font-size: 14px;
|
||||
margin-bottom: 12px;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.pake-modal-content button {
|
||||
background: #11182B;
|
||||
color: #FFF;
|
||||
padding: 6px 14px;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
margin-right: 4px;
|
||||
font-size:14px;
|
||||
border: 1px solid #11182B;
|
||||
}
|
||||
|
||||
#pakeUrlClose{
|
||||
background: #fff;
|
||||
color: #11182B;
|
||||
}
|
||||
|
||||
#pakeUrlInput {
|
||||
min-width: 320px;
|
||||
text-align: left;
|
||||
min-height: 30px;
|
||||
}
|
||||
`;
|
||||
|
||||
const modalDiv = document.createElement('div');
|
||||
modalDiv.innerHTML = modalHtml;
|
||||
document.body.appendChild(modalDiv);
|
||||
|
||||
const modalStyleElement = document.createElement('style');
|
||||
modalStyleElement.innerText = modalStyle;
|
||||
document.head.appendChild(modalStyleElement);
|
||||
|
||||
const urlModal = document.getElementById('pakeUrlModal');
|
||||
const urlInput = document.getElementById('pakeUrlInput');
|
||||
const urlSubmit = document.getElementById('pakeUrlSubmit');
|
||||
const urlClose = document.getElementById('pakeUrlClose');
|
||||
|
||||
urlSubmit.onclick = function() {
|
||||
const url = urlInput.value;
|
||||
if (url) {
|
||||
window.location.href = url;
|
||||
}
|
||||
};
|
||||
|
||||
urlClose.onclick = function() {
|
||||
urlModal.style.display = 'none';
|
||||
};
|
||||
|
||||
urlInput.addEventListener('keydown', function(event) {
|
||||
if (event.key === 'Enter') {
|
||||
const url = urlInput.value;
|
||||
if (url) {
|
||||
window.location.href = url;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener('keydown', function(event) {
|
||||
if (event.key === 'Escape' && urlModal.style.display === 'block') {
|
||||
urlModal.style.display = 'none';
|
||||
}
|
||||
});
|
||||
|
||||
window.showUrlModal = function() {
|
||||
urlModal.style.display = 'block';
|
||||
urlInput.focus();
|
||||
};
|
||||
|
||||
// Toast
|
||||
function pakeToast(msg) {
|
||||
const m = document.createElement('div');
|
||||
|
||||
Reference in New Issue
Block a user