mirror of
https://code.gri.mw/GUI/grim.git
synced 2026-07-19 05:08:59 +00:00
android: update activity lib, optimize app exit
This commit is contained in:
+5
-2
@@ -65,8 +65,11 @@ impl<Platform: PlatformCallbacks> eframe::App for PlatformApp<Platform> {
|
||||
}
|
||||
|
||||
fn on_close_event(&mut self) -> bool {
|
||||
Root::show_exit_modal();
|
||||
self.root.exit_allowed
|
||||
let exit = self.root.exit_allowed;
|
||||
if !exit {
|
||||
Root::show_exit_modal();
|
||||
}
|
||||
exit
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -74,15 +74,4 @@ impl PlatformCallbacks for Android {
|
||||
};
|
||||
paste_data
|
||||
}
|
||||
|
||||
fn exit(&self) {
|
||||
use jni::objects::{JObject};
|
||||
|
||||
let vm = unsafe { jni::JavaVM::from_raw(self.android_app.vm_as_ptr() as _) }.unwrap();
|
||||
let mut env = vm.attach_current_thread().unwrap();
|
||||
let activity = unsafe {
|
||||
JObject::from_raw(self.android_app.activity_as_ptr() as jni::sys::jobject)
|
||||
};
|
||||
env.call_method(activity, "onExit", "()V", &[]).unwrap();
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,4 @@ impl PlatformCallbacks for Desktop {
|
||||
fn get_string_from_buffer(&self) -> String {
|
||||
"".to_string()
|
||||
}
|
||||
|
||||
fn exit(&self) {}
|
||||
}
|
||||
|
||||
@@ -26,5 +26,4 @@ pub trait PlatformCallbacks {
|
||||
fn hide_keyboard(&self);
|
||||
fn copy_string_to_buffer(&self, data: String);
|
||||
fn get_string_from_buffer(&self) -> String;
|
||||
fn exit(&self);
|
||||
}
|
||||
+8
-22
@@ -78,7 +78,7 @@ impl Root {
|
||||
pub fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame, cb: &dyn PlatformCallbacks) {
|
||||
// Show opened exit confirmation modal content.
|
||||
if self.can_draw_modal() {
|
||||
self.exit_modal_content(ui, frame, cb);
|
||||
self.exit_modal_content(ui, frame);
|
||||
}
|
||||
|
||||
let (is_panel_open, panel_width) = Self::network_panel_state_width(frame);
|
||||
@@ -148,14 +148,11 @@ impl Root {
|
||||
}
|
||||
|
||||
/// Draw exit confirmation modal content.
|
||||
fn exit_modal_content(&mut self,
|
||||
ui: &mut egui::Ui,
|
||||
frame: &mut eframe::Frame,
|
||||
cb: &dyn PlatformCallbacks) {
|
||||
fn exit_modal_content(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) {
|
||||
Modal::ui(ui, |ui, modal| {
|
||||
if self.show_exit_progress {
|
||||
if !Node::is_running() {
|
||||
self.exit(frame, cb);
|
||||
self.exit(frame);
|
||||
modal.close();
|
||||
}
|
||||
ui.add_space(16.0);
|
||||
@@ -185,7 +182,7 @@ impl Root {
|
||||
columns[0].vertical_centered_justified(|ui| {
|
||||
View::button(ui, t!("modal_exit.exit"), Colors::WHITE, || {
|
||||
if !Node::is_running() {
|
||||
self.exit(frame, cb);
|
||||
self.exit(frame);
|
||||
modal.close();
|
||||
} else {
|
||||
Node::stop(true);
|
||||
@@ -206,21 +203,10 @@ impl Root {
|
||||
});
|
||||
}
|
||||
|
||||
/// Platform-specific exit from the application.
|
||||
fn exit(&mut self, frame: &mut eframe::Frame, cb: &dyn PlatformCallbacks) {
|
||||
match OperatingSystem::from_target_os() {
|
||||
OperatingSystem::Android => {
|
||||
cb.exit();
|
||||
}
|
||||
OperatingSystem::IOS => {
|
||||
//TODO: exit on iOS.
|
||||
}
|
||||
OperatingSystem::Nix | OperatingSystem::Mac | OperatingSystem::Windows => {
|
||||
self.exit_allowed = true;
|
||||
frame.close();
|
||||
}
|
||||
OperatingSystem::Unknown => {}
|
||||
}
|
||||
/// Exit from the application.
|
||||
fn exit(&mut self, frame: &mut eframe::Frame) {
|
||||
self.exit_allowed = true;
|
||||
frame.close();
|
||||
}
|
||||
|
||||
/// Handle Back key event.
|
||||
|
||||
Reference in New Issue
Block a user