Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Organize first template #434

Merged
merged 55 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
65f1ee7
Shorten first guide sentences
temeddix Sep 14, 2024
524c728
Move `communicate` to another Rust module
temeddix Sep 14, 2024
c593312
Remove unneeded line
temeddix Sep 14, 2024
c89c925
Fix a small bug
temeddix Sep 14, 2024
d43db43
Organize `Cargo.toml`
temeddix Sep 14, 2024
f49794e
Remove unused derive
temeddix Sep 14, 2024
f1b920d
Replace `OnceLock` with `LazyLock`
temeddix Sep 14, 2024
0ccc2f9
Replace `OnceLock` with `LazyLock`
temeddix Sep 14, 2024
6ca1f32
Remove unused imports from code generation
temeddix Sep 14, 2024
ab3f427
Remove unneeded errors
temeddix Sep 14, 2024
8798944
Fix typos
temeddix Sep 14, 2024
00b92bf
Use event-based shutdown procedure
temeddix Sep 14, 2024
4eae6c1
Update comments
temeddix Sep 14, 2024
4beeb30
Update HTML
temeddix Sep 14, 2024
3bcf93c
Remove unneeded comments
temeddix Sep 14, 2024
6cb3324
Revert "Remove unneeded comments"
temeddix Sep 14, 2024
3546367
Add a field `started_session` to `WaitFuture` of `Event`
temeddix Sep 14, 2024
4c57cae
Organize `Event` code
temeddix Sep 14, 2024
9106ee0
Fix a comment
temeddix Sep 14, 2024
3f01f3f
Improve comments
temeddix Sep 14, 2024
d1ac5f0
Check for inner flag from `wait`
temeddix Sep 14, 2024
c4b49d9
Organize code
temeddix Sep 14, 2024
94afa5a
Organize code
temeddix Sep 14, 2024
d7dfcf4
Fix a comment
temeddix Sep 14, 2024
4430b11
Fix errors in other platforms
temeddix Sep 14, 2024
3916505
Remove wrong code
temeddix Sep 14, 2024
2690257
Organize `poll` method code
temeddix Sep 15, 2024
8617515
Rename an error variant
temeddix Sep 15, 2024
5f29d42
Rename some variables
temeddix Sep 15, 2024
6e028d2
Change the homepage text
temeddix Sep 15, 2024
819bf86
Fix a small error
temeddix Sep 15, 2024
50419bd
Use maximum line length of 80 in Rust
temeddix Sep 15, 2024
9a53638
Split long comments into multiple lines
temeddix Sep 15, 2024
85f185f
Hide some Rust items from the docs
temeddix Sep 15, 2024
6bb8d15
Rename `rustfmt.toml` to `.rustfmt.toml`
temeddix Sep 15, 2024
7c74e3d
Write Clippy rules
temeddix Sep 15, 2024
a7c8c16
Clarify error messages of `main.rs`
temeddix Sep 15, 2024
21e806d
Use `const` for simple constants
temeddix Sep 15, 2024
7c4b58e
Split long line of macro code
temeddix Sep 15, 2024
669249a
Use transparent and static webpage header
temeddix Sep 15, 2024
467be10
Add extra CSS
temeddix Sep 15, 2024
9058317
Make cards fill the width
temeddix Sep 15, 2024
1279b26
Make the cards mobile-friendly
temeddix Sep 15, 2024
e1c932e
Modify guide box CSS
temeddix Sep 15, 2024
181533f
Remove go to top button
temeddix Sep 15, 2024
dc42fb7
Add a spacing element at the bottom
temeddix Sep 15, 2024
8da1a4d
Remove unneeded buttons from webpage
temeddix Sep 15, 2024
1887d16
Update MkDocs dependencies
temeddix Sep 15, 2024
f04c705
Fix the primary color in bright mode
temeddix Sep 15, 2024
61f5f78
Fix dark mode toggle behavior
temeddix Sep 15, 2024
f2e3e1d
Improve CSS in various aspects
temeddix Sep 15, 2024
3fd9417
Fix CSS behavior on narrow phones
temeddix Sep 15, 2024
af45c62
Format docs
temeddix Sep 15, 2024
0863d23
Resolve lint issues inside `shutdown` module
temeddix Sep 15, 2024
b776c6c
Remove outdatd attribute macro
temeddix Sep 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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