Skip to content

Commit

Permalink
Merge pull request #62 from pacholoamit/feat/add-api
Browse files Browse the repository at this point in the history
feat/add api
  • Loading branch information
pacholoamit authored May 11, 2023
2 parents 2c82da1 + 28ae4d0 commit d86baa4
Show file tree
Hide file tree
Showing 27 changed files with 361 additions and 108 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# env

.env


# Logs
logs
*.log
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file. This projec

## 0.3.6-rc

- Updated `tauri` to `1.3`
- Updated dependencies

## 0.3.5

Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"dependencies": {
"@emotion/react": "^11.10.8",
"@mantine/core": "^6.0.10",
"@mantine/form": "^6.0.10",
"@mantine/hooks": "^6.0.10",
"@mantine/notifications": "^6.0.10",
"@tabler/icons-react": "^2.17.0",
Expand All @@ -22,12 +23,14 @@
"lodash.sortby": "^4.7.0",
"luxon": "^3.3.0",
"mantine-datatable": "^2.4.15",
"pocketbase": "^0.14.4",
"react": "^18.2.0",
"react-apexcharts": "^1.4.0",
"react-chartjs-2": "^5.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.11.1",
"tauri-plugin-log-api": "https://github.com/tauri-apps/tauri-plugin-log"
"tauri-plugin-log-api": "https://github.com/tauri-apps/tauri-plugin-log",
"tauri-plugin-store": "https://github.com/tauri-apps/tauri-plugin-store"
},
"devDependencies": {
"@tauri-apps/cli": "^1.3.0",
Expand Down
86 changes: 15 additions & 71 deletions src-tauri/Cargo.lock

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

6 changes: 3 additions & 3 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ chrono = {version = "0.4.23", features= ["serde"] }
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.2.3", features = ["api-all", "system-tray", "updater"] }
sysinfo = "0.28.4"
sysinfo = "0.29.0"
tauri-plugin-log = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "dev" }
tauri-plugin-store = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
log = "^0.4"
notify = { version = "5.1.0", default-features = false, features = ["macos_kqueue"] }
# log4rs = "1.2.0"




Expand Down
49 changes: 40 additions & 9 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,49 @@ mod models;
mod utils;

use app::AppState;
use log::info;
use log::{error, info};
use std::time::Duration;
use tauri::api::path::cache_dir;
use tauri::{CustomMenuItem, Manager, SystemTray, SystemTrayEvent, SystemTrayMenu};
use tauri::{api, CustomMenuItem, Manager, SystemTray, SystemTrayEvent, SystemTrayMenu};
use tauri_plugin_log::LogTarget;

use crate::models::Config;

fn setup_app() -> std::io::Result<()> {
let config_path = match api::path::config_dir().unwrap().to_str() {
Some(path) => format!("{}/{}", path, "config.json"),
None => String::from(""),
};

match std::fs::metadata(&config_path) {
Ok(_) => info!("Config file exists at: {}", &config_path),
Err(e) => {
error!("Error checking config file: {}", e);
info!("Attempting to create config file at: {}", &config_path);

let default = Config::default();
let default_config = serde_json::to_string_pretty(&default).unwrap();

std::fs::write(&config_path, default_config)?;
info!("Created config file at: {}", &config_path);
}
}

Ok(())
}

fn build_and_run_app(app: AppState) {
info!("Cache Directory: {:?}", cache_dir().unwrap());

let log_plugin = tauri_plugin_log::Builder::default()
.targets([LogTarget::Folder(cache_dir().unwrap()), LogTarget::Stdout])
.build();

let store_plugin = tauri_plugin_store::Builder::default().build();

tauri::Builder::default()
.plugin(
tauri_plugin_log::Builder::default()
.targets([LogTarget::Folder(cache_dir().unwrap()), LogTarget::Stdout])
.build(),
)
.plugin(log_plugin)
.plugin(store_plugin)
.setup(|app| {
let window = app.get_window("main").unwrap();
let state = AppState::new();
Expand Down Expand Up @@ -67,12 +95,15 @@ fn build_and_run_app(app: AppState) {
}
})
.manage(app)
.invoke_handler(tauri::generate_handler![app::kill_process])
.invoke_handler(tauri::generate_handler![app::kill_process,])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

fn main() {
fn main() -> std::io::Result<()> {
let app = AppState::new();
setup_app()?;
build_and_run_app(app);

Ok(())
}
10 changes: 5 additions & 5 deletions src-tauri/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::models::*;
use crate::utils::{current_time, get_percentage, round};
use std::str::{self, FromStr};
use sysinfo::{CpuExt, DiskExt, NetworkExt, Pid, ProcessExt, Signal, System, SystemExt};
use sysinfo::{CpuExt, DiskExt, NetworkExt, Pid, ProcessExt, System, SystemExt};

pub struct Metrics {
sys: System,
Expand Down Expand Up @@ -98,9 +98,9 @@ impl DisksTrait for Metrics {
None => "Unknown".to_owned(),
};

let disk_type = match disk.type_() {
sysinfo::DiskType::HDD => "HDD".to_owned(),
sysinfo::DiskType::SSD => "SSD".to_owned(),
let disk_type = match disk.kind() {
sysinfo::DiskKind::HDD => "HDD".to_owned(),
sysinfo::DiskKind::SSD => "SSD".to_owned(),
_ => "Unknown".to_owned(),
};
let file_system = match str::from_utf8(disk.file_system()) {
Expand Down Expand Up @@ -231,7 +231,7 @@ impl ProcessesTrait for Metrics {
None => return false,
};

process.kill_with(Signal::Kill).unwrap_or(false)
process.kill()
}
}

Expand Down
14 changes: 14 additions & 0 deletions src-tauri/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,17 @@ pub trait ProcessesTrait {
fn get_processes(&mut self) -> Vec<Process>;
fn kill_process(&mut self, pid: &str) -> bool;
}

#[derive(Debug, Serialize, Deserialize, Default)]
pub struct Config {
pub user: User,
}

#[derive(Debug, Serialize, Deserialize, Default)]
pub struct User {
pub email: String,
pub first_name: String,
pub last_name: String,
pub skipped_setup: bool,
pub user_hash: String,
}
46 changes: 44 additions & 2 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,49 @@
"iconAsTemplate": true
},
"allowlist": {
"all": true
"all": true,
"path": {
"all": true
},
"fs": {
"all": true,
"readFile": true,
"writeFile": true,
"readDir": true,
"copyFile": true,
"createDir": true,
"removeDir": true,
"removeFile": true,
"renameFile": true,
"exists": true,
"scope": [
"$APPCONFIG",
"$APPDATA",
"$APPLOCALDATA",
"$APPCACHE",
"$APPLOG",
"$AUDIO",
"$CACHE",
"$CONFIG",
"$DATA",
"$LOCALDATA",
"$DESKTOP",
"$DOCUMENT",
"$DOWNLOAD",
"$EXE",
"$FONT",
"$HOME",
"$PICTURE",
"$PUBLIC",
"$RUNTIME",
"$TEMPLATE",
"$VIDEO",
"$RESOURCE",
"$APP",
"$LOG",
"$TEMP"
]
}
},
"bundle": {
"active": true,
Expand Down Expand Up @@ -50,7 +92,7 @@
},
"updater": {
"active": true,
"endpoints": ["https://pachtop.pacholoamit.com/releases/pachtop/{{target}}/{{current_version}}"],
"endpoints": ["https://update.pachtop.com/releases/pachtop/{{target}}/{{current_version}}"],
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IEM0NkIyODA1NThCM0I0MUEKUldRYXRMTllCU2hyeE9mSUx0MElJN2N5VFo5TytFV1RwaUtoaytDNVdmajNQMmlseVlYMGYzeUkK"
},
"windows": [
Expand Down
9 changes: 9 additions & 0 deletions src/api/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Pocketbase from "pocketbase";
import { CreateAppUserInput, User } from "@/api/types";

const api = new Pocketbase(import.meta.env.VITE_API_URL);

export const createAppUser = async (input: CreateAppUserInput) => {
const appUser = await api.collection("app_users").create<User>(input); // Add type
return appUser;
};
2 changes: 2 additions & 0 deletions src/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "@/api/client";
export * from "@/api/types";
Loading

0 comments on commit d86baa4

Please sign in to comment.