Skip to content

Commit

Permalink
#215 Tauri
Browse files Browse the repository at this point in the history
#215 icons, tray icon, menu

#215 make atomic-server also a library

#215 tauri menu refactor


#251 WIP
  • Loading branch information
joepio committed Nov 24, 2021
1 parent d6363e9 commit a714f2f
Show file tree
Hide file tree
Showing 35 changed files with 2,654 additions and 277 deletions.
Binary file modified .DS_Store
Binary file not shown.
2,522 changes: 2,265 additions & 257 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]
members = [
"server",
"cli",
"lib",
"server",
"cli",
"lib",
"src-tauri",
]
10 changes: 9 additions & 1 deletion server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ name = "atomic-server"
repository = "https://github.com/joepio/atomic-data-rust"
version = "0.29.0"

[lib]
name = "atomic_server_lib"
path = "src/lib.rs"

[[bin]]
name = "atomic_server"
path = "src/bin.rs"

[dependencies]
actix = "0.10.0"
actix-cors = "0.5.4"
Expand Down Expand Up @@ -58,7 +66,7 @@ version = "1.4.0"

[dependencies.tray-item]
optional = true
version = "0.4.0-alpha"
version = "0.6.0"

[dev-dependencies]
# Currently only used for testing, the other actix is included in the web crate
Expand Down
8 changes: 5 additions & 3 deletions server/src/appstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,20 @@ pub struct AppState {
}

/// Creates the server context.
/// Initializes a store on disk.
/// Initializes or opens a store on disk.
/// Initializes logging.
/// Creates a new agent, if neccessary.
pub fn init(config: Config) -> AtomicServerResult<AppState> {
// Enable logging, but hide most tantivy logs
std::env::set_var("RUST_LOG", "info,tantivy=warn");
env_logger::init();
const VERSION: &str = env!("CARGO_PKG_VERSION");
log::info!("Atomic-server {}. Use --help for more options. Visit https://docs.atomicdata.dev and https://github.com/joepio/atomic-data-rust.", VERSION);

// Check if atomic-server is already running somwehere, and try to stop it. It's not a problem if things go wrong here, so errors are simply logged.
let _ = crate::process::terminate_existing_processes(&config)
.map_err(|e| log::error!("Could not check for running instance: {}", e));

const VERSION: &str = env!("CARGO_PKG_VERSION");
log::info!("Atomic-server {}. Use --help for more options. Visit https://docs.atomicdata.dev and https://github.com/joepio/atomic-data-rust.", VERSION);
log::info!("Opening database...");
let store = atomic_lib::Db::init(&config.store_path, config.local_base_url.clone())?;
if config.initialize {
Expand Down
15 changes: 7 additions & 8 deletions server/src/main.rs → server/src/bin.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use atomic_lib::{errors::AtomicResult, Storelike};
use std::{fs::File, io::Write};

mod actor_messages;
mod appstate;
mod commit_monitor;
mod config;
pub mod config;
mod content_types;
mod errors;
mod handlers;
Expand All @@ -11,20 +14,16 @@ mod https;
mod jsonerrors;
mod process;
mod routes;
pub mod serve;
// #[cfg(feature = "search")]
mod search;
mod serve;
#[cfg(test)]
mod tests;
#[cfg(feature = "desktop")]
mod tray_icon;

use atomic_lib::Storelike;
use errors::AtomicServerResult;
use std::{fs::File, io::Write};

#[actix_web::main]
async fn main() -> AtomicServerResult<()> {
async fn main() -> AtomicResult<()> {
// Parse CLI commands, env vars
let config = config::init().map_err(|e| format!("Initialization failed: {}", e))?;

Expand Down Expand Up @@ -79,6 +78,6 @@ async fn main() -> AtomicServerResult<()> {
println!("Sucesfully created {}", pathstr);
Ok(())
}
None => crate::serve::serve(config).await,
None => serve::serve(&config).await,
}
}
20 changes: 20 additions & 0 deletions server/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
mod actor_messages;
mod appstate;
mod commit_monitor;
pub mod config;
mod content_types;
mod errors;
mod handlers;
mod helpers;
#[cfg(feature = "https")]
mod https;
mod jsonerrors;
mod process;
mod routes;
pub mod serve;
// #[cfg(feature = "search")]
mod search;
#[cfg(test)]
mod tests;
#[cfg(feature = "desktop")]
mod tray_icon;
9 changes: 4 additions & 5 deletions server/src/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::sync::Mutex;
use crate::errors::AtomicServerResult;

/// Start the server
pub async fn serve(config: crate::config::Config) -> AtomicServerResult<()> {
pub async fn serve(config: &crate::config::Config) -> AtomicResult<()> {
// Setup the database and more
let appstate = crate::appstate::init(config.clone())?;

Expand Down Expand Up @@ -77,9 +77,9 @@ pub async fn serve(config: crate::config::Config) -> AtomicServerResult<()> {
if std::fs::File::open(&config.cert_path).is_err()
|| crate::https::check_expiration_certs()
{
crate::https::cert_init_server(&config).await?;
crate::https::cert_init_server(config).await?;
}
let https_config = crate::https::get_https_config(&config)
let https_config = crate::https::get_https_config(config)
.expect("HTTPS TLS Configuration with Let's Encrypt failed.");
let endpoint = format!("{}:{}", config.opts.ip, config.opts.port_https);
println!("{}", message);
Expand All @@ -101,8 +101,7 @@ pub async fn serve(config: crate::config::Config) -> AtomicServerResult<()> {
.run()
.await?;
}
crate::process::remove_pid(&config)?;

crate::process::remove_pid(config)?;
Ok(())
}

Expand Down
27 changes: 27 additions & 0 deletions server/static/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta content="width=device-width,initial-scale=1" name="viewport">
<meta content="The easiest way to create, share and model Linked Atomic Data." name="description">
<link href="https://joepio.github.io/atomic-data-browser/icon.png" rel="icon" type="image/png">
<link href="https://joepio.github.io/atomic-data-browser/apple-touch-icon.png" rel="apple-touch-icon" sizes="180x180">
<link href="https://joepio.github.io/atomic-data-browser/favicon-32x32.png" rel="icon" sizes="32x32" type="image/png">
<link href="https://joepio.github.io/atomic-data-browser/favicon-16x16.png" rel="icon" sizes="16x16" type="image/png">
<link href="https://joepio.github.io/atomic-data-browser/site.webmanifest" rel="manifest">
<link color="#1e43a3" href="https://joepio.github.io/atomic-data-browser/safari-pinned-tab.svg" rel="mask-icon">
<meta content="#ffffff" name="msapplication-TileColor">
<meta content="#ffffff" name="theme-color">
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="yes" name="mobile-web-app-capable">
<title>Atomic Data Browser</title>
</head>

<body>
<div id="root"></div>
<script src="https://joepio.github.io/atomic-data-browser/dist/index.js" type="module"></script>
<script>{ script }</script>
</body>

</html>
4 changes: 4 additions & 0 deletions src-tauri/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Generated by Cargo
# will have compiled files and executables
/target/
WixTools
34 changes: 34 additions & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[package]
authors = ["you"]
build = "src/build.rs"
default-run = "atomic-server-tauri"
description = "Atomic Server"
edition = "2018"
license = ""
name = "atomic-server-tauri"
repository = ""
version = "0.28.3"

[build-dependencies]
[build-dependencies.tauri-build]
version = "1.0.0-beta.4"

[dependencies]
actix-rt = "1.1.1"
serde_json = "1.0"

[dependencies.atomic-server]
path = "../server"
version = "0.28.2"

[dependencies.serde]
features = ["derive"]
version = "1.0"

[dependencies.tauri]
features = ["api-all", "system-tray"]
version = "1.0.0-beta.8"

[features]
custom-protocol = ["tauri/custom-protocol"]
default = ["custom-protocol"]
8 changes: 8 additions & 0 deletions src-tauri/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Atomic-server Tauri

```sh
# install tauri
yarn global add @tauri/tauri-cli
# run dev server
tauri dev
```
Binary file added src-tauri/icons/128x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src-tauri/icons/128x128@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src-tauri/icons/32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src-tauri/icons/Square107x107Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src-tauri/icons/Square142x142Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src-tauri/icons/Square150x150Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src-tauri/icons/Square284x284Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src-tauri/icons/Square30x30Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src-tauri/icons/Square310x310Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src-tauri/icons/Square44x44Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src-tauri/icons/Square71x71Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src-tauri/icons/Square89x89Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src-tauri/icons/StoreLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src-tauri/icons/atomic-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src-tauri/icons/icon.icns
Binary file not shown.
Binary file added src-tauri/icons/icon.ico
Binary file not shown.
Binary file added src-tauri/icons/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions src-tauri/rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
max_width = 100
hard_tabs = false
tab_spaces = 2
newline_style = "Auto"
use_small_heuristics = "Default"
reorder_imports = true
reorder_modules = true
remove_nested_parens = true
edition = "2018"
merge_derives = true
use_try_shorthand = false
use_field_init_shorthand = false
force_explicit_abi = true
imports_granularity = "Crate"
3 changes: 3 additions & 0 deletions src-tauri/src/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
tauri_build::build()
}
30 changes: 30 additions & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
mod menu;
mod system_tray;

pub async fn test() {
println!("test local");
}

fn main() {
let ctx = tauri::generate_context!();

let config: atomic_server_lib::config::Config = atomic_server_lib::config::init()
.map_err(|e| format!("Initialization failed: {}", e))
.expect("failed init config");

// Find a way to combine actix and tauri runtimes...
{
// let config_clone = config.clone();
// atomic_server_lib::serve::serve(&config_clone);
}
tauri::Builder::default()
.menu(crate::menu::build(&ctx))
.on_menu_event(crate::menu::handle)
.system_tray(crate::system_tray::build())
.on_system_tray_event(move |e, h| {
let cfg = config.clone();
crate::system_tray::handle(e, h, &cfg)
})
.run(ctx)
.expect("Tauri Error.");
}
103 changes: 103 additions & 0 deletions src-tauri/src/menu.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
use tauri::{
api::shell, utils::assets::EmbeddedAssets, Context, CustomMenuItem, Menu, MenuItem, Submenu,
WindowMenuEvent,
};

/// Handle events on menu items
pub fn handle(event: WindowMenuEvent) {
let event_name = event.menu_item_id();
event.window().emit("menu", event_name).unwrap();
match event_name {
"Learn More" => {
shell::open(
"https://github.com/joepio/atomic-data-rust".to_string(),
None,
)
.unwrap();
}
_ => {}
}
}

/// Create the task bar menu items
pub fn build(ctx: &Context<EmbeddedAssets>) -> Menu {
let menu = Menu::new()
.add_default_app_submenu(&ctx.package_info().name)
.add_default_edit_submenu()
.add_default_view_submenu()
.add_default_window_submenu()
.add_submenu(Submenu::new(
"Help",
Menu::new().add_item(CustomMenuItem::new("github", "GitHub")),
));
menu
}

trait AddDefaultSubmenus {
fn add_default_app_submenu(self, app_name: &str) -> Self;
fn add_default_file_submenu(self) -> Self;
fn add_default_edit_submenu(self) -> Self;
fn add_default_view_submenu(self) -> Self;
fn add_default_window_submenu(self) -> Self;
}

impl AddDefaultSubmenus for Menu {
fn add_default_app_submenu(self, app_name: &str) -> Menu {
#[cfg(target_os = "macos")]
return self.add_submenu(Submenu::new(
app_name.to_string(),
Menu::new()
.add_native_item(MenuItem::About(app_name.to_string()))
.add_native_item(MenuItem::Separator)
.add_native_item(MenuItem::Hide)
.add_native_item(MenuItem::HideOthers)
.add_native_item(MenuItem::ShowAll)
.add_native_item(MenuItem::Separator)
.add_native_item(MenuItem::Quit),
));
#[cfg(not(target_os = "macos"))]
return self;
}
fn add_default_file_submenu(self) -> Menu {
self.add_submenu(Submenu::new(
"File",
Menu::new().add_native_item(MenuItem::CloseWindow),
))
}

fn add_default_edit_submenu(self) -> Menu {
self.add_submenu(Submenu::new("Edit", {
let mut menu = Menu::new()
.add_native_item(MenuItem::Undo)
.add_native_item(MenuItem::Redo)
.add_native_item(MenuItem::Separator)
.add_native_item(MenuItem::Cut)
.add_native_item(MenuItem::Copy)
.add_native_item(MenuItem::Paste);
#[cfg(not(target_os = "macos"))]
{
menu = menu.add_native_item(MenuItem::Separator);
}
menu = menu.add_native_item(MenuItem::SelectAll);
// macOS automatically adds "Start Dictation" and "Emoji & Symbols" to
// the bottom of the Edit menu
menu
}))
}

fn add_default_view_submenu(self) -> Menu {
self.add_submenu(Submenu::new(
"View",
Menu::new().add_native_item(MenuItem::EnterFullScreen),
))
}

fn add_default_window_submenu(self) -> Menu {
self.add_submenu(Submenu::new(
"Window",
Menu::new()
.add_native_item(MenuItem::Minimize)
.add_native_item(MenuItem::Zoom),
))
}
}
Loading

0 comments on commit a714f2f

Please sign in to comment.