Initial scaffold: Sinatra map app with Tauri desktop shell
Sinatra backend serving a basic Leaflet map, wrapped in a Tauri desktop shell that starts the same server in a native window.
This commit is contained in:
commit
7329497e95
27 files changed
+5010
No files matched your search
+16
@@ -0,0 +1,16 @@
|
||||
# Ruby / Bundler
|
||||
/.bundle/
|
||||
/vendor/bundle/
|
||||
*.gem
|
||||
/log/
|
||||
/tmp/
|
||||
|
||||
# Rust / Tauri
|
||||
/src-tauri/target/
|
||||
|
||||
# Editor / OS
|
||||
.DS_Store
|
||||
*.swp
|
||||
|
||||
# Local tooling settings
|
||||
.claude/settings.local.json
|
||||
@@ -0,0 +1 @@
|
||||
4.0.6
|
||||
@@ -0,0 +1,9 @@
|
||||
source "https://rubygems.org"
|
||||
|
||||
gem "sinatra", "~> 4.2"
|
||||
gem "sinatra-contrib", "~> 4.2"
|
||||
gem "puma", "~> 8.0"
|
||||
|
||||
group :development do
|
||||
gem "rerun"
|
||||
end
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
base64 (0.3.0)
|
||||
ffi (1.17.4)
|
||||
ffi (1.17.4-aarch64-linux-gnu)
|
||||
ffi (1.17.4-aarch64-linux-musl)
|
||||
ffi (1.17.4-arm-linux-gnu)
|
||||
ffi (1.17.4-arm-linux-musl)
|
||||
ffi (1.17.4-arm64-darwin)
|
||||
ffi (1.17.4-x86-linux-gnu)
|
||||
ffi (1.17.4-x86-linux-musl)
|
||||
ffi (1.17.4-x86_64-darwin)
|
||||
ffi (1.17.4-x86_64-linux-gnu)
|
||||
ffi (1.17.4-x86_64-linux-musl)
|
||||
listen (3.10.0)
|
||||
logger
|
||||
rb-fsevent (~> 0.10, >= 0.10.3)
|
||||
rb-inotify (~> 0.9, >= 0.9.10)
|
||||
logger (1.7.0)
|
||||
multi_json (1.21.1)
|
||||
mustermann (3.1.1)
|
||||
nio4r (2.7.5)
|
||||
puma (8.0.2)
|
||||
nio4r (~> 2.0)
|
||||
rack (3.2.7)
|
||||
rack-protection (4.2.1)
|
||||
base64 (>= 0.1.0)
|
||||
logger (>= 1.6.0)
|
||||
rack (>= 3.0.0, < 4)
|
||||
rack-session (2.1.2)
|
||||
base64 (>= 0.1.0)
|
||||
rack (>= 3.0.0)
|
||||
rb-fsevent (0.11.2)
|
||||
rb-inotify (0.11.1)
|
||||
ffi (~> 1.0)
|
||||
rerun (0.14.0)
|
||||
listen (~> 3.0)
|
||||
sinatra (4.2.1)
|
||||
logger (>= 1.6.0)
|
||||
mustermann (~> 3.0)
|
||||
rack (>= 3.0.0, < 4)
|
||||
rack-protection (= 4.2.1)
|
||||
rack-session (>= 2.0.0, < 3)
|
||||
tilt (~> 2.0)
|
||||
sinatra-contrib (4.2.1)
|
||||
multi_json (>= 0.0.2)
|
||||
mustermann (~> 3.0)
|
||||
rack-protection (= 4.2.1)
|
||||
sinatra (= 4.2.1)
|
||||
tilt (~> 2.0)
|
||||
tilt (2.9.0)
|
||||
|
||||
PLATFORMS
|
||||
aarch64-linux-gnu
|
||||
aarch64-linux-musl
|
||||
arm-linux-gnu
|
||||
arm-linux-musl
|
||||
arm64-darwin
|
||||
ruby
|
||||
x86-linux-gnu
|
||||
x86-linux-musl
|
||||
x86_64-darwin
|
||||
x86_64-linux-gnu
|
||||
x86_64-linux-musl
|
||||
|
||||
DEPENDENCIES
|
||||
puma (~> 8.0)
|
||||
rerun
|
||||
sinatra (~> 4.2)
|
||||
sinatra-contrib (~> 4.2)
|
||||
|
||||
CHECKSUMS
|
||||
base64 (0.3.0) sha256=27337aeabad6ffae05c265c450490628ef3ebd4b67be58257393227588f5a97b
|
||||
bundler (4.0.18) sha256=02d9a17429de1847b4e0c9f27a9ee4b20c0a74c0a641b4e77195d6019e3618ac
|
||||
ffi (1.17.4) sha256=bcd1642e06f0d16fc9e09ac6d49c3a7298b9789bcb58127302f934e437d60acf
|
||||
ffi (1.17.4-aarch64-linux-gnu) sha256=b208f06f91ffd8f5e1193da3cae3d2ccfc27fc36fba577baf698d26d91c080df
|
||||
ffi (1.17.4-aarch64-linux-musl) sha256=9286b7a615f2676245283aef0a0a3b475ae3aae2bb5448baace630bb77b91f39
|
||||
ffi (1.17.4-arm-linux-gnu) sha256=d6dbddf7cb77bf955411af5f187a65b8cd378cb003c15c05697f5feee1cb1564
|
||||
ffi (1.17.4-arm-linux-musl) sha256=9d4838ded0465bef6e2426935f6bcc93134b6616785a84ffd2a3d82bc3cf6f95
|
||||
ffi (1.17.4-arm64-darwin) sha256=19071aaf1419251b0a46852abf960e77330a3b334d13a4ab51d58b31a937001b
|
||||
ffi (1.17.4-x86-linux-gnu) sha256=38e150df5f4ca555e25beca4090823ae09657bceded154e3c52f8631c1ed72cf
|
||||
ffi (1.17.4-x86-linux-musl) sha256=fbeec0fc7c795bcf86f623bb18d31ea1820f7bd580e1703a3d3740d527437809
|
||||
ffi (1.17.4-x86_64-darwin) sha256=aa70390523cf3235096cf64962b709b4cfbd5c082a2cb2ae714eb0fe2ccda496
|
||||
ffi (1.17.4-x86_64-linux-gnu) sha256=9d3db14c2eae074b382fa9c083fe95aec6e0a1451da249eab096c34002bc752d
|
||||
ffi (1.17.4-x86_64-linux-musl) sha256=3fdf9888483de005f8ef8d1cf2d3b20d86626af206cbf780f6a6a12439a9c49e
|
||||
listen (3.10.0) sha256=c6e182db62143aeccc2e1960033bebe7445309c7272061979bb098d03760c9d2
|
||||
logger (1.7.0) sha256=196edec7cc44b66cfb40f9755ce11b392f21f7967696af15d274dde7edff0203
|
||||
multi_json (1.21.1) sha256=e6126a31808e3b4d19f483c775ceac34df190dffa62adfb63a165ee14ba68080
|
||||
mustermann (3.1.1) sha256=4c6170c7234d5499c345562ba7c7dfe73e1754286dcc1abb053064d66a127198
|
||||
nio4r (2.7.5) sha256=6c90168e48fb5f8e768419c93abb94ba2b892a1d0602cb06eef16d8b7df1dca1
|
||||
puma (8.0.2) sha256=c8ed871dfbbe66448ea9ffd46692342d9804d4071522b52b5331b7b6e7b686fb
|
||||
rack (3.2.7) sha256=93e13e1c24f93556671d85d2d79fa228c3485815c50d7e2f265b5330c6528fb7
|
||||
rack-protection (4.2.1) sha256=cf6e2842df8c55f5e4d1a4be015e603e19e9bc3a7178bae58949ccbb58558bac
|
||||
rack-session (2.1.2) sha256=595434f8c0c3473ae7d7ac56ecda6cc6dfd9d37c0b2b5255330aa1576967ffe8
|
||||
rb-fsevent (0.11.2) sha256=43900b972e7301d6570f64b850a5aa67833ee7d87b458ee92805d56b7318aefe
|
||||
rb-inotify (0.11.1) sha256=a0a700441239b0ff18eb65e3866236cd78613d6b9f78fea1f9ac47a85e47be6e
|
||||
rerun (0.14.0) sha256=996a5af2b2b34dcb30146c6c728addab9113e07c119003370daa9bf27feb88fd
|
||||
sinatra (4.2.1) sha256=b7aeb9b11d046b552972ade834f1f9be98b185fa8444480688e3627625377080
|
||||
sinatra-contrib (4.2.1) sha256=10d091c944d268aa910c618ea40a3c3ebe0533e6e32990d84af92235a3d26b4a
|
||||
tilt (2.9.0) sha256=da5735d0280bba96e9a91041bb14aee435ccad5c17b0fa519249ae543d9aa3a5
|
||||
|
||||
BUNDLED WITH
|
||||
4.0.18
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
= MapTool
|
||||
:toc:
|
||||
:toclevels: 2
|
||||
:source-highlighter: rouge
|
||||
|
||||
A mapping application backend written in Ruby with Sinatra, optionally
|
||||
wrapped as a native desktop app with Tauri.
|
||||
|
||||
The project's shape is still open — this is the initial scaffold.
|
||||
|
||||
== Status
|
||||
|
||||
Early scaffold. The web application serves a basic Leaflet map; the
|
||||
desktop shell boots the same server inside a native window.
|
||||
|
||||
== Requirements
|
||||
|
||||
* Ruby (see `.ruby-version`) and Bundler
|
||||
* Rust and the Tauri CLI, only if you want to build the desktop shell
|
||||
(see `docs/development.adoc`)
|
||||
|
||||
== Getting started
|
||||
|
||||
[source,shell]
|
||||
----
|
||||
bundle install
|
||||
bundle exec puma -C config/puma.rb
|
||||
----
|
||||
|
||||
Then open http://127.0.0.1:4567 in a browser.
|
||||
|
||||
== Documentation
|
||||
|
||||
* link:docs/architecture.adoc[Architecture]
|
||||
* link:docs/development.adoc[Development guide]
|
||||
@@ -0,0 +1,17 @@
|
||||
require "sinatra/base"
|
||||
require "sinatra/json"
|
||||
|
||||
module Maptool
|
||||
class App < Sinatra::Base
|
||||
set :public_folder, File.join(__dir__, "public")
|
||||
set :views, File.join(__dir__, "views")
|
||||
|
||||
get "/" do
|
||||
erb :index
|
||||
end
|
||||
|
||||
get "/api/health" do
|
||||
json status: "ok"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
bind "tcp://127.0.0.1:#{ENV.fetch('PORT', 4567)}"
|
||||
|
||||
environment ENV.fetch("RACK_ENV", "development")
|
||||
|
||||
workers 0
|
||||
threads 1, 4
|
||||
@@ -0,0 +1,81 @@
|
||||
= Architecture
|
||||
:toc:
|
||||
:toclevels: 2
|
||||
|
||||
== Overview
|
||||
|
||||
MapTool is a Sinatra web application. The desktop build does not
|
||||
reimplement anything natively — it wraps the same Sinatra app in a
|
||||
https://tauri.app[Tauri] window, which is the standard way to ship a
|
||||
non-JavaScript backend as a desktop app with Tauri: the Rust shell owns
|
||||
the native window and starts the web server as a local process; the
|
||||
window then simply loads `http://127.0.0.1:4567` as if it were a
|
||||
regular page.
|
||||
|
||||
[source]
|
||||
----
|
||||
+----------------------------+
|
||||
| Tauri window (WebView) |
|
||||
| loads http://127.0.0.1:PORT
|
||||
+--------------+-------------+
|
||||
|
|
||||
v
|
||||
+----------------------------+
|
||||
| Sinatra app (Puma) |
|
||||
| app.rb / config.ru |
|
||||
+----------------------------+
|
||||
----
|
||||
|
||||
== Directory layout
|
||||
|
||||
[cols="1,3"]
|
||||
|===
|
||||
| Path | Purpose
|
||||
|
||||
| `app.rb`, `config.ru`
|
||||
| Sinatra application and Rack entry point.
|
||||
|
||||
| `config/puma.rb`
|
||||
| Puma server configuration (binds to `127.0.0.1` only — the app is
|
||||
local-only, not exposed on the network).
|
||||
|
||||
| `public/`, `views/`
|
||||
| Frontend assets and Sinatra templates. The map view uses Leaflet.
|
||||
|
||||
| `src-tauri/`
|
||||
| The Tauri (Rust) desktop shell.
|
||||
|
||||
| `docs/`
|
||||
| Project documentation, in AsciiDoc.
|
||||
|===
|
||||
|
||||
== Desktop shell (Tauri)
|
||||
|
||||
In *development*, `src-tauri/tauri.conf.json` sets `beforeDevCommand`
|
||||
to start Puma, and `devUrl` points the window at it. Running the dev
|
||||
build (see `docs/development.adoc`) starts both together.
|
||||
|
||||
In a *packaged build* there is no `beforeDevCommand` hook, so
|
||||
`src-tauri/src/lib.rs` starts the server itself (`bundle exec puma`)
|
||||
next to the bundled resources when the app launches, and stops it when
|
||||
the window closes.
|
||||
|
||||
=== Known limitation: production packaging
|
||||
|
||||
The packaged-build server spawn currently assumes a Ruby + Bundler
|
||||
installation already present on the machine running the app. That is
|
||||
fine for internal or developer builds, but not for a distributable,
|
||||
self-contained desktop app.
|
||||
|
||||
Shipping a real self-contained build would mean embedding a Ruby
|
||||
runtime as a Tauri https://tauri.app/develop/sidecar/[sidecar] binary
|
||||
(for example, produced with https://github.com/tebako/tebako[tebako]),
|
||||
instead of relying on the system Ruby. That decision — and the
|
||||
resulting sidecar build step — is not implemented yet and should be
|
||||
revisited before any real distribution build.
|
||||
|
||||
== Networking
|
||||
|
||||
The Sinatra server only binds to `127.0.0.1`. It is not meant to be
|
||||
reachable from other machines; the Tauri window talks to it over
|
||||
loopback only.
|
||||
@@ -0,0 +1,77 @@
|
||||
= Development guide
|
||||
:toc:
|
||||
:toclevels: 2
|
||||
|
||||
== Web app only
|
||||
|
||||
[source,shell]
|
||||
----
|
||||
bundle install
|
||||
bundle exec puma -C config/puma.rb
|
||||
----
|
||||
|
||||
Open http://127.0.0.1:4567. For auto-reload during development, run
|
||||
via the `rerun` gem instead:
|
||||
|
||||
[source,shell]
|
||||
----
|
||||
bundle exec rerun -- bundle exec puma -C config/puma.rb
|
||||
----
|
||||
|
||||
== Desktop shell (Tauri)
|
||||
|
||||
=== Prerequisites
|
||||
|
||||
* Rust (stable) and the Tauri CLI: `cargo install tauri-cli --version "^2"`
|
||||
* Ruby + Bundler, with gems installed (`bundle install` in the project
|
||||
root)
|
||||
* Platform build tools required by Tauri itself:
|
||||
** *Linux*: WebKitGTK and GTK development packages, e.g. on
|
||||
Debian/Ubuntu:
|
||||
+
|
||||
[source,shell]
|
||||
----
|
||||
sudo apt install libwebkit2gtk-4.1-dev libjavascriptcoregtk-4.1-dev \
|
||||
libgtk-3-dev libsoup-3.0-dev build-essential
|
||||
----
|
||||
** *macOS*: Xcode command line tools.
|
||||
** *Windows*: the WebView2 runtime (preinstalled on current Windows) and
|
||||
the MSVC build tools.
|
||||
|
||||
See the upstream https://tauri.app/start/prerequisites/[Tauri
|
||||
prerequisites] page for the current package names on your platform.
|
||||
|
||||
=== Running in development
|
||||
|
||||
[source,shell]
|
||||
----
|
||||
cd src-tauri
|
||||
cargo tauri dev
|
||||
----
|
||||
|
||||
This runs `beforeDevCommand` (starts Puma on `127.0.0.1:4567`) and
|
||||
opens a native window pointed at it, per `src-tauri/tauri.conf.json`.
|
||||
|
||||
=== Building
|
||||
|
||||
[source,shell]
|
||||
----
|
||||
cd src-tauri
|
||||
cargo tauri build
|
||||
----
|
||||
|
||||
Requires `Gemfile.lock` to exist (`bundle install` beforehand), since
|
||||
the Ruby app files are embedded into the bundle as resources. See
|
||||
`docs/architecture.adoc` for the current limitation around this build
|
||||
still depending on a system Ruby installation on the target machine.
|
||||
|
||||
=== Regenerating icons
|
||||
|
||||
Desktop icons live in `src-tauri/icons/`. To regenerate them from a
|
||||
new source image (at least 1024x1024 PNG):
|
||||
|
||||
[source,shell]
|
||||
----
|
||||
cd src-tauri
|
||||
cargo tauri icon path/to/source.png
|
||||
----
|
||||
@@ -0,0 +1,9 @@
|
||||
html, body {
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
#map {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
const map = L.map("map").setView([48.1486, 17.1077], 13);
|
||||
|
||||
L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
|
||||
maxZoom: 19,
|
||||
attribution: "© OpenStreetMap contributors",
|
||||
}).addTo(map);
|
||||
Generated
+4495
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,22 @@
|
||||
[package]
|
||||
name = "maptool"
|
||||
version = "0.1.0"
|
||||
description = "Desktop shell for the MapTool mapping application"
|
||||
edition = "2021"
|
||||
rust-version = "1.77"
|
||||
|
||||
[lib]
|
||||
name = "maptool_lib"
|
||||
crate-type = ["staticlib", "cdylib", "rlib"]
|
||||
|
||||
[build-dependencies]
|
||||
tauri-build = { version = "2", features = [] }
|
||||
|
||||
[dependencies]
|
||||
tauri = { version = "2", features = [] }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
|
||||
[[bin]]
|
||||
name = "maptool"
|
||||
path = "src/main.rs"
|
||||
@@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
tauri_build::build()
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 5.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.4 KiB |
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
@@ -0,0 +1,59 @@
|
||||
#[cfg(not(debug_assertions))]
|
||||
use std::process::{Child, Command};
|
||||
#[cfg(not(debug_assertions))]
|
||||
use std::sync::Mutex;
|
||||
|
||||
#[cfg(not(debug_assertions))]
|
||||
use tauri::Manager;
|
||||
|
||||
#[cfg(not(debug_assertions))]
|
||||
struct ServerProcess(Mutex<Option<Child>>);
|
||||
|
||||
pub fn run() {
|
||||
let builder = tauri::Builder::default();
|
||||
|
||||
#[cfg(not(debug_assertions))]
|
||||
let builder = builder.setup(|app| {
|
||||
let child = spawn_server(&app.handle())
|
||||
.expect("failed to start the Sinatra server (is Ruby/Bundler installed?)");
|
||||
app.manage(ServerProcess(Mutex::new(Some(child))));
|
||||
Ok(())
|
||||
});
|
||||
|
||||
let app = builder
|
||||
.build(tauri::generate_context!())
|
||||
.expect("error while building the tauri application");
|
||||
|
||||
app.run(|_app_handle, event| {
|
||||
#[cfg(not(debug_assertions))]
|
||||
if let tauri::RunEvent::ExitRequested { .. } = event {
|
||||
if let Some(state) = _app_handle.try_state::<ServerProcess>() {
|
||||
if let Some(mut child) = state.0.lock().unwrap().take() {
|
||||
let _ = child.kill();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// In development, `beforeDevCommand` (see tauri.conf.json) already starts the
|
||||
// Sinatra server, so the window just points at it. In a packaged build there
|
||||
// is no such hook, so the shell starts the server itself, next to the bundled
|
||||
// resources, and stops it again when the window closes.
|
||||
//
|
||||
// NOTE: this assumes a Ruby + Bundler installation on the target machine.
|
||||
// Producing a fully self-contained bundle (no external Ruby dependency)
|
||||
// requires embedding a Ruby runtime as a sidecar (e.g. via tebako) — see
|
||||
// docs/architecture.adoc for the open follow-up.
|
||||
#[cfg(not(debug_assertions))]
|
||||
fn spawn_server(app: &tauri::AppHandle) -> std::io::Result<Child> {
|
||||
let resource_dir = app
|
||||
.path()
|
||||
.resource_dir()
|
||||
.expect("failed to resolve the resource directory");
|
||||
|
||||
Command::new("bundle")
|
||||
.args(["exec", "puma", "-C", "config/puma.rb"])
|
||||
.current_dir(resource_dir)
|
||||
.spawn()
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// Prevents an additional console window on Windows in release builds.
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
fn main() {
|
||||
maptool_lib::run();
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"$schema": "https://schema.tauri.app/config/2",
|
||||
"productName": "MapTool",
|
||||
"version": "0.1.0",
|
||||
"identifier": "net.priesol.maptool",
|
||||
"build": {
|
||||
"beforeDevCommand": "bundle exec puma -C ../config/puma.rb",
|
||||
"devUrl": "http://127.0.0.1:4567",
|
||||
"frontendDist": "http://127.0.0.1:4567"
|
||||
},
|
||||
"app": {
|
||||
"windows": [
|
||||
{
|
||||
"title": "MapTool",
|
||||
"width": 1200,
|
||||
"height": 800,
|
||||
"minWidth": 800,
|
||||
"minHeight": 600
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
"csp": null
|
||||
}
|
||||
},
|
||||
"bundle": {
|
||||
"active": true,
|
||||
"targets": "all",
|
||||
"icon": [
|
||||
"icons/32x32.png",
|
||||
"icons/128x128.png",
|
||||
"icons/128x128@2x.png",
|
||||
"icons/icon.icns",
|
||||
"icons/icon.ico"
|
||||
],
|
||||
"resources": {
|
||||
"../Gemfile": "Gemfile",
|
||||
"../Gemfile.lock": "Gemfile.lock",
|
||||
"../app.rb": "app.rb",
|
||||
"../config.ru": "config.ru",
|
||||
"../config/*": "config/",
|
||||
"../public/*": "public/",
|
||||
"../views/*": "views/"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<div id="map"></div>
|
||||
@@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>MapTool</title>
|
||||
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css">
|
||||
<link rel="stylesheet" href="/css/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<%= yield %>
|
||||
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
|
||||
<script src="/js/map.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user