build: fix build for desktop

This commit is contained in:
ardocrat 2023-07-11 16:23:10 +03:00
parent bab8c49f26
commit 88f92d51b3
9 changed files with 149 additions and 138 deletions

View file

@ -1,2 +0,0 @@
[build]
target = "aarch64-linux-android"

2
.gitignore vendored
View file

@ -11,5 +11,5 @@ local.properties
*.so *.so
# Added by cargo # Added by cargo
/target /target
/.cargo/

View file

@ -7,6 +7,10 @@ version = "0.1.0"
edition = "2021" edition = "2021"
build = "src/build/build.rs" build = "src/build/build.rs"
[lib]
name="grim"
crate_type=["cdylib", "rlib"]
[features] [features]
#static_ssl = ['openssl/vendored'] #static_ssl = ['openssl/vendored']
@ -67,8 +71,4 @@ winit = { version = "0.28" }
[target.'cfg(target_os = "android")'.dependencies] [target.'cfg(target_os = "android")'.dependencies]
android_logger = "0.13.1" android_logger = "0.13.1"
jni = "0.21.1" jni = "0.21.1"
winit = { version = "0.28", features = [ "android-game-activity" ] } winit = { version = "0.28", features = [ "android-game-activity" ] }
[lib]
name="grim"
crate_type=["cdylib"]

View file

@ -1,116 +0,0 @@
// Copyright 2023 The Grim Developers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use eframe::{AppCreator, NativeOptions, Renderer, Theme};
#[cfg(target_os = "android")]
use winit::platform::android::activity::AndroidApp;
use crate::gui::{App, PlatformApp};
use crate::node::Node;
use crate::Settings;
#[allow(dead_code)]
#[cfg(target_os = "android")]
#[no_mangle]
fn android_main(app: AndroidApp) {
#[cfg(debug_assertions)]
{
std::env::set_var("RUST_BACKTRACE", "full");
let log_config = android_logger::Config::default()
.with_max_level(log::LevelFilter::Info)
.with_tag("grim");
android_logger::init_once(log_config);
}
use crate::gui::platform::Android;
let platform = Android::new(app.clone());
use winit::platform::android::EventLoopBuilderExtAndroid;
let mut options = NativeOptions::default();
options.event_loop_builder = Some(Box::new(move |builder| {
builder.with_android_app(app);
}));
start(options, app_creator(PlatformApp::new(platform)));
}
#[allow(dead_code)]
#[cfg(not(target_os = "android"))]
fn main() {
#[cfg(debug_assertions)]
env_logger::builder()
.filter_level(Info)
.parse_default_env()
.init();
use crate::gui::platform::Desktop;
let options = NativeOptions::default();
start(options, app_creator(Desktop::default()));
}
fn app_creator<T: 'static>(app: PlatformApp<T>) -> AppCreator where PlatformApp<T>: eframe::App {
Box::new(|cc| {
App::setup_visuals(&cc.egui_ctx);
App::setup_fonts(&cc.egui_ctx);
//TODO: Setup storage
Box::new(app)
})
}
fn start(mut options: NativeOptions, app_creator: AppCreator) {
options.default_theme = Theme::Light;
options.renderer = Renderer::Wgpu;
setup_i18n();
if Settings::app_config_to_read().auto_start_node {
Node::start();
}
let _ = eframe::run_native("Grim", options, app_creator);
}
fn setup_i18n() {
const DEFAULT_LOCALE: &str = "en";
let locale = sys_locale::get_locale().unwrap_or(String::from(DEFAULT_LOCALE));
let locale_str = if locale.contains("-") {
locale.split("-").next().unwrap_or(DEFAULT_LOCALE)
} else {
DEFAULT_LOCALE
};
if crate::_rust_i18n_available_locales().contains(&locale_str) {
rust_i18n::set_locale(locale_str);
}
}
mod built_info {
include!(concat!(env!("OUT_DIR"), "/built.rs"));
}
pub fn info_strings() -> (String, String) {
(
format!(
"This is Grim version {}{}, built for {} by {}.",
built_info::PKG_VERSION,
built_info::GIT_VERSION.map_or_else(|| "".to_owned(), |v| format!(" (git {})", v)),
built_info::TARGET,
built_info::RUSTC_VERSION,
),
format!(
"Built with profile \"{}\", features \"{}\".",
built_info::PROFILE,
built_info::FEATURES_STR,
),
)
}

View file

@ -12,13 +12,37 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use crate::gui::PlatformApp; use crate::gui::{App, PlatformApp};
use crate::gui::platform::PlatformCallbacks;
#[derive(Default)] #[derive(Default)]
pub struct Desktop; pub struct Desktop;
impl PlatformCallbacks for Desktop {
fn show_keyboard(&self) {}
fn hide_keyboard(&self) {}
fn copy_string_to_buffer(&self, data: String) {}
fn get_string_from_buffer(&self) -> String {
"".to_string()
}
fn exit(&self) {}
}
impl PlatformApp<Desktop> { impl PlatformApp<Desktop> {
pub fn new(cc: &eframe::CreationContext<'_>) -> Self { pub fn new(platform: Desktop) -> Self {
Self::default() Self {
app: App::default(),
platform,
}
}
}
impl eframe::App for PlatformApp<Desktop> {
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
self.app.ui(ctx, frame, &self.platform);
} }
} }

View file

@ -11,6 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
pub use self::platform::*; pub use self::platform::*;
#[cfg(target_os = "android")] #[cfg(target_os = "android")]
@ -18,7 +19,7 @@ pub use self::platform::*;
pub mod platform; pub mod platform;
#[cfg(not(target_os = "android"))] #[cfg(not(target_os = "android"))]
#[path = "desktop/mod.rs"] #[path = "desktop/mod.rs"]
pub mod app; pub mod platform;
pub trait PlatformCallbacks { pub trait PlatformCallbacks {
fn show_keyboard(&self); fn show_keyboard(&self);

View file

@ -14,13 +14,82 @@
#[macro_use] #[macro_use]
extern crate rust_i18n; extern crate rust_i18n;
use eframe::{AppCreator, Renderer, Theme};
#[cfg(target_os = "android")]
use winit::platform::android::activity::AndroidApp;
pub use settings::{AppConfig, Settings};
use crate::gui::{App, PlatformApp};
use crate::node::Node;
i18n!("locales"); i18n!("locales");
mod node; pub mod node;
mod wallet; mod wallet;
mod gui; pub mod gui;
pub mod grim;
mod settings; mod settings;
pub use settings::{Settings, AppConfig};
#[allow(dead_code)]
#[cfg(target_os = "android")]
#[no_mangle]
fn android_main(app: AndroidApp) {
#[cfg(debug_assertions)]
{
std::env::set_var("RUST_BACKTRACE", "full");
let log_config = android_logger::Config::default()
.with_max_level(log::LevelFilter::Info)
.with_tag("grim");
android_logger::init_once(log_config);
}
use gui::platform::Android;
use gui::PlatformApp;
let platform = Android::new(app.clone());
use winit::platform::android::EventLoopBuilderExtAndroid;
let mut options = eframe::NativeOptions::default();
options.event_loop_builder = Some(Box::new(move |builder| {
builder.with_android_app(app);
}));
start(options, app_creator(PlatformApp::new(platform)));
}
pub fn app_creator<T: 'static>(app: PlatformApp<T>) -> AppCreator where PlatformApp<T>: eframe::App {
Box::new(|cc| {
App::setup_visuals(&cc.egui_ctx);
App::setup_fonts(&cc.egui_ctx);
//TODO: Setup storage
Box::new(app)
})
}
pub fn start(mut options: eframe::NativeOptions, app_creator: AppCreator) {
options.default_theme = Theme::Light;
options.renderer = Renderer::Wgpu;
setup_i18n();
if Settings::app_config_to_read().auto_start_node {
Node::start();
}
let _ = eframe::run_native("Grim", options, app_creator);
}
fn setup_i18n() {
const DEFAULT_LOCALE: &str = "en";
let locale = sys_locale::get_locale().unwrap_or(String::from(DEFAULT_LOCALE));
let locale_str = if locale.contains("-") {
locale.split("-").next().unwrap_or(DEFAULT_LOCALE)
} else {
DEFAULT_LOCALE
};
if _rust_i18n_available_locales().contains(&locale_str) {
rust_i18n::set_locale(locale_str);
}
}

36
src/main.rs Normal file
View file

@ -0,0 +1,36 @@
// Copyright 2023 The Grim Developers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
pub fn main() {
#[allow(dead_code)]
#[cfg(not(target_os = "android"))]
real_main();
}
#[allow(dead_code)]
#[cfg(not(target_os = "android"))]
fn real_main() {
#[cfg(debug_assertions)]
env_logger::builder()
.filter_level(log::LevelFilter::Info)
.parse_default_env()
.init();
use grim::gui::platform::Desktop;
use grim::gui::PlatformApp;
let platform = Desktop::default();
let options = eframe::NativeOptions::default();
grim::start(options, grim::app_creator(PlatformApp::new(platform)));
}

View file

@ -24,7 +24,6 @@ use grin_core::global;
use grin_core::global::ChainTypes; use grin_core::global::ChainTypes;
use grin_servers::{Server, ServerStats, StratumServerConfig, StratumStats}; use grin_servers::{Server, ServerStats, StratumServerConfig, StratumStats};
use grin_servers::common::types::Error; use grin_servers::common::types::Error;
use jni::sys::{jboolean, jstring};
use lazy_static::lazy_static; use lazy_static::lazy_static;
use crate::node::NodeConfig; use crate::node::NodeConfig;
use crate::node::stratum::{StratumStopState, StratumServer}; use crate::node::stratum::{StratumStopState, StratumServer};
@ -612,7 +611,7 @@ pub extern "C" fn Java_mw_gri_android_BackgroundService_getSyncStatusText(
_env: jni::JNIEnv, _env: jni::JNIEnv,
_class: jni::objects::JObject, _class: jni::objects::JObject,
_activity: jni::objects::JObject, _activity: jni::objects::JObject,
) -> jstring { ) -> jni::sys::jstring {
let status_text = Node::get_sync_status_text(); let status_text = Node::get_sync_status_text();
let j_text = _env.new_string(status_text); let j_text = _env.new_string(status_text);
return j_text.unwrap().into_raw(); return j_text.unwrap().into_raw();
@ -627,7 +626,7 @@ pub extern "C" fn Java_mw_gri_android_BackgroundService_getSyncTitle(
_env: jni::JNIEnv, _env: jni::JNIEnv,
_class: jni::objects::JObject, _class: jni::objects::JObject,
_activity: jni::objects::JObject, _activity: jni::objects::JObject,
) -> jstring { ) -> jni::sys::jstring {
let j_text = _env.new_string(t!("network.node")); let j_text = _env.new_string(t!("network.node"));
return j_text.unwrap().into_raw(); return j_text.unwrap().into_raw();
} }
@ -641,7 +640,7 @@ pub extern "C" fn Java_mw_gri_android_BackgroundService_exitAppAfterNodeStop(
_env: jni::JNIEnv, _env: jni::JNIEnv,
_class: jni::objects::JObject, _class: jni::objects::JObject,
_activity: jni::objects::JObject, _activity: jni::objects::JObject,
) -> jboolean { ) -> jni::sys::jboolean {
let exit_needed = !Node::is_running() && NODE_STATE.exit_after_stop.load(Ordering::Relaxed); let exit_needed = !Node::is_running() && NODE_STATE.exit_after_stop.load(Ordering::Relaxed);
return exit_needed as jboolean; return exit_needed as jni::sys::jboolean;
} }