Skip to content

Commit

Permalink
mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
domechn committed Jul 28, 2023
1 parent 4912263 commit 7defb1a
Show file tree
Hide file tree
Showing 6 changed files with 272 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"@types/uuid": "^9.0.2",
"@types/yaml": "^1.9.7",
"@vitejs/plugin-react": "^2.0.0",
"internal-ip": "^8.0.0",
"node-fetch": "^3.3.1",
"typescript": "^4.6.4",
"vite": "^3.2.7"
Expand Down
3 changes: 3 additions & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ custom-protocol = ["tauri/custom-protocol"]
branch = "v1"
features = ["sqlite"] # or "postgres", or "mysql"
git = "https://github.com/tauri-apps/plugins-workspace"

[lib]
crate-type = ["staticlib", "cdylib", "rlib"]
8 changes: 8 additions & 0 deletions src-tauri/mobile.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[app]
name = "track3"
stylized-name = "Track3"
domain = "track3.dev"
template-pack = "wry"

[apple]
development-team = "domechn"
42 changes: 42 additions & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,45 @@ pub mod migration;
pub mod okex;
pub mod price;
pub mod types;

use tauri::App;

#[cfg(mobile)]
mod mobile;
#[cfg(mobile)]
pub use mobile::*;

pub type SetupHook = Box<dyn FnOnce(&mut App) -> Result<(), Box<dyn std::error::Error>> + Send>;

#[derive(Default)]
pub struct AppBuilder {
setup: Option<SetupHook>,
}

impl AppBuilder {
pub fn new() -> Self {
Self::default()
}

#[must_use]
pub fn setup<F>(mut self, setup: F) -> Self
where
F: FnOnce(&mut App) -> Result<(), Box<dyn std::error::Error>> + Send + 'static,
{
self.setup.replace(Box::new(setup));
self
}

pub fn run(self) {
let setup = self.setup;
tauri::Builder::default()
.setup(move |app| {
if let Some(setup) = setup {
(setup)(app)?;
}
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
}
4 changes: 4 additions & 0 deletions src-tauri/src/mobile.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[tauri::mobile_entry_point]
fn main() {
super::AppBuilder::new().run();
}
Loading

0 comments on commit 7defb1a

Please sign in to comment.