Skip to content

Commit

Permalink
feat: 移除自定义panic处理器
Browse files Browse the repository at this point in the history
  • Loading branch information
shadow3aaa committed May 25, 2024
1 parent 8f76068 commit fd9d65c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 36 deletions.
5 changes: 2 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ mod misc;
use std::{
env, fs,
io::{self, prelude::*},
panic, process,
process,
};

use framework::prelude::*;
Expand All @@ -45,7 +45,7 @@ use log::{error, warn};
use log::debug;

use cpu_common::CpuCommon;
use misc::{daemon_panic_handler, setprop};
use misc::setprop;

const USER_CONFIG: &str = "/sdcard/Android/fas-rs/games.toml";

Expand All @@ -61,7 +61,6 @@ fn main() -> Result<()> {

return Ok(());
} else if args[1] == "run" {
panic::set_hook(Box::new(daemon_panic_handler));
setprop("fas-rs-server-started", "true");
run(&args[2]).unwrap_or_else(|e| error!("{e:#?}"));
}
Expand Down
34 changes: 1 addition & 33 deletions src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::{
backtrace::Backtrace,
panic::PanicInfo,
process::{self, Command},
};

use log::error;
use std::process::Command;

pub fn setprop<S: AsRef<str>>(k: S, v: S) {
let key = k.as_ref();
let value = v.as_ref();
let _ = Command::new("setprop").args([key, value]).spawn();
}

pub fn daemon_panic_handler(panic_info: &PanicInfo) {
setprop("fas-rs-server-started", "false");

error!("fas-rs paniced! An unrecoverable error occurred!");

if let Some(location) = panic_info.location() {
error!(
"panic location: in file {} at line {}",
location.file(),
location.line()
);
}

if let Some(r) = panic_info.payload().downcast_ref::<&str>() {
error!("reason: {r:#?}");
} else {
error!("reason: Unknown");
}

let backtrace = Backtrace::force_capture();
error!("BACKTRACE: {backtrace}");

error!("If you're sure this shouldn't happen, open an issue on https://github.com/shadow3aaa/fas-rs/issues");
process::exit(-1);
}

0 comments on commit fd9d65c

Please sign in to comment.