Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bundler): add TAURI_BUNDLER_TOOLS_GITHUB_MIRRORto specify a GitHub mirror #10866

Merged
merged 16 commits into from
Sep 11, 2024

Conversation

thep0y
Copy link
Contributor

@thep0y thep0y commented Sep 2, 2024

This feature is designed to facilitate the use of tauri for developers in Mainland China or other regions where GitHub is not accessible.

This commit introduces a feature that checks for the presence of an environment variable TAURI_BUNDLER_TOOLS_GITHUB_MIRROR before downloading the webview2 offline installer. If TAURI_BUNDLER_TOOLS_GITHUB_MIRROR is set, the download URL is rewritten to use a specified GitHub mirror, which can improve download speeds for users in regions where direct access to GitHub might be slow or unreliable. This change allows users to benefit from faster downloads without needing to configure proxy servers, particularly beneficial for those in mainland China where alternative mirrors are commonly used.

This commit helps resolve the issue encountered in #7338.

PowerShell:

$Env:TAURI_BUNDLER_TOOLS_GITHUB_MIRROR='https://mirror.ghproxy.com/'
bun run tauri build
pnpm run tauri build
npm run tauri build

…ler to support GitHub CDN

This commit introduces a feature that checks for the presence of an environment variable `GITHUB_CDN` before downloading the webview2 offline installer. If `GITHUB_CDN` is set, the download URL is rewritten to use a specified GitHub CDN, which can improve download speeds for users in regions where direct access to GitHub might be slow or unreliable. This change allows users to benefit from faster downloads without needing to configure proxy servers, particularly beneficial for those in mainland China where alternative CDNs are commonly used.
Copy link
Contributor

github-actions bot commented Sep 5, 2024

Package Changes Through 1c42375

There are 2 changes which include tauri-bundler with prerelease, tauri-cli with prerelease

Planned Package Versions

The following package releases are the planned based on the context of changes in this pull request.

package current next
tauri-bundler 2.0.1-rc.10 2.0.1-rc.11
@tauri-apps/cli 2.0.0-rc.13 2.0.0-rc.14
tauri-cli 2.0.0-rc.12 2.0.0-rc.13

Add another change file through the GitHub UI by following this link.


Read about change files or the docs at github.com/jbolda/covector

Copy link
Member

@amrbashir amrbashir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, could you also add a change file in .changes directory?

@@ -70,8 +70,20 @@ pub fn download_webview2_offline_installer(base_path: &Path, arch: &str) -> crat
pub fn download(url: &str) -> crate::Result<Vec<u8>> {
log::info!(action = "Downloading"; "{}", url);

let agent = ureq::AgentBuilder::new().try_proxy_from_env(true).build();
let response = agent.get(url).call().map_err(Box::new)?;
let (agent, url) = match std::env::var("GITHUB_CDN") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think GITHUB_CDN is a bit vague, maybe TAURI_BUNDLER_TOOLS_DOWNLOAD_HOST is better here. You also need to document that env var in crates/tauri-cli/ENVIRONEMENT_VARIABLES.md file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, tauri-bundler downloads files from GitHub, which is why the variable name GITHUB_CDN is used.

If future versions source downloads from other websites, the variable TAURI_BUNDLER_TOOLS_DOWNLOAD_HOST might cause confusion or errors. To avoid this, would it be more appropriate to rename it to TAURI_BUNDLER_TOOLS_DOWNLOAD_GITHUB_CDN or TAURI_BUNDLER_TOOLS_DOWNLOAD_GITHUB_TEMPLATE?

Or is it unlikely that future versions of tauri-bundler will download files from any site other than GitHub?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

webview2, which this pr is about, isn't downloaded from github though?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In accordance with internet regulations, users in mainland China are unable to directly download files from GitHub. A proxy is typically required. However, some users are not proficient in using proxies. Hence, I desire to add this feature—to facilitate file downloads from GitHub via public reverse proxy servers (CDN).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, i understood this. I am not against this PR/change. I'm just saying that the GITHUB_CDN variable is used here for files that are not downloaded from github but from microsoft.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand what you mean now, so I should add a source check, prioritizing CDN usage for files coming from GitHub, and for files from other source websites, downloading them based on try_proxy_from_env.

crates/tauri-bundler/src/bundle/windows/util.rs Outdated Show resolved Hide resolved
crates/tauri-bundler/src/bundle/windows/util.rs Outdated Show resolved Hide resolved
- Renamed the `GITHUB_CDN` environment variable to `TAURI_BUNDLER_TOOLS_DOWNLOAD_GITHUB_CDN` for clarity.
- Added error handling for URL parsing in the Windows-specific utility functions.
- Updated documentation to reflect the new environment variable.
- Extracted the creation of the HTTP agent and URL into a separate function `create_agent_and_url`.
- Ensured that the `TAURI_BUNDLER_TOOLS_DOWNLOAD_GITHUB_CDN` environment variable is used when downloading from GitHub CDN.
crates/tauri-bundler/src/error.rs Outdated Show resolved Hide resolved
crates/tauri-cli/ENVIRONMENT_VARIABLES.md Outdated Show resolved Hide resolved
.changes/bundler-github-cdn-from-env.md Outdated Show resolved Hide resolved
crates/tauri-bundler/src/bundle/windows/util.rs Outdated Show resolved Hide resolved
thep0y and others added 5 commits September 11, 2024 08:20
Co-authored-by: Amr Bashir <github@amrbashir.me>
Co-authored-by: Amr Bashir <github@amrbashir.me>
Co-authored-by: Amr Bashir <github@amrbashir.me>
Co-authored-by: Amr Bashir <github@amrbashir.me>
@thep0y thep0y changed the title feat(bundler): Use GitHub CDN for webview2 installer if available feat(bundler): Use GitHub mirror for webview2 installer if available Sep 11, 2024
@amrbashir amrbashir changed the title feat(bundler): Use GitHub mirror for webview2 installer if available feat(bundler): add TAURI_BUNDLER_TOOLS_GITHUB_MIRRORto specify a GitHub mirror Sep 11, 2024
@amrbashir amrbashir merged commit 6566182 into tauri-apps:dev Sep 11, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants