Skip to content

Commit

Permalink
refactor: support proxy option
Browse files Browse the repository at this point in the history
  • Loading branch information
jeasonnow committed Jul 30, 2024
1 parent a631e11 commit 5752996
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ program
.option('--multi-arch', 'Only for Mac, supports both Intel and M1', DEFAULT.multiArch)
.option('--inject [injects...]', 'Injection of .js or .css Files', DEFAULT.inject)
.option('--debug', 'Debug build and more output', DEFAULT.debug)
.option('--proxy-url', "Proxy URL", DEFAULT.proxyUrl)
.addOption(new Option('--user-agent <string>', 'Custom user agent').default(DEFAULT.userAgent).hideHelp())
.addOption(
new Option('--targets <string>', 'Only for Linux, option "deb" or "appimage"').default(DEFAULT.targets).hideHelp(),
Expand Down
1 change: 1 addition & 0 deletions bin/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = {
targets: 'deb',
useLocalFile: false,
systemTrayIcon: '',
proxyUrl: "",
debug: false,
inject: [],
safeDomain: [],
Expand Down
3 changes: 3 additions & 0 deletions bin/helpers/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export async function mergeConfig(url: string, options: PakeAppOptions, tauriCon
name,
resizable = true,
inject,
proxyUrl,
} = options;

const { platform } = process;
Expand Down Expand Up @@ -189,6 +190,8 @@ export async function mergeConfig(url: string, options: PakeAppOptions, tauriCon
await fsExtra.writeFile(injectFilePath, '');
}

tauriConf.pake.proxy_url = proxyUrl || "";

// Save config file.
const platformConfigPaths: PlatformMap = {
win32: 'tauri.windows.conf.json',
Expand Down
3 changes: 3 additions & 0 deletions bin/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ export interface PakeCliOptions {

/* the domain that can use ipc or tauri javascript sdk */
safeDomain: string[];

// Proxy
proxyUrl: string;
}

export interface PakeAppOptions extends PakeCliOptions {
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ tauri-build = { version = "2.0.0-beta", features = [] }
[dependencies]
serde_json = "1.0.116"
serde = { version = "1.0.200", features = ["derive"] }
tauri = { version = "2.0.0-beta.25", features = ["tray-icon", "image-ico", "image-png"] }
tauri = { version = "2.0.0-beta.25", features = ["tray-icon", "image-ico", "image-png", "macos-proxy"] }
tauri-plugin-window-state = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
tauri-plugin-oauth = { git = "https://github.com/FabianLars/tauri-plugin-oauth", branch = "v2" }
tauri-plugin-clipboard-manager = "2.1.0-beta.6"
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/app/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub struct PakeConfig {
pub user_agent: UserAgent,

Check warning on line 52 in src-tauri/src/app/config.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/config.rs
pub system_tray: FunctionON,
pub system_tray_path: String,
pub proxy_url: String
}

impl PakeConfig {
Expand Down
9 changes: 7 additions & 2 deletions src-tauri/src/app/window.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::app::config::PakeConfig;
use std::path::PathBuf;
use tauri::{App, WebviewUrl, WebviewWindow, WebviewWindowBuilder};
use std::{path::PathBuf, str::FromStr};
use tauri::{App, Url, WebviewUrl, WebviewWindow, WebviewWindowBuilder};

#[cfg(target_os = "macos")]
use tauri::TitleBarStyle;
Expand Down Expand Up @@ -40,6 +40,11 @@ pub fn get_window(app: &mut App, config: &PakeConfig, _data_dir: PathBuf) -> Web
//This is necessary to allow for file injection by external developers for customization purposes.
.initialization_script(include_str!("../inject/custom.js"));

Check warning on line 42 in src-tauri/src/app/window.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/window.rs
if config.proxy_url != "" {
println!("{}", &config.proxy_url);
window_builder = window_builder.proxy_url(Url::from_str(&config.proxy_url.as_str()).unwrap());
}

#[cfg(target_os = "macos")]
{
let title_bar_style = if window_config.hide_title_bar {
Expand Down

0 comments on commit 5752996

Please sign in to comment.