🔥 Remove configuration menu settings

This commit is contained in:
Tw93
2024-04-28 17:47:12 +08:00
parent 7b94f5ba78
commit 750efe9bff
12 changed files with 26 additions and 282 deletions

9
bin/README.md vendored
View File

@@ -59,7 +59,6 @@ yarn cli:dev
The script will reads the above configuration and packages the specified `app` using `watch` mode, and changes to the `pake-cli` code and `pake` are hot updated in real time.
### CLI Usage
```bash
@@ -171,14 +170,6 @@ Customize the browser user agent. Default is empty.
--user-agent <value>
```
#### [show-menu]
Display the menu bar. Default is not to display. Use the following command to enable the menu bar. Recommended for macOS users.
```shell
--show-menu
```
#### [show-system-tray]
Display the system tray. Default is not to display. Use the following command to enable the system tray.

8
bin/README_CN.md vendored
View File

@@ -172,14 +172,6 @@ Linux默认为 `all`。
--user-agent <value>
```
#### [show-menu]
设置是否显示菜单栏,默认不显示。在 macOS 上推荐启用此选项。
```shell
--show-menu
```
#### [show-system-tray]
设置是否显示通知栏托盘,默认不显示。

1
bin/cli.ts vendored
View File

@@ -32,7 +32,6 @@ program
.option('--transparent', 'Only for Mac, hide title bar', DEFAULT.transparent)
.option('--fullscreen', 'Start in full screen', DEFAULT.fullscreen)
.option('--user-agent <string>', 'Custom user agent', DEFAULT.userAgent)
.option('--show-menu', 'Show menu in app', DEFAULT.showMenu)
.option('--show-system-tray', 'Show system tray in app', DEFAULT.showSystemTray)
.option('--system-tray-icon <string>', 'Custom system tray icon', DEFAULT.systemTrayIcon)
.option('--iter-copy-file', 'Copy files when URL is a local file', DEFAULT.iterCopyFile)

1
bin/defaults.ts vendored
View File

@@ -8,7 +8,6 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = {
resizable: true,
transparent: false,
userAgent: '',
showMenu: false,
showSystemTray: false,
multiArch: false,
targets: 'deb',

View File

@@ -14,7 +14,6 @@ export async function mergeConfig(url: string, options: PakeAppOptions, tauriCon
fullscreen,
transparent,
userAgent,
showMenu,
showSystemTray,
systemTrayIcon,
iterCopyFile,
@@ -103,7 +102,6 @@ export async function mergeConfig(url: string, options: PakeAppOptions, tauriCon
tauriConf.pake.user_agent[currentPlatform] = userAgent;
}
tauriConf.pake.menu[currentPlatform] = showMenu;
tauriConf.pake.system_tray[currentPlatform] = showSystemTray;
// Processing targets are currently only open to Linux.

3
bin/types.ts vendored
View File

@@ -27,9 +27,6 @@ export interface PakeCliOptions {
// Custom User-Agent, default off
userAgent: string;
// Enable menu bar, default on for macOS, off for Windows and Linux
showMenu: boolean;
// Enable system tray, default off for macOS, on for Windows and Linux
showSystemTray: boolean;

39
dist/cli.js vendored
View File

@@ -20,7 +20,7 @@ import psl from 'psl';
import isUrl from 'is-url';
var name = "pake-cli";
var version = "2.3.6";
var version = "2.3.7";
var description = "🤱🏻 Turn any webpage into a desktop app with Rust. 🤱🏻 利用 Rust 轻松构建轻量级多端桌面应用。";
var engines = {
node: ">=16.0.0"
@@ -67,15 +67,15 @@ var type = "module";
var exports = "./dist/pake.js";
var license = "MIT";
var dependencies = {
"@tauri-apps/api": "^1.5.1",
"@tauri-apps/cli": "^1.5.6",
axios: "^1.6.1",
"@tauri-apps/api": "^1.5.4",
"@tauri-apps/cli": "^1.5.12",
axios: "^1.6.8",
chalk: "^5.3.0",
commander: "^11.1.0",
"file-type": "^18.6.0",
"fs-extra": "^11.1.1",
"file-type": "^18.7.0",
"fs-extra": "^11.2.0",
"is-url": "^1.2.4",
loglevel: "^1.8.1",
loglevel: "^1.9.1",
ora: "^7.0.1",
prompts: "^2.4.2",
psl: "^1.9.0",
@@ -84,25 +84,25 @@ var dependencies = {
"update-notifier": "^7.0.0"
};
var devDependencies = {
"@rollup/plugin-alias": "^5.0.1",
"@rollup/plugin-alias": "^5.1.0",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-json": "^6.0.1",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-replace": "^5.0.5",
"@rollup/plugin-terser": "^0.4.4",
"@types/fs-extra": "^11.0.4",
"@types/is-url": "^1.2.32",
"@types/page-icon": "^0.3.6",
"@types/prompts": "^2.4.8",
"@types/prompts": "^2.4.9",
"@types/psl": "^1.1.3",
"@types/shelljs": "^0.8.15",
"@types/tmp": "^0.2.6",
"@types/update-notifier": "^6.0.7",
"@types/update-notifier": "^6.0.8",
"app-root-path": "^3.1.0",
"cross-env": "^7.0.3",
rollup: "^4.3.0",
rollup: "^4.17.0",
"rollup-plugin-typescript2": "^0.36.0",
tslib: "^2.6.2",
typescript: "^5.2.2"
typescript: "^5.4.5"
};
var packageJson = {
name: name,
@@ -138,11 +138,6 @@ var user_agent = {
linux: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36",
windows: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"
};
var menu = {
macos: false,
linux: false,
windows: false
};
var system_tray = {
macos: false,
linux: true,
@@ -153,7 +148,6 @@ var inject = [
var pakeConf = {
windows: windows,
user_agent: user_agent,
menu: menu,
system_tray: system_tray,
inject: inject
};
@@ -176,7 +170,7 @@ var tauri$3 = {
},
systemTray: {
iconPath: "png/icon_512.png",
iconAsTemplate: true
iconAsTemplate: false
},
allowlist: {
all: true,
@@ -476,7 +470,7 @@ async function combineFiles(files, output) {
}
async function mergeConfig(url, options, tauriConf) {
const { width, height, fullscreen, transparent, userAgent, showMenu, showSystemTray, systemTrayIcon, iterCopyFile, identifier, name, resizable = true, inject, safeDomain, } = options;
const { width, height, fullscreen, transparent, userAgent, showSystemTray, systemTrayIcon, iterCopyFile, identifier, name, resizable = true, inject, safeDomain, } = options;
const { platform } = process;
// Set Windows parameters.
const tauriConfWindowOptions = {
@@ -543,7 +537,6 @@ async function mergeConfig(url, options, tauriConf) {
if (userAgent.length > 0) {
tauriConf.pake.user_agent[currentPlatform] = userAgent;
}
tauriConf.pake.menu[currentPlatform] = showMenu;
tauriConf.pake.system_tray[currentPlatform] = showSystemTray;
// Processing targets are currently only open to Linux.
if (platform === 'linux') {
@@ -831,7 +824,6 @@ const DEFAULT_PAKE_OPTIONS = {
resizable: true,
transparent: false,
userAgent: '',
showMenu: false,
showSystemTray: false,
multiArch: false,
targets: 'deb',
@@ -1024,7 +1016,6 @@ program
.option('--transparent', 'Only for Mac, hide title bar', DEFAULT_PAKE_OPTIONS.transparent)
.option('--fullscreen', 'Start in full screen', DEFAULT_PAKE_OPTIONS.fullscreen)
.option('--user-agent <string>', 'Custom user agent', DEFAULT_PAKE_OPTIONS.userAgent)
.option('--show-menu', 'Show menu in app', DEFAULT_PAKE_OPTIONS.showMenu)
.option('--show-system-tray', 'Show system tray in app', DEFAULT_PAKE_OPTIONS.showSystemTray)
.option('--system-tray-icon <string>', 'Custom system tray icon', DEFAULT_PAKE_OPTIONS.systemTrayIcon)
.option('--iter-copy-file', 'Copy files when URL is a local file', DEFAULT_PAKE_OPTIONS.iterCopyFile)

View File

@@ -15,11 +15,6 @@
"linux": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36",
"windows": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"
},
"menu": {
"macos": false,
"linux": false,
"windows": false
},
"system_tray": {
"macos": false,
"linux": true,

View File

@@ -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()
}

View File

@@ -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!");
// }
_ => {}
}
};

View File

@@ -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');

View File

@@ -19,7 +19,7 @@
},
"systemTray": {
"iconPath": "png/icon_512.png",
"iconAsTemplate": true
"iconAsTemplate": false
},
"allowlist": {
"all": true,