Skip to content

Commit

Permalink
🔥 Remove configuration menu settings
Browse files Browse the repository at this point in the history
  • Loading branch information
tw93 committed Apr 28, 2024
1 parent 7b94f5b commit 750efe9
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 282 deletions.
9 changes: 0 additions & 9 deletions bin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 0 additions & 8 deletions bin/README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,6 @@ Linux,默认为 `all`。
--user-agent <value>
```

#### [show-menu]

设置是否显示菜单栏,默认不显示。在 macOS 上推荐启用此选项。

```shell
--show-menu
```

#### [show-system-tray]

设置是否显示通知栏托盘,默认不显示。
Expand Down
1 change: 0 additions & 1 deletion bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion bin/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = {
resizable: true,
transparent: false,
userAgent: '',
showMenu: false,
showSystemTray: false,
multiArch: false,
targets: 'deb',
Expand Down
2 changes: 0 additions & 2 deletions bin/helpers/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export async function mergeConfig(url: string, options: PakeAppOptions, tauriCon
fullscreen,
transparent,
userAgent,
showMenu,
showSystemTray,
systemTrayIcon,
iterCopyFile,
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 0 additions & 3 deletions bin/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
39 changes: 15 additions & 24 deletions dist/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -153,7 +148,6 @@ var inject = [
var pakeConf = {
windows: windows,
user_agent: user_agent,
menu: menu,
system_tray: system_tray,
inject: inject
};
Expand All @@ -176,7 +170,7 @@ var tauri$3 = {
},
systemTray: {
iconPath: "png/icon_512.png",
iconAsTemplate: true
iconAsTemplate: false
},
allowlist: {
all: true,
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -831,7 +824,6 @@ const DEFAULT_PAKE_OPTIONS = {
resizable: true,
transparent: false,
userAgent: '',
showMenu: false,
showSystemTray: false,
multiArch: false,
targets: 'deb',
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 0 additions & 5 deletions src-tauri/pake.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 0 additions & 6 deletions src-tauri/src/app/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
104 changes: 10 additions & 94 deletions src-tauri/src/app/menu.rs
Original file line number Diff line number Diff line change
@@ -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};

Check warning on line 1 in src-tauri/src/app/menu.rs

View workflow job for this annotation

GitHub Actions / Enforce codebase style (cargo fmt)

Diff in /home/runner/work/Pake/Pake/src-tauri/src/app/menu.rs
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!");
// }
_ => {}
}
};
Expand Down
Loading

0 comments on commit 750efe9

Please sign in to comment.