Init commit

This commit is contained in:
Yu-Wei Wu
2022-01-19 23:32:07 +08:00
commit ce90429b11
6 changed files with 1887 additions and 0 deletions

10
.gitignore vendored Normal file
View File

@@ -0,0 +1,10 @@
# Rust
target/
**/*.rs.bk
# cargo-mobile
.cargo/
/gen
# macOS
.DS_Store

1734
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

24
Cargo.toml Normal file
View File

@@ -0,0 +1,24 @@
[package]
name = "wry-mobile"
version = "0.1.0"
authors = ["Yu-Wei Wu <wusyong9104@gmail.com>"]
edition = "2018"
[lib]
crate-type = ["staticlib", "cdylib", "rlib"]
[[bin]]
name = "wry-mobile-desktop"
path = "gen/bin/desktop.rs"
[dependencies]
mobile-entry-point = "0.1.0"
wry = { git = "https://github.com/tauri-apps/wry", branch = "next" }
[target.'cfg(target_os = "android")'.dependencies]
android_logger = "0.9.0"
log = "0.4.11"
ndk-glue = "0.2.1"
[target.'cfg(not(target_os = "android"))'.dependencies]
simple_logger = "1.11.0"

36
README.md Normal file
View File

@@ -0,0 +1,36 @@
# wry-mobile
This is the mobile template setup by cargo mobile.
## Cargo mobile
Build with [cargo mobile](https://github.com/BrainiumLLC/cargo-mobile) for our tests and simplicity of use.
```bash
cargo install --git https://github.com/BrainiumLLC/cargo-mobile
```
## iOS
### Open the project in XCode
```bash
cargo apple open
```
**Important: You need to link Webview Framework in build settings**
wry-mobile > General > Frameworks, Libraries, and Embedded Content > Webkit.framework
### Run on your connected phone
```bash
cargo apple run
```
If you haven't trusted the device, go to Settings > General > VPN 與裝置管理(what's the english name of this lol) to trust the device.
## Android
TODO

8
mobile.toml Normal file
View File

@@ -0,0 +1,8 @@
[app]
name = "wry-mobile"
stylized-name = "Wry Mobile"
domain = "example.com"
template-pack = "winit"
[apple]
development-team = "H47LR8SAAZ"

75
src/lib.rs Normal file
View File

@@ -0,0 +1,75 @@
use mobile_entry_point::mobile_entry_point;
use std::collections::HashMap;
use wry::{
application::{
dpi::LogicalSize,
event::{Event, WindowEvent, StartCause},
event_loop::{ControlFlow, EventLoop},
platform::ios::{WindowBuilderExtIOS, WindowExtIOS, ScreenEdge},
window::WindowBuilder,
},
webview::WebViewBuilder,
};
#[cfg(target_os = "android")]
fn init_logging() {
android_logger::init_once(
android_logger::Config::default()
.with_min_level(log::Level::Trace)
.with_tag("wry-mobile"),
);
}
#[cfg(not(target_os = "android"))]
fn init_logging() {
simple_logger::SimpleLogger::new().init().unwrap();
}
#[mobile_entry_point]
fn main() {
init_logging();
let event_loop = EventLoop::new();
let mut weviews = HashMap::new();
event_loop.run(move |event, event_loop, control_flow| {
*control_flow = ControlFlow::Wait;
match event {
Event::NewEvents(StartCause::Init) => {
println!("Init");
let window = WindowBuilder::new()
.build(&event_loop)
.unwrap();
let window_id = window.id();
let weview = WebViewBuilder::new(window)
.unwrap()
.with_url("https://tauri.studio")
.unwrap()
.build()
.unwrap();
weviews.insert(window_id, weview);
},
Event::Resumed => {
println!("applicationDidBecomeActive");
}
Event::Suspended => {
println!("applicationWillResignActive");
}
Event::LoopDestroyed => {
println!("applicationWillTerminate");
}
Event::WindowEvent {
window_id,
event: WindowEvent::Touch(touch),
..
} => {
println!("touch on {:?} {:?}", window_id, touch);
}
_ => {}
}
});
}