Skip to content

Commit

Permalink
Merge branch 'master' into themes
Browse files Browse the repository at this point in the history
  • Loading branch information
nakajimayoshi authored Jul 11, 2023
2 parents 2f2a836 + 10d1ad2 commit b15bec8
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 21 deletions.
87 changes: 87 additions & 0 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ rust-version = "1.57"
tauri-build = {version = "1.2", features = [] }

[dependencies]
serde_json = "1.0"
discord-rich-presence = "0.2.3"
log = "^0.4"
matchit = "0.7.0"
notify = { version = "5.0.0", features = ["serde"] }
notify-debouncer-mini = "0.2.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tauri = { version = "1.2", features = ["api-all"] }
tauri-plugin-log = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1", features = ["colored"] }
uuid = { version = "1.2.2", features = ["v4", "fast-rng", "serde"] }
notify = { version = "5.0.0", features = ["serde"] }
notify-debouncer-mini = "0.2.1"
matchit = "0.7.0"
discord-rich-presence = "0.2.3"
window-shadows = "0.2.1"

[features]
Expand Down
11 changes: 9 additions & 2 deletions src-tauri/src/discord.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use discord_rich_presence::activity::{Activity, Timestamps};
use discord_rich_presence::{DiscordIpc, DiscordIpcClient};
use log::{error, info};
use std::ops::DerefMut;
use std::sync::RwLock;
use std::time::{SystemTime, UNIX_EPOCH};
Expand All @@ -10,8 +11,14 @@ impl DiscordClient {
pub fn new() -> Self {
let mut discord = DiscordIpcClient::new("1046278806685622302").unwrap();
let ipc = match discord.connect() {
Ok(_) => Some(discord),
Err(_) => None,
Ok(_) => {
info!("Connected to Discord IPC");
Some(discord)
}
Err(err) => {
error!("{err}");
None
}
};

let client = DiscordClient(RwLock::new(ipc));
Expand Down
42 changes: 36 additions & 6 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,63 @@
windows_subsystem = "windows"
)]

use tauri::Manager;
use crate::discord::DiscordClient;
use crate::project::ActiveProject;
use crate::server::ResourceRouter;
use crate::watcher::FileWatcher;
use log::LevelFilter;
use tauri::Manager;
use tauri_plugin_log::fern::colors::{Color, ColoredLevelConfig};
use tauri_plugin_log::LogTarget;
use window_shadows::set_shadow;

pub mod discord;
pub mod project;
pub mod server;
pub mod watcher;
pub mod simvars;
pub mod watcher;

fn main() {
let log_color_config = ColoredLevelConfig::default()
.info(Color::Blue)
.debug(Color::Cyan)
.trace(Color::BrightWhite);

tauri::Builder::default()
.plugin(
tauri_plugin_log::Builder::default()
.format(move |out, message, record| {
out.finish(format_args!(
"{:<5} [{}] {}",
log_color_config.color(record.level()),
record.target(),
message,
));
})
.targets([LogTarget::LogDir, LogTarget::Stdout])
.level(if cfg!(debug_assertions) {
LevelFilter::Debug
} else {
LevelFilter::Info
})
.build(),
)
.setup(move |app| {
// Window shadow and (on Windows) rounded corners since we disabled `decorations`.
if cfg!(target_os = "windows") || cfg!(target_os = "linux") {
let window = app.get_window("main").unwrap();
set_shadow(&window, true).unwrap_or_default();
}

// Configure manage state here so that `tauri_plugin_log` can capture messages.
app.manage(ActiveProject::default());
app.manage(FileWatcher::default());
app.manage(ResourceRouter::new());
app.manage(DiscordClient::new());

Ok(())
})
.register_uri_scheme_protocol("ace", server::handle_ace_request)
.manage(ActiveProject::default())
.manage(FileWatcher::default())
.manage(ResourceRouter::new())
.manage(DiscordClient::new())
.invoke_handler(tauri::generate_handler![
project::commands::create_project,
project::commands::update_project,
Expand Down
25 changes: 17 additions & 8 deletions src-tauri/src/server.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::project::ActiveProject;
use log::{error, info};
use matchit::Router;
use std::error::Error;
use std::fs;
Expand Down Expand Up @@ -27,6 +28,7 @@ pub enum ResourceType {
}

pub fn handle_ace_request(app: &AppHandle<Wry>, req: &Request) -> Result<Response, Box<dyn Error>> {
info!("{} {}", req.method(), req.uri());
let resource_router = app.state::<ResourceRouter>().inner();
let active_project = app.state::<ActiveProject>().inner();

Expand All @@ -52,22 +54,29 @@ pub fn handle_ace_request(app: &AppHandle<Wry>, req: &Request) -> Result<Respons
.join(project.config.paths.html_ui.as_path())
.join(matched.params.get("path").unwrap()),
};
info!("Resolved to {:?} {}", matched.value, file_path.display());
match fs::read(file_path) {
Ok(data) => ResponseBuilder::new()
.status(200)
.header("Access-Control-Allow-Origin", "*")
.body(data)
.unwrap(),
Err(_) => ResponseBuilder::new()
.status(404)
.body("Unknown path".as_bytes().to_vec())
.unwrap(),
Err(err) => {
error!("{err}");
ResponseBuilder::new()
.status(404)
.body("Unknown path".as_bytes().to_vec())
.unwrap()
}
}
}
Err(_) => ResponseBuilder::new()
.status(404)
.body("Unknown path".as_bytes().to_vec())
.unwrap(),
Err(err) => {
error!("{err}");
ResponseBuilder::new()
.status(404)
.body("Unknown path".as_bytes().to_vec())
.unwrap()
}
};

Ok(response)
Expand Down

0 comments on commit b15bec8

Please sign in to comment.