mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-12-14 21:21:44 +03:00
feat(android): enable dev HMR in both HTTP and HTTPS dev servers (#5033)
This commit is contained in:
parent
752ad3b203
commit
4a5f2ec1ae
@ -847,7 +847,10 @@ impl<R: Runtime> WindowManager<R> {
|
||||
let mut response = {
|
||||
let mut url = url.clone();
|
||||
url.set_path(&path);
|
||||
match attohttpc::get(url.as_str()).send() {
|
||||
match attohttpc::get(url.as_str())
|
||||
.danger_accept_invalid_certs(true)
|
||||
.send()
|
||||
{
|
||||
Ok(r) => {
|
||||
for (name, value) in r.headers() {
|
||||
builder = builder.header(name, value);
|
||||
|
2
examples/api/src-tauri/Cargo.lock
generated
2
examples/api/src-tauri/Cargo.lock
generated
@ -4222,7 +4222,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "wry"
|
||||
version = "0.20.2"
|
||||
source = "git+https://github.com/tauri-apps/wry?branch=dev#b4789034dc4d10ab83f6acce6b4152d79f702940"
|
||||
source = "git+https://github.com/tauri-apps/wry?branch=dev#b1e8560c3f13f2674528f6ca440ba476ddbef7c2"
|
||||
dependencies = [
|
||||
"block",
|
||||
"cocoa",
|
||||
|
@ -21,6 +21,7 @@ export default defineConfig(async ({ command, mode }) => {
|
||||
port: 5173,
|
||||
strictPort: true,
|
||||
hmr: {
|
||||
protocol: 'ws',
|
||||
host,
|
||||
port: 5183
|
||||
},
|
||||
|
@ -113,6 +113,14 @@ fn env() -> Result<Env, Error> {
|
||||
cargo_mobile::android::env::Env::from_env(env).map_err(Error::AndroidEnvInitFailed)
|
||||
}
|
||||
|
||||
fn delete_codegen_vars() {
|
||||
for (k, _) in std::env::vars() {
|
||||
if k.starts_with("WRY_") && (k.ends_with("CLASS_EXTENSION") || k.ends_with("CLASS_INIT")) {
|
||||
std::env::remove_var(k);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn device_prompt<'a>(env: &'_ Env) -> Result<Device<'a>, PromptError<adb::device_list::Error>> {
|
||||
let device_list =
|
||||
adb::device_list(env).map_err(|cause| PromptError::detection_failed("Android", cause))?;
|
||||
|
@ -1,4 +1,7 @@
|
||||
use super::{ensure_init, env, init_dot_cargo, log_finished, with_config, Error, MobileTarget};
|
||||
use super::{
|
||||
delete_codegen_vars, ensure_init, env, init_dot_cargo, log_finished, with_config, Error,
|
||||
MobileTarget,
|
||||
};
|
||||
use crate::{
|
||||
helpers::{config::get as get_tauri_config, flock},
|
||||
interface::{AppSettings, Interface, Options as InterfaceOptions},
|
||||
@ -13,6 +16,8 @@ use cargo_mobile::{
|
||||
target::TargetTrait,
|
||||
};
|
||||
|
||||
use std::env::set_var;
|
||||
|
||||
#[derive(Debug, Clone, Parser)]
|
||||
#[clap(about = "Android build")]
|
||||
pub struct Options {
|
||||
@ -60,7 +65,11 @@ impl From<Options> for crate::build::Options {
|
||||
}
|
||||
|
||||
pub fn command(options: Options) -> Result<()> {
|
||||
delete_codegen_vars();
|
||||
with_config(|root_conf, config, _metadata| {
|
||||
set_var("WRY_RUSTWEBVIEWCLIENT_CLASS_EXTENSION", "");
|
||||
set_var("WRY_RUSTWEBVIEW_CLASS_INIT", "");
|
||||
|
||||
ensure_init(config.project_dir(), MobileTarget::Android)
|
||||
.map_err(|e| Error::ProjectNotInitialized(e.to_string()))?;
|
||||
|
||||
|
@ -1,4 +1,7 @@
|
||||
use super::{device_prompt, ensure_init, env, init_dot_cargo, with_config, Error, MobileTarget};
|
||||
use super::{
|
||||
delete_codegen_vars, device_prompt, ensure_init, env, init_dot_cargo, with_config, Error,
|
||||
MobileTarget,
|
||||
};
|
||||
use crate::{
|
||||
helpers::{config::get as get_tauri_config, flock},
|
||||
interface::{AppSettings, Interface, MobileOptions, Options as InterfaceOptions},
|
||||
@ -14,6 +17,17 @@ use cargo_mobile::{
|
||||
os,
|
||||
};
|
||||
|
||||
use std::env::set_var;
|
||||
|
||||
const WEBVIEW_CLIENT_CLASS_EXTENSION: &str = "
|
||||
@android.annotation.SuppressLint(\"WebViewClientOnReceivedSslError\")
|
||||
override fun onReceivedSslError(view: WebView?, handler: SslErrorHandler, error: android.net.http.SslError) {
|
||||
handler.proceed()
|
||||
}
|
||||
";
|
||||
const WEBVIEW_CLASS_INIT: &str =
|
||||
"this.settings.mixedContentMode = android.webkit.WebSettings.MIXED_CONTENT_ALWAYS_ALLOW";
|
||||
|
||||
#[derive(Debug, Clone, Parser)]
|
||||
#[clap(about = "Android dev")]
|
||||
pub struct Options {
|
||||
@ -50,7 +64,13 @@ impl From<Options> for crate::dev::Options {
|
||||
}
|
||||
|
||||
pub fn command(options: Options) -> Result<()> {
|
||||
delete_codegen_vars();
|
||||
with_config(|root_conf, config, metadata| {
|
||||
set_var(
|
||||
"WRY_RUSTWEBVIEWCLIENT_CLASS_EXTENSION",
|
||||
WEBVIEW_CLIENT_CLASS_EXTENSION,
|
||||
);
|
||||
set_var("WRY_RUSTWEBVIEW_CLASS_INIT", WEBVIEW_CLASS_INIT);
|
||||
ensure_init(config.project_dir(), MobileTarget::Android)
|
||||
.map_err(|e| Error::ProjectNotInitialized(e.to_string()))?;
|
||||
run_dev(options, root_conf, config, metadata).map_err(|e| Error::DevFailed(format!("{:#}", e)))
|
||||
|
@ -9,6 +9,7 @@ plugins {
|
||||
android {
|
||||
compileSdk = 33
|
||||
defaultConfig {
|
||||
manifestPlaceholders["usesCleartextTraffic"] = "false"
|
||||
applicationId = "{{reverse-domain app.domain}}.{{snake-case app.name}}"
|
||||
minSdk = {{android.min-sdk-version}}
|
||||
targetSdk = 33
|
||||
@ -23,6 +24,7 @@ android {
|
||||
}
|
||||
buildTypes {
|
||||
getByName("debug") {
|
||||
manifestPlaceholders["usesCleartextTraffic"] = "true"
|
||||
isDebuggable = true
|
||||
isJniDebuggable = true
|
||||
isMinifyEnabled = false
|
||||
|
@ -5,7 +5,8 @@
|
||||
<application
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/Theme.{{snake-case app.name}}">
|
||||
android:theme="@style/Theme.{{snake-case app.name}}"
|
||||
android:usesCleartextTraffic="${usesCleartextTraffic}">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true">
|
||||
|
Loading…
Reference in New Issue
Block a user