2023-04-21 03:45:59 +03:00
|
|
|
// Copyright 2023 The Grim Developers
|
2023-04-10 16:02:53 +03:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2023-04-21 03:45:59 +03:00
|
|
|
#[macro_use]
|
|
|
|
extern crate rust_i18n;
|
2023-07-11 16:23:10 +03:00
|
|
|
|
2023-07-13 18:44:37 +03:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
2023-07-11 16:23:10 +03:00
|
|
|
#[cfg(target_os = "android")]
|
|
|
|
use winit::platform::android::activity::AndroidApp;
|
|
|
|
|
|
|
|
pub use settings::{AppConfig, Settings};
|
|
|
|
|
|
|
|
use crate::gui::{App, PlatformApp};
|
2023-07-11 21:02:36 +03:00
|
|
|
use crate::gui::platform::PlatformCallbacks;
|
2023-07-11 16:23:10 +03:00
|
|
|
use crate::node::Node;
|
|
|
|
|
2023-04-21 03:45:59 +03:00
|
|
|
i18n!("locales");
|
|
|
|
|
2023-07-11 16:26:39 +03:00
|
|
|
mod node;
|
2023-04-10 16:02:53 +03:00
|
|
|
mod wallet;
|
2023-07-11 16:23:10 +03:00
|
|
|
pub mod gui;
|
2023-06-15 23:54:31 +03:00
|
|
|
|
|
|
|
mod settings;
|
2023-07-11 16:23:10 +03:00
|
|
|
|
|
|
|
#[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();
|
2023-07-13 18:44:37 +03:00
|
|
|
// Use limits are guaranteed to be compatible with Android devices.
|
|
|
|
options.wgpu_options.device_descriptor = Arc::new(|adapter| {
|
|
|
|
let base_limits = wgpu::Limits::downlevel_webgl2_defaults();
|
|
|
|
wgpu::DeviceDescriptor {
|
|
|
|
label: Some("egui wgpu device"),
|
|
|
|
features: wgpu::Features::default(),
|
|
|
|
limits: wgpu::Limits {
|
|
|
|
max_texture_dimension_2d: 8192,
|
|
|
|
..base_limits
|
|
|
|
},
|
|
|
|
}
|
|
|
|
});
|
2023-07-11 16:23:10 +03:00
|
|
|
options.event_loop_builder = Some(Box::new(move |builder| {
|
|
|
|
builder.with_android_app(app);
|
|
|
|
}));
|
|
|
|
|
|
|
|
start(options, app_creator(PlatformApp::new(platform)));
|
|
|
|
}
|
|
|
|
|
2023-07-11 16:26:39 +03:00
|
|
|
pub fn app_creator<T: 'static>(app: PlatformApp<T>) -> eframe::AppCreator
|
2023-07-11 21:02:36 +03:00
|
|
|
where PlatformApp<T>: eframe::App, T: PlatformCallbacks {
|
2023-07-11 16:23:10 +03:00
|
|
|
Box::new(|cc| {
|
|
|
|
App::setup_visuals(&cc.egui_ctx);
|
|
|
|
App::setup_fonts(&cc.egui_ctx);
|
|
|
|
//TODO: Setup storage
|
|
|
|
Box::new(app)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-07-11 16:26:39 +03:00
|
|
|
pub fn start(mut options: eframe::NativeOptions, app_creator: eframe::AppCreator) {
|
|
|
|
options.default_theme = eframe::Theme::Light;
|
|
|
|
options.renderer = eframe::Renderer::Wgpu;
|
2023-07-11 21:02:36 +03:00
|
|
|
options.initial_window_size = Some(egui::Vec2::new(1200.0, 720.0));
|
2023-07-11 16:23:10 +03:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|