Skip to content

Commit

Permalink
Merge pull request #434 from cunarist/organize-first-template
Browse files Browse the repository at this point in the history
Organize first template
  • Loading branch information
temeddix authored Sep 16, 2024
2 parents 42395dc + b776c6c commit e54017e
Show file tree
Hide file tree
Showing 28 changed files with 449 additions and 320 deletions.
1 change: 1 addition & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
max_width = 80 # This matches the maximum line length used in Dart
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

![Preview](https://github.com/cunarist/rinf/assets/66480156/5c9a7fb6-e566-4c4e-bd77-d72c1c064d6c)

Rinf is a production-ready framework for creating beautiful and performant cross-platform apps using Flutter and Rust with batteries fully included. Simply add this framework to your app project, and you're all set to write Flutter and Rust together!
Rinf is a framework for creating beautiful and performant cross-platform apps using Flutter and Rust with batteries fully included. Simply add this framework to your app project, and you're all set to write Flutter and Rust together!

## 🎮 Demo

Expand Down
2 changes: 1 addition & 1 deletion documentation/docs/state-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Several crates on `crates.io` provide building blocks for implementing the actor

Here’s a basic example using the [`actix`](https://github.com/actix/actix) crate, a popular choice for the actor model:

```rust
```rust title="Rust"
use actix::prelude::*;

// this is our Message
Expand Down
13 changes: 13 additions & 0 deletions documentation/docs/stylesheets/extra.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
html {
overflow-y: scroll;
}

.md-header {
background-color: transparent !important;
position: relative;
box-shadow: none;
}

.md-search {
padding: 4px;
}
6 changes: 4 additions & 2 deletions documentation/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ theme:
palette:
# Palette toggle for light mode
- media: "(prefers-color-scheme: light)"
primary: grey
primary: white
scheme: default
toggle:
icon: material/brightness-7
Expand All @@ -21,7 +21,6 @@ theme:
icon: material/brightness-4
features:
- navigation.instant
- navigation.top
- navigation.tracking
- navigation.path
- navigation.footer
Expand Down Expand Up @@ -59,4 +58,7 @@ extra:
- icon: fontawesome/brands/twitter
link: https://twitter.com/cunarist

extra_css:
- stylesheets/extra.css

copyright: Copyright © 2024 Cunarist
78 changes: 41 additions & 37 deletions documentation/overrides/home.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
{% extends "main.html" %}
{% extends "base.html" %}
<!-- END OF BLOCK -->

{% block tabs %}
<style>
[data-md-color-scheme="default"] {
--md-default-bg-color: #ffffff;
}
[data-md-color-scheme="slate"] {
--md-default-bg-color: #141414;
}
.outermost {
padding: 0px 24px 0px;
text-align: center;
Expand Down Expand Up @@ -35,7 +41,7 @@
box-shadow: 0px 8px 24px rgba(0, 0, 0, 0.4);
margin-bottom: 24px;
width: 400px;
max-width: 50svw !important;
max-width: 72svw !important;
outline: 1px solid rgba(122, 122, 122, 1);
outline-offset: -1px;
filter: grayscale();
Expand All @@ -49,24 +55,31 @@
.spacing {
height: 40px;
}
.description-text {
padding: 0px 40px;
}
.guide-box {
max-width: min(36em, 80svw);
min-width: 14em;
min-width: 18em;
margin: 0em auto 0em;
padding: 8px;
padding: 16px;
text-align: left;
flex: 1;
}
.repeated-box {
max-width: 14em;
min-width: 14em;
width: 14em;
height: 28em;
margin: 8px;
padding: 24px;
text-align: left;
background-color: rgba(127, 127, 127, 0.08);
border-radius: 4px;
height: 30em;
flex: 1;
}
@media (max-width: 40em) {
.repeated-box {
width: 100%;
height: fit-content;
}
}
.lang-icon {
margin-top: 30px;
Expand Down Expand Up @@ -94,41 +107,31 @@
<div class="md-grid md-typeset outermost">
<div class="front-panel">
<div class="spacing"></div>
<div class="centered">
<img
src="assets/preview.webp"
loop
class="preview-image"
draggable="false"
/>
<div>
<a
href="https://rinf-demo.cunarist.com"
target="_blank"
title="Visit demo"
>
<img
src="assets/preview.webp"
loop
class="preview-image"
draggable="false"
/>
</a>
</div>
<div class="centered">
<p class="semi-transparent">
Production-ready framework for creating beautiful and performant
cross-platform apps
<div>
<p class="semi-transparent description-text">
Build beautiful and performant cross-platform apps
</p>
<p class="web-title">Rinf</p>
<p class="semi-transparent"><strong>RUST IN FLUTTER</strong></p>
</div>
<div class="spacing"></div>
</div>
<div class="spacing"></div>
<div class="centered">
<h2>Quick Start</h2>
<div class="spacing"></div>
<a href="{{ page.next_page.url | url }}" class="md-button fixed-button">
Read the Docs
</a>
<a
href="https://rinf-demo.cunarist.com"
class="md-button fixed-button"
target="_blank"
>
Visit demo
</a>
</div>
<div class="spacing"></div>
<div class="centered">
<div>
<h2>The Combination</h2>
<div class="columns">
<div class="guide-box">
Expand Down Expand Up @@ -184,7 +187,7 @@ <h3>Rust for Performance</h3>
</div>
</div>
<div class="spacing"></div>
<div class="centered">
<div>
<h2>Platform Support</h2>
<div class="guide-box">
<p>
Expand All @@ -207,7 +210,7 @@ <h2>Platform Support</h2>
</div>
</div>
<div class="spacing"></div>
<div class="centered">
<div>
<h2>Benefits</h2>
<div class="columns">
<div class="repeated-box">
Expand Down Expand Up @@ -274,6 +277,7 @@ <h3>Reliable</h3>
</div>
</div>
</div>
<div class="spacing"></div>
</div>
{% endblock %}
<!-- END OF BLOCK -->
Expand Down
10 changes: 5 additions & 5 deletions documentation/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package-mode = false

[tool.poetry.dependencies]
python = "^3.10"
mkdocs = "^1.5.2"
mkdocs-material = "^9.1.21"
mkdocs-awesome-pages-plugin = "^2.9.1"
mkdocs-glightbox = "^0.3.4"
mkdocs-git-revision-date-localized-plugin = "^1.2.2"
mkdocs = "^1.6.1"
mkdocs-material = "^9.5.34"
mkdocs-awesome-pages-plugin = "^2.9.3"
mkdocs-glightbox = "^0.4.0"
mkdocs-git-revision-date-localized-plugin = "^1.2.9"
2 changes: 1 addition & 1 deletion flutter_package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

![Preview](https://github.com/cunarist/rinf/assets/66480156/5c9a7fb6-e566-4c4e-bd77-d72c1c064d6c)

Rinf is a production-ready framework for creating beautiful and performant cross-platform apps using Flutter and Rust with batteries fully included. Simply add this framework to your app project, and you're all set to write Flutter and Rust together!
Rinf is a framework for creating beautiful and performant cross-platform apps using Flutter and Rust with batteries fully included. Simply add this framework to your app project, and you're all set to write Flutter and Rust together!

## 🎮 Demo

Expand Down
37 changes: 16 additions & 21 deletions flutter_package/bin/src/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,7 @@ import 'package:rinf/rinf.dart';
use prost::Message;
use rinf::{
debug_print, send_rust_signal, signal_channel,
DartSignal, RinfError, SignalReceiver,
SignalSender,
DartSignal, SignalReceiver, SignalSender,
};
use std::sync::LazyLock;
Expand Down Expand Up @@ -422,29 +421,21 @@ impl ${normalizePascal(messageName)} {
#![allow(unused_imports)]
#![allow(unused_mut)]
use super::*;
use prost::Message;
use rinf::{debug_print, signal_channel, DartSignal, RinfError};
use rinf::{DartSignal, RinfError};
use std::collections::HashMap;
use std::error::Error;
use std::sync::OnceLock;
use std::sync::LazyLock;
type Handler = dyn Fn(&[u8], &[u8]) -> Result<(), RinfError> + Send + Sync;
type DartSignalHandlers = HashMap<i32, Box<Handler>>;
static DART_SIGNAL_HANDLERS: OnceLock<DartSignalHandlers> = OnceLock::new();
pub fn assign_dart_signal(
message_id: i32,
message_bytes: &[u8],
binary: &[u8]
) -> Result<(), RinfError> {
let hash_map = DART_SIGNAL_HANDLERS.get_or_init(|| {
let mut new_hash_map: DartSignalHandlers = HashMap::new();
static DART_SIGNAL_HANDLERS: LazyLock<DartSignalHandlers> = LazyLock::new(|| {
let mut hash_map: DartSignalHandlers = HashMap::new();
''';
for (final entry in markedMessagesAll.entries) {
final subpath = entry.key;
final files = entry.value;
for (final entry in files.entries) {
final filename = entry.key;
final markedMessages = entry.value;
for (final markedMessage in markedMessages) {
final markType = markedMessage.markType;
Expand All @@ -455,13 +446,12 @@ pub fn assign_dart_signal(
var modulePath = subpath.replaceAll('/', '::');
modulePath = modulePath == '::' ? '' : modulePath;
rustReceiveScript += '''
new_hash_map.insert(
hash_map.insert(
${markedMessage.id},
Box::new(|message_bytes: &[u8], binary: &[u8]| {
use super::$modulePath$filename::*;
let message =
${normalizePascal(messageName)}::decode(message_bytes)
.map_err(|_| RinfError::DecodeMessage)?;
.map_err(|_| RinfError::CannotDecodeMessage)?;
let dart_signal = DartSignal {
message,
binary: binary.to_vec(),
Expand All @@ -476,10 +466,15 @@ new_hash_map.insert(
}
}
rustReceiveScript += '''
new_hash_map
});
hash_map
});
let signal_handler = match hash_map.get(&message_id) {
pub fn assign_dart_signal(
message_id: i32,
message_bytes: &[u8],
binary: &[u8]
) -> Result<(), RinfError> {
let signal_handler = match DART_SIGNAL_HANDLERS.get(&message_id) {
Some(inner) => inner,
None => return Err(RinfError::NoSignalHandler),
};
Expand Down
8 changes: 4 additions & 4 deletions flutter_package/example/native/hub/src/common.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::error::Error;

/// Using this `Result` type alias allows
/// handling any error type that implements the `Error` trait.
/// This approach eliminates the need
/// to depend on external crates for error handling.
/// This `Result` type alias allows handling any error type
/// that implements the `Error` trait.
/// In practice, it is recommended to use custom solutions
/// or crates dedicated to error handling.
pub type Result<T> = std::result::Result<T, Box<dyn Error + Send + Sync>>;
11 changes: 3 additions & 8 deletions flutter_package/example/native/hub/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ mod common;
mod messages;
mod sample_functions;

use common::*;
use tokio_with_wasm::alias as tokio;

rinf::write_interface!();
Expand All @@ -16,16 +15,12 @@ rinf::write_interface!();
// If you really need to use blocking code,
// use `tokio::task::spawn_blocking`.
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
async fn main() {
// Spawn the concurrent tasks.
tokio::spawn(sample_functions::tell_numbers());
tokio::spawn(sample_functions::stream_fractal());
tokio::spawn(sample_functions::run_debug_tests());

// Get the shutdown receiver from Rinf.
// This receiver will await a signal from Dart shutdown.
let shutdown_receiver = rinf::get_shutdown_receiver()?;
shutdown_receiver.await;

Ok(())
// Keep the main function running until Dart shutdown.
rinf::dart_shutdown().await;
}
11 changes: 7 additions & 4 deletions flutter_package/example/native/hub/src/sample_functions.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! This crate is written for Rinf demonstrations.
//! This module is written for Rinf demonstrations.
use crate::common::*;
use crate::messages::*;
Expand All @@ -8,9 +8,9 @@ use std::time::Duration;

// Using the `cfg` macro enables conditional statement.
#[cfg(debug_assertions)]
static IS_DEBUG_MODE: bool = true;
const IS_DEBUG_MODE: bool = true;
#[cfg(not(debug_assertions))]
static IS_DEBUG_MODE: bool = false;
const IS_DEBUG_MODE: bool = false;

// Business logic for the counter widget.
pub async fn tell_numbers() {
Expand Down Expand Up @@ -193,7 +193,10 @@ pub async fn run_debug_tests() -> Result<()> {
prime_count += 1;
}
}
format!("There are {prime_count} primes from {count_from} to {count_to}.")
format!(
"There are {} primes from {} to {}.",
prime_count, count_from, count_to,
)
});
join_handles.push(join_handle);
}
Expand Down
Loading

0 comments on commit e54017e

Please sign in to comment.