Skip to content

Commit

Permalink
Remove log command and add log flag
Browse files Browse the repository at this point in the history
  • Loading branch information
enfipy committed Aug 4, 2022
1 parent 6b239ea commit df02215
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 49 deletions.
16 changes: 0 additions & 16 deletions crossbundle/cli/src/commands/log/android.rs

This file was deleted.

19 changes: 0 additions & 19 deletions crossbundle/cli/src/commands/log/mod.rs

This file was deleted.

5 changes: 0 additions & 5 deletions crossbundle/cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pub mod build;
pub mod install;
pub mod log;
pub mod new;
pub mod run;

Expand All @@ -20,9 +19,6 @@ pub enum Commands {
/// Creates a new Cargo package in the given directory. Project will be ready to build
/// with `crossbundle`
New(new::NewCommand),
/// Attach logger to device with running application
#[clap(subcommand)]
Log(log::LogCommand),
/// Installs bundletool and Android Studio's sdkmanager
#[clap(subcommand)]
Install(install::InstallCommand),
Expand All @@ -34,7 +30,6 @@ impl Commands {
Commands::Build(cmd) => cmd.handle_command(config),
Commands::Run(cmd) => cmd.handle_command(config),
Commands::New(cmd) => cmd.handle_command(config),
Commands::Log(cmd) => cmd.handle_command(config),
Commands::Install(cmd) => cmd.handle_command(config),
}
}
Expand Down
29 changes: 22 additions & 7 deletions crossbundle/cli/src/commands/run/android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ use crate::commands::build::{android::AndroidBuildCommand, BuildContext};
use crate::error::*;
use clap::Parser;
use crossbundle_tools::{
commands::android::{common::start_app, gradle::gradle_init, native::install_apk},
commands::android::{
common::{attach_logger_only_rust, start_app},
gradle::gradle_init,
native::install_apk,
},
error::CommandExt,
tools::{BuildApks, InstallApks},
types::AndroidStrategy,
Expand All @@ -13,6 +17,9 @@ use crossbundle_tools::{
pub struct AndroidRunCommand {
#[clap(flatten)]
pub build_command: AndroidBuildCommand,
/// Enable logging attach after run.
#[clap(long)]
pub log: bool,
}

impl AndroidRunCommand {
Expand Down Expand Up @@ -60,6 +67,10 @@ impl AndroidRunCommand {
&android_manifest.package,
"android.app.NativeActivity",
)?;
if self.log {
config.status("Attaching logger")?;
attach_logger_only_rust(&sdk)?;
}
config.status("Run finished successfully")?;
Ok(())
}
Expand All @@ -75,12 +86,16 @@ impl AndroidRunCommand {
&android_manifest.package,
"android.app.NativeActivity",
)?;
if self.log {
config.status("Attaching logger")?;
attach_logger_only_rust(&sdk)?;
}
config.status("Run finished successfully")?;
Ok(())
}

pub fn run_gradle_apk(&self, config: &Config, context: &BuildContext) -> Result<()> {
let (android_manifest, sdk, gradle_project_path) =
let (_, sdk, gradle_project_path) =
self.build_command
.build_gradle(config, context, &self.build_command.export_path)?;
config.status("Installing APK file on device")?;
Expand All @@ -91,11 +106,11 @@ impl AndroidRunCommand {
.arg(dunce::simplified(&gradle_project_path));
gradle.output_err(true)?;
config.status("Starting APK file")?;
start_app(
&sdk,
&android_manifest.package,
"com.crossbow.game.CrossbowApp",
)?;
start_app(&sdk, "com.crossbow.game", ".CrossbowApp")?;
if self.log {
config.status("Attaching logger")?;
attach_logger_only_rust(&sdk)?;
}
config.status("Run finished successfully")?;
Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ fn logcat_cmd(sdk: &AndroidSdk) -> Result<Command> {
pub fn attach_logger_only_rust(sdk: &AndroidSdk) -> Result<()> {
let mut adb = logcat_cmd(sdk)?;
adb.arg("RustStdoutStderr:D").arg("SAPP:D").arg("*:S");
adb.spawn()?;
adb.spawn()?.wait()?;
Ok(())
}
5 changes: 4 additions & 1 deletion examples/macroquad-permissions/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async fn main() -> anyhow::Result<()> {
clear_background(WHITE);

root_ui().push_skin(&window_skin);
root_ui().window(hash!(), vec2(0.0, 250.0), vec2(500.0, 500.0), |ui| {
root_ui().window(hash!(), vec2(0.0, 50.0), vec2(1000.0, 1000.0), |ui| {
#[cfg(target_os = "android")]
ui.label(vec2(15.0, 0.0), "AdMob");
ui.label(vec2(15.0, 50.0), &label);
Expand All @@ -72,7 +72,9 @@ async fn main() -> anyhow::Result<()> {
if ui.button(vec2(-15.0, 300.0), btn_camera) {
btn_clicked = btn_camera;
}
#[cfg(target_os = "ios")]
let btn_camera = "Photos permission";
#[cfg(target_os = "ios")]
if ui.button(vec2(-15.0, 450.0), btn_camera) {
btn_clicked = btn_camera;
}
Expand Down Expand Up @@ -109,6 +111,7 @@ async fn main() -> anyhow::Result<()> {
let res = Permission::Microphone.request_async().await?;
label = format!("Microphone {:?}", res);
}
#[cfg(target_os = "ios")]
"Photos permission" => {
let res = Permission::Photos.request_async().await?;
label = format!("Photos {:?}", res);
Expand Down

0 comments on commit df02215

Please sign in to comment.