init
24
.gitignore
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
7
.vscode/extensions.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"recommendations": [
|
||||
"Vue.volar",
|
||||
"tauri-apps.tauri-vscode",
|
||||
"rust-lang.rust-analyzer"
|
||||
]
|
||||
}
|
||||
7
README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# Tauri + Vue + TypeScript
|
||||
|
||||
This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
|
||||
|
||||
## Recommended IDE Setup
|
||||
|
||||
- [VS Code](https://code.visualstudio.com/) + [Vue - Official](https://marketplace.visualstudio.com/items?itemName=Vue.volar) + [Tauri](https://marketplace.visualstudio.com/items?itemName=tauri-apps.tauri-vscode) + [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer)
|
||||
14
index.html
Normal file
@@ -0,0 +1,14 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Tauri + Vue + Typescript App</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
33
package.json
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "chrono-snap",
|
||||
"private": true,
|
||||
"version": "0.1.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vue-tsc --noEmit && vite build",
|
||||
"preview": "vite preview",
|
||||
"tauri": "tauri"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": "^2",
|
||||
"@tauri-apps/plugin-autostart": "~2.5.1",
|
||||
"@tauri-apps/plugin-dialog": "~2.6.0",
|
||||
"@tauri-apps/plugin-fs": "~2.4.5",
|
||||
"@tauri-apps/plugin-opener": "^2",
|
||||
"@tauri-apps/plugin-store": "~2.4.2",
|
||||
"lucide-vue-next": "^0.577.0",
|
||||
"vue": "^3.5.13"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tailwindcss/vite": "^4.2.2",
|
||||
"@tauri-apps/cli": "^2",
|
||||
"@vitejs/plugin-vue": "^5.2.1",
|
||||
"autoprefixer": "^10.4.27",
|
||||
"postcss": "^8.5.8",
|
||||
"tailwindcss": "^4.2.2",
|
||||
"typescript": "~5.6.2",
|
||||
"vite": "^6.0.3",
|
||||
"vue-tsc": "^2.1.10"
|
||||
}
|
||||
}
|
||||
1599
pnpm-lock.yaml
generated
Normal file
6
public/tauri.svg
Normal file
@@ -0,0 +1,6 @@
|
||||
<svg width="206" height="231" viewBox="0 0 206 231" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M143.143 84C143.143 96.1503 133.293 106 121.143 106C108.992 106 99.1426 96.1503 99.1426 84C99.1426 71.8497 108.992 62 121.143 62C133.293 62 143.143 71.8497 143.143 84Z" fill="#FFC131"/>
|
||||
<ellipse cx="84.1426" cy="147" rx="22" ry="22" transform="rotate(180 84.1426 147)" fill="#24C8DB"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M166.738 154.548C157.86 160.286 148.023 164.269 137.757 166.341C139.858 160.282 141 153.774 141 147C141 144.543 140.85 142.121 140.558 139.743C144.975 138.204 149.215 136.139 153.183 133.575C162.73 127.404 170.292 118.608 174.961 108.244C179.63 97.8797 181.207 86.3876 179.502 75.1487C177.798 63.9098 172.884 53.4021 165.352 44.8883C157.82 36.3744 147.99 30.2165 137.042 27.1546C126.095 24.0926 114.496 24.2568 103.64 27.6274C92.7839 30.998 83.1319 37.4317 75.8437 46.1553C74.9102 47.2727 74.0206 48.4216 73.176 49.5993C61.9292 50.8488 51.0363 54.0318 40.9629 58.9556C44.2417 48.4586 49.5653 38.6591 56.679 30.1442C67.0505 17.7298 80.7861 8.57426 96.2354 3.77762C111.685 -1.01901 128.19 -1.25267 143.769 3.10474C159.348 7.46215 173.337 16.2252 184.056 28.3411C194.775 40.457 201.767 55.4101 204.193 71.404C206.619 87.3978 204.374 103.752 197.73 118.501C191.086 133.25 180.324 145.767 166.738 154.548ZM41.9631 74.275L62.5557 76.8042C63.0459 72.813 63.9401 68.9018 65.2138 65.1274C57.0465 67.0016 49.2088 70.087 41.9631 74.275Z" fill="#FFC131"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M38.4045 76.4519C47.3493 70.6709 57.2677 66.6712 67.6171 64.6132C65.2774 70.9669 64 77.8343 64 85.0001C64 87.1434 64.1143 89.26 64.3371 91.3442C60.0093 92.8732 55.8533 94.9092 51.9599 97.4256C42.4128 103.596 34.8505 112.392 30.1816 122.756C25.5126 133.12 23.9357 144.612 25.6403 155.851C27.3449 167.09 32.2584 177.598 39.7906 186.112C47.3227 194.626 57.153 200.784 68.1003 203.846C79.0476 206.907 90.6462 206.743 101.502 203.373C112.359 200.002 122.011 193.568 129.299 184.845C130.237 183.722 131.131 182.567 131.979 181.383C143.235 180.114 154.132 176.91 164.205 171.962C160.929 182.49 155.596 192.319 148.464 200.856C138.092 213.27 124.357 222.426 108.907 227.222C93.458 232.019 76.9524 232.253 61.3736 227.895C45.7948 223.538 31.8055 214.775 21.0867 202.659C10.3679 190.543 3.37557 175.59 0.949823 159.596C-1.47592 143.602 0.768139 127.248 7.41237 112.499C14.0566 97.7497 24.8183 85.2327 38.4045 76.4519ZM163.062 156.711L163.062 156.711C162.954 156.773 162.846 156.835 162.738 156.897C162.846 156.835 162.954 156.773 163.062 156.711Z" fill="#24C8DB"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.5 KiB |
1
public/vite.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 1.5 KiB |
7
src-tauri/.gitignore
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
/target/
|
||||
|
||||
# Generated by Tauri
|
||||
# will have schema files for capabilities auto-completion
|
||||
/gen/schemas
|
||||
7086
src-tauri/Cargo.lock
generated
Normal file
36
src-tauri/Cargo.toml
Normal file
@@ -0,0 +1,36 @@
|
||||
[package]
|
||||
name = "chrono-snap"
|
||||
version = "0.1.0"
|
||||
description = "A Tauri App"
|
||||
authors = ["you"]
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[lib]
|
||||
# The `_lib` suffix may seem redundant but it is necessary
|
||||
# to make the lib name unique and wouldn't conflict with the bin name.
|
||||
# This seems to be only an issue on Windows, see https://github.com/rust-lang/cargo/issues/8519
|
||||
name = "chrono_snap_lib"
|
||||
crate-type = ["staticlib", "cdylib", "rlib"]
|
||||
|
||||
[build-dependencies]
|
||||
tauri-build = { version = "2", features = [] }
|
||||
|
||||
[dependencies]
|
||||
tauri = { version = "2", features = ["tray-icon"] }
|
||||
tauri-plugin-opener = "2"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
tauri-plugin-store = "2"
|
||||
tauri-plugin-fs = "2"
|
||||
tauri-plugin-dialog = "2"
|
||||
xcap = "0.9.3"
|
||||
image = "0.25.10"
|
||||
chrono = "0.4.44"
|
||||
tokio = { version = "1.50.0", features = ["rt-multi-thread", "macros", "time"] }
|
||||
anyhow = "1.0.102"
|
||||
|
||||
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
|
||||
tauri-plugin-autostart = "2"
|
||||
|
||||
3
src-tauri/build.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
tauri_build::build()
|
||||
}
|
||||
10
src-tauri/capabilities/default.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"$schema": "../gen/schemas/desktop-schema.json",
|
||||
"identifier": "default",
|
||||
"description": "Capability for the main window",
|
||||
"windows": ["main"],
|
||||
"permissions": [
|
||||
"core:default",
|
||||
"opener:default"
|
||||
]
|
||||
}
|
||||
17
src-tauri/capabilities/desktop.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"identifier": "desktop-capability",
|
||||
"platforms": [
|
||||
"macOS",
|
||||
"windows",
|
||||
"linux"
|
||||
],
|
||||
"windows": [
|
||||
"main"
|
||||
],
|
||||
"permissions": [
|
||||
"autostart:default",
|
||||
"dialog:default",
|
||||
"store:default",
|
||||
"fs:default"
|
||||
]
|
||||
}
|
||||
BIN
src-tauri/icons/128x128.png
Normal file
|
After Width: | Height: | Size: 3.4 KiB |
BIN
src-tauri/icons/128x128@2x.png
Normal file
|
After Width: | Height: | Size: 6.8 KiB |
BIN
src-tauri/icons/32x32.png
Normal file
|
After Width: | Height: | Size: 974 B |
BIN
src-tauri/icons/Square107x107Logo.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
src-tauri/icons/Square142x142Logo.png
Normal file
|
After Width: | Height: | Size: 3.8 KiB |
BIN
src-tauri/icons/Square150x150Logo.png
Normal file
|
After Width: | Height: | Size: 3.9 KiB |
BIN
src-tauri/icons/Square284x284Logo.png
Normal file
|
After Width: | Height: | Size: 7.6 KiB |
BIN
src-tauri/icons/Square30x30Logo.png
Normal file
|
After Width: | Height: | Size: 903 B |
BIN
src-tauri/icons/Square310x310Logo.png
Normal file
|
After Width: | Height: | Size: 8.4 KiB |
BIN
src-tauri/icons/Square44x44Logo.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
src-tauri/icons/Square71x71Logo.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
src-tauri/icons/Square89x89Logo.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
src-tauri/icons/StoreLogo.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
src-tauri/icons/icon.icns
Normal file
BIN
src-tauri/icons/icon.ico
Normal file
|
After Width: | Height: | Size: 85 KiB |
BIN
src-tauri/icons/icon.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
216
src-tauri/src/engine.rs
Normal file
@@ -0,0 +1,216 @@
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::Arc;
|
||||
use tokio::time::{interval, Duration};
|
||||
use tauri::{AppHandle, Manager};
|
||||
use xcap::Monitor;
|
||||
use chrono::Local;
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
use tauri_plugin_store::StoreExt;
|
||||
|
||||
pub struct AppState {
|
||||
pub is_paused: Arc<AtomicBool>,
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn toggle_pause(state: tauri::State<'_, AppState>) -> bool {
|
||||
let current = state.is_paused.load(Ordering::SeqCst);
|
||||
state.is_paused.store(!current, Ordering::SeqCst);
|
||||
!current
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn get_pause_state(state: tauri::State<'_, AppState>) -> bool {
|
||||
state.is_paused.load(Ordering::SeqCst)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn get_timeline(date: String, base_dir: String) -> Vec<serde_json::Value> {
|
||||
let mut results = Vec::new();
|
||||
let dir_path = PathBuf::from(base_dir).join(date);
|
||||
|
||||
if !dir_path.exists() || !dir_path.is_dir() {
|
||||
return results;
|
||||
}
|
||||
|
||||
if let Ok(entries) = fs::read_dir(dir_path) {
|
||||
let mut paths: Vec<_> = entries
|
||||
.filter_map(|e| e.ok())
|
||||
.map(|e| e.path())
|
||||
.filter(|p| p.is_file() && p.extension().and_then(|s| s.to_str()) == Some("jpg"))
|
||||
.collect();
|
||||
|
||||
paths.sort();
|
||||
|
||||
for path in paths {
|
||||
if let Some(file_name) = path.file_stem().and_then(|s| s.to_str()) {
|
||||
// file_name format: "14-30-00" or "14-30-00_0"
|
||||
let time_str = file_name.replace("-", ":").replace("_", " ");
|
||||
results.push(serde_json::json!({
|
||||
"time": time_str,
|
||||
"path": path.to_string_lossy().to_string()
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
results
|
||||
}
|
||||
|
||||
pub fn start_engine(app: AppHandle) {
|
||||
let state = app.state::<AppState>();
|
||||
let is_paused = state.is_paused.clone();
|
||||
|
||||
// Start Cleanup routine
|
||||
let app_clone = app.clone();
|
||||
tauri::async_runtime::spawn(async move {
|
||||
// Run once on startup, then every 24 hours
|
||||
let mut ticker = interval(Duration::from_secs(60 * 60 * 24));
|
||||
loop {
|
||||
ticker.tick().await;
|
||||
if let Err(e) = run_cleanup(&app_clone).await {
|
||||
eprintln!("Cleanup error: {}", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
tauri::async_runtime::spawn(async move {
|
||||
// Every 60 seconds
|
||||
let mut ticker = interval(Duration::from_secs(60));
|
||||
|
||||
loop {
|
||||
ticker.tick().await;
|
||||
|
||||
if is_paused.load(Ordering::SeqCst) {
|
||||
continue;
|
||||
}
|
||||
|
||||
println!("Tick: capturing screen...");
|
||||
if let Err(e) = capture_screens(&app).await {
|
||||
eprintln!("Failed to capture screens: {}", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async fn run_cleanup(app: &AppHandle) -> anyhow::Result<()> {
|
||||
let store = match app.store("config.json") {
|
||||
Ok(s) => s,
|
||||
Err(_) => return Ok(()),
|
||||
};
|
||||
|
||||
let save_path_value = store.get("savePath");
|
||||
let save_path_str = match save_path_value {
|
||||
Some(serde_json::Value::String(s)) => s,
|
||||
_ => return Ok(()),
|
||||
};
|
||||
|
||||
let base_dir = PathBuf::from(save_path_str);
|
||||
if !base_dir.exists() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let retain_days = store
|
||||
.get("retainDays")
|
||||
.and_then(|v| v.as_u64())
|
||||
.unwrap_or(30) as i64;
|
||||
|
||||
let now = chrono::Local::now().naive_local().date();
|
||||
|
||||
if let Ok(entries) = fs::read_dir(&base_dir) {
|
||||
for entry in entries.flatten() {
|
||||
let path = entry.path();
|
||||
if path.is_dir() {
|
||||
if let Some(folder_name) = path.file_name().and_then(|n| n.to_str()) {
|
||||
if let Ok(folder_date) = chrono::NaiveDate::parse_from_str(folder_name, "%Y-%m-%d") {
|
||||
let duration = now.signed_duration_since(folder_date);
|
||||
if duration.num_days() > retain_days {
|
||||
let _ = fs::remove_dir_all(&path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn capture_screens(app: &AppHandle) -> anyhow::Result<()> {
|
||||
let store = match app.store("config.json") {
|
||||
Ok(s) => s,
|
||||
Err(_) => return Ok(()),
|
||||
};
|
||||
|
||||
let save_path_value = store.get("savePath");
|
||||
let save_path_str = match save_path_value {
|
||||
Some(serde_json::Value::String(s)) => s,
|
||||
_ => return Ok(()),
|
||||
};
|
||||
|
||||
let base_dir = PathBuf::from(save_path_str);
|
||||
if !base_dir.exists() {
|
||||
fs::create_dir_all(&base_dir)?;
|
||||
}
|
||||
|
||||
let merge_screens = store
|
||||
.get("mergeScreens")
|
||||
.and_then(|v| v.as_bool())
|
||||
.unwrap_or(false);
|
||||
|
||||
let monitors = Monitor::all()?;
|
||||
let now = Local::now();
|
||||
let timestamp = now.format("%H-%M-%S").to_string();
|
||||
let date_folder = now.format("%Y-%m-%d").to_string();
|
||||
let save_dir = base_dir.join(date_folder);
|
||||
|
||||
if !save_dir.exists() {
|
||||
fs::create_dir_all(&save_dir)?;
|
||||
}
|
||||
|
||||
if merge_screens {
|
||||
let mut min_x = i32::MAX;
|
||||
let mut min_y = i32::MAX;
|
||||
let mut max_x = i32::MIN;
|
||||
let mut max_y = i32::MIN;
|
||||
|
||||
for m in &monitors {
|
||||
let x = m.x()?;
|
||||
let y = m.y()?;
|
||||
let width = m.width()? as i32;
|
||||
let height = m.height()? as i32;
|
||||
|
||||
min_x = min_x.min(x);
|
||||
min_y = min_y.min(y);
|
||||
max_x = max_x.max(x + width);
|
||||
max_y = max_y.max(y + height);
|
||||
}
|
||||
|
||||
let total_width = (max_x - min_x) as u32;
|
||||
let total_height = (max_y - min_y) as u32;
|
||||
|
||||
let mut combined_image = image::RgbaImage::new(total_width, total_height);
|
||||
|
||||
for m in &monitors {
|
||||
let capture = m.capture_image()?;
|
||||
let offset_x = (m.x()? - min_x) as u32;
|
||||
let offset_y = (m.y()? - min_y) as u32;
|
||||
image::imageops::overlay(&mut combined_image, &capture, offset_x as i64, offset_y as i64);
|
||||
}
|
||||
|
||||
let file_path = save_dir.join(format!("{}.jpg", timestamp));
|
||||
let dynamic_image = image::DynamicImage::ImageRgba8(combined_image);
|
||||
let rgb_image = dynamic_image.into_rgb8();
|
||||
rgb_image.save_with_format(file_path, image::ImageFormat::Jpeg)?;
|
||||
} else {
|
||||
for (i, m) in monitors.iter().enumerate() {
|
||||
let capture = m.capture_image()?;
|
||||
let file_path = save_dir.join(format!("{}_{}.jpg", timestamp, i));
|
||||
let dynamic_image = image::DynamicImage::ImageRgba8(capture);
|
||||
let rgb_image = dynamic_image.into_rgb8();
|
||||
rgb_image.save_with_format(file_path, image::ImageFormat::Jpeg)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
41
src-tauri/src/lib.rs
Normal file
@@ -0,0 +1,41 @@
|
||||
mod engine;
|
||||
mod tray;
|
||||
|
||||
use tauri::Manager;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_dialog::init())
|
||||
.plugin(tauri_plugin_fs::init())
|
||||
.plugin(tauri_plugin_store::Builder::new().build())
|
||||
.plugin(tauri_plugin_autostart::init(
|
||||
tauri_plugin_autostart::MacosLauncher::LaunchAgent,
|
||||
Some(vec!["--minimized"]),
|
||||
))
|
||||
.plugin(tauri_plugin_opener::init())
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
engine::toggle_pause,
|
||||
engine::get_pause_state,
|
||||
engine::get_timeline
|
||||
])
|
||||
.setup(|app| {
|
||||
app.manage(engine::AppState {
|
||||
is_paused: Arc::new(AtomicBool::new(false)),
|
||||
});
|
||||
tray::create_tray(app.handle())?;
|
||||
engine::start_engine(app.handle().clone());
|
||||
Ok(())
|
||||
})
|
||||
.on_window_event(|window, event| match event {
|
||||
tauri::WindowEvent::CloseRequested { api, .. } => {
|
||||
window.hide().unwrap();
|
||||
api.prevent_close();
|
||||
}
|
||||
_ => {}
|
||||
})
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
6
src-tauri/src/main.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
fn main() {
|
||||
chrono_snap_lib::run()
|
||||
}
|
||||
59
src-tauri/src/tray.rs
Normal file
@@ -0,0 +1,59 @@
|
||||
use tauri::{
|
||||
menu::{Menu, MenuItem},
|
||||
tray::{MouseButton, MouseButtonState, TrayIconBuilder, TrayIconEvent},
|
||||
AppHandle, Manager,
|
||||
};
|
||||
|
||||
pub fn create_tray(app: &AppHandle) -> tauri::Result<()> {
|
||||
let open_i = MenuItem::with_id(app, "open", "打开主界面", true, None::<&str>)?;
|
||||
let toggle_i = MenuItem::with_id(app, "toggle", "暂停记录", true, None::<&str>)?;
|
||||
let quit_i = MenuItem::with_id(app, "quit", "退出", true, None::<&str>)?;
|
||||
|
||||
let menu = Menu::with_items(app, &[&open_i, &toggle_i, &quit_i])?;
|
||||
|
||||
let toggle_i_clone = toggle_i.clone();
|
||||
|
||||
TrayIconBuilder::with_id("main_tray")
|
||||
.tooltip("Chrono Snap")
|
||||
.icon(app.default_window_icon().unwrap().clone())
|
||||
.menu(&menu)
|
||||
.show_menu_on_left_click(false)
|
||||
.on_menu_event(move |app, event| match event.id().as_ref() {
|
||||
"open" => {
|
||||
if let Some(window) = app.get_webview_window("main") {
|
||||
let _ = window.show();
|
||||
let _ = window.set_focus();
|
||||
}
|
||||
}
|
||||
"toggle" => {
|
||||
let state = app.state::<crate::engine::AppState>();
|
||||
let current = state.is_paused.load(std::sync::atomic::Ordering::SeqCst);
|
||||
let new_state = !current;
|
||||
state.is_paused.store(new_state, std::sync::atomic::Ordering::SeqCst);
|
||||
|
||||
let text = if new_state { "恢复记录" } else { "暂停记录" };
|
||||
let _ = toggle_i_clone.set_text(text);
|
||||
}
|
||||
"quit" => {
|
||||
app.exit(0);
|
||||
}
|
||||
_ => {}
|
||||
})
|
||||
.on_tray_icon_event(|tray, event| {
|
||||
if let TrayIconEvent::Click {
|
||||
button: MouseButton::Left,
|
||||
button_state: MouseButtonState::Up,
|
||||
..
|
||||
} = event
|
||||
{
|
||||
let app = tray.app_handle();
|
||||
if let Some(window) = app.get_webview_window("main") {
|
||||
let _ = window.show();
|
||||
let _ = window.set_focus();
|
||||
}
|
||||
}
|
||||
})
|
||||
.build(app)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
35
src-tauri/tauri.conf.json
Normal file
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"$schema": "https://schema.tauri.app/config/2",
|
||||
"productName": "chrono-snap",
|
||||
"version": "0.1.0",
|
||||
"identifier": "top.volan.chrono-snap",
|
||||
"build": {
|
||||
"beforeDevCommand": "pnpm dev",
|
||||
"devUrl": "http://localhost:1420",
|
||||
"beforeBuildCommand": "pnpm build",
|
||||
"frontendDist": "../dist"
|
||||
},
|
||||
"app": {
|
||||
"windows": [
|
||||
{
|
||||
"title": "chrono-snap",
|
||||
"width": 800,
|
||||
"height": 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"
|
||||
]
|
||||
}
|
||||
}
|
||||
281
src/App.vue
Normal file
@@ -0,0 +1,281 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from "vue";
|
||||
import { load } from "@tauri-apps/plugin-store";
|
||||
import { open } from "@tauri-apps/plugin-dialog";
|
||||
import { convertFileSrc, invoke } from "@tauri-apps/api/core";
|
||||
import { FolderOpen, Settings, Play, Pause, Maximize2, X } from "lucide-vue-next";
|
||||
|
||||
const isSetupComplete = ref(false);
|
||||
const savePath = ref("");
|
||||
const isPaused = ref(false);
|
||||
|
||||
const currentDate = ref(new Date().toISOString().split("T")[0]); // YYYY-MM-DD
|
||||
const timelineImages = ref<{ time: string; path: string }[]>([]);
|
||||
const selectedImage = ref<{ time: string; path: string } | null>(null);
|
||||
const isFullscreen = ref(false);
|
||||
const isSettingsOpen = ref(false);
|
||||
const mergeScreens = ref(false);
|
||||
const retainDays = ref(30);
|
||||
|
||||
let store: any = null;
|
||||
|
||||
onMounted(async () => {
|
||||
store = await load("config.json");
|
||||
const path = await store.get("savePath");
|
||||
if (path) {
|
||||
savePath.value = path as string;
|
||||
isSetupComplete.value = true;
|
||||
mergeScreens.value = (await store.get("mergeScreens")) as boolean || false;
|
||||
retainDays.value = (await store.get("retainDays")) as number || 30;
|
||||
isPaused.value = await invoke("get_pause_state");
|
||||
await loadTimeline();
|
||||
}
|
||||
});
|
||||
|
||||
const selectFolder = async () => {
|
||||
const selected = await open({
|
||||
directory: true,
|
||||
multiple: false,
|
||||
});
|
||||
if (selected && typeof selected === "string") {
|
||||
savePath.value = selected;
|
||||
await store.set("savePath", selected);
|
||||
await store.save();
|
||||
isSetupComplete.value = true;
|
||||
await loadTimeline();
|
||||
}
|
||||
};
|
||||
|
||||
const updateSettings = async () => {
|
||||
await store.set("mergeScreens", mergeScreens.value);
|
||||
await store.set("retainDays", retainDays.value);
|
||||
await store.save();
|
||||
};
|
||||
|
||||
const togglePauseState = async () => {
|
||||
isPaused.value = await invoke("toggle_pause");
|
||||
};
|
||||
|
||||
const loadTimeline = async () => {
|
||||
if (!savePath.value) return;
|
||||
const dateStr = currentDate.value;
|
||||
// Rust is joining paths, Tauri FS plugin has a resolve function or we can use string concat.
|
||||
// Wait, readDir with an absolute path requires specific permissions in Tauri v2, or we need to use Rust to list files.
|
||||
// Actually, standard `readDir` supports absolute paths if we configure scope in capabilities.
|
||||
// We didn't allow `$fs:allow-read-all` or similar, we only added `fs:default`.
|
||||
// The simplest way to fetch timeline is a custom Rust command since we already manage the paths there!
|
||||
// It's safer to read files from Rust and return a list of { time, absolute_path }.
|
||||
timelineImages.value = await invoke("get_timeline", { date: dateStr, baseDir: savePath.value });
|
||||
};
|
||||
|
||||
const refresh = async () => {
|
||||
await loadTimeline();
|
||||
};
|
||||
|
||||
const selectImage = (img: { time: string; path: string }) => {
|
||||
selectedImage.value = img;
|
||||
};
|
||||
|
||||
const getSrc = (path: string) => {
|
||||
return convertFileSrc(path);
|
||||
};
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="h-screen w-screen flex flex-col overflow-hidden text-main bg-light">
|
||||
<!-- Setup Wizard -->
|
||||
<div v-if="!isSetupComplete" class="flex-1 flex items-center justify-center">
|
||||
<div class="bg-white p-10 rounded-3xl shadow-[0_12px_30px_rgba(0,0,0,0.04)] max-w-md text-center">
|
||||
<h1 class="text-3xl font-semibold mb-4 text-main">Welcome to Chrono Snap</h1>
|
||||
<p class="text-sec mb-8">Please select a folder to save your screenshots.</p>
|
||||
<button
|
||||
@click="selectFolder"
|
||||
class="bg-[#007AFF] text-white px-6 py-3 rounded-xl font-medium hover:bg-[#0063CC] transition shadow-[0_4px_12px_rgba(0,122,255,0.25)] flex items-center justify-center gap-2 w-full"
|
||||
>
|
||||
<FolderOpen :size="20" />
|
||||
Choose Folder
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Main App -->
|
||||
<div v-else class="flex flex-1 overflow-hidden">
|
||||
<!-- Sidebar -->
|
||||
<div class="w-64 bg-sidebar border-r border-[#E5E5E7] flex flex-col">
|
||||
<div class="p-6 pb-2">
|
||||
<h2 class="text-xl font-semibold mb-4">Timeline</h2>
|
||||
<input
|
||||
type="date"
|
||||
v-model="currentDate"
|
||||
@change="loadTimeline"
|
||||
class="w-full bg-white border border-[#E5E5E7] rounded-xl px-4 py-2 text-sm focus:outline-none focus:border-[#007AFF]"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="flex-1 overflow-y-auto px-4 py-2 space-y-2 no-scrollbar">
|
||||
<div
|
||||
v-for="img in timelineImages"
|
||||
:key="img.path"
|
||||
@click="selectImage(img)"
|
||||
class="p-3 rounded-xl cursor-pointer transition flex justify-between items-center"
|
||||
:class="selectedImage?.path === img.path ? 'bg-[#007AFF] text-white shadow-sm' : 'hover:bg-white text-sec hover:text-main'"
|
||||
>
|
||||
<span class="font-medium">{{ img.time }}</span>
|
||||
</div>
|
||||
<div v-if="timelineImages.length === 0" class="text-center text-sm text-sec mt-10">
|
||||
No records for this day.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="p-4 border-t border-[#E5E5E7] flex justify-between items-center bg-sidebar">
|
||||
<button
|
||||
@click="togglePauseState"
|
||||
class="p-2 rounded-lg hover:bg-[#E5E5E7] transition text-sec"
|
||||
:title="isPaused ? 'Resume' : 'Pause'"
|
||||
>
|
||||
<Play v-if="isPaused" :size="20" />
|
||||
<Pause v-else :size="20" />
|
||||
</button>
|
||||
|
||||
<button
|
||||
@click="refresh"
|
||||
class="text-sm font-medium text-[#007AFF] px-3 py-1 rounded-lg hover:bg-white transition"
|
||||
>
|
||||
Refresh
|
||||
</button>
|
||||
|
||||
<button
|
||||
@click="isSettingsOpen = true"
|
||||
class="p-2 rounded-lg hover:bg-[#E5E5E7] transition text-sec"
|
||||
title="Settings"
|
||||
>
|
||||
<Settings :size="20" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Content Area -->
|
||||
<div class="flex-1 bg-light flex flex-col relative">
|
||||
<div v-if="selectedImage" class="flex-1 p-10 flex items-center justify-center overflow-hidden">
|
||||
<div class="relative max-w-full max-h-full group">
|
||||
<img
|
||||
:src="getSrc(selectedImage.path)"
|
||||
class="max-w-full max-h-full object-contain rounded-2xl shadow-[0_12px_30px_rgba(0,0,0,0.08)]"
|
||||
/>
|
||||
<button
|
||||
@click="isFullscreen = true"
|
||||
class="absolute top-4 right-4 bg-black/50 text-white p-2 rounded-xl opacity-0 group-hover:opacity-100 transition backdrop-blur-md"
|
||||
>
|
||||
<Maximize2 :size="20" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="flex-1 flex items-center justify-center text-sec">
|
||||
Select a point in the timeline to view.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Settings Modal -->
|
||||
<div
|
||||
v-if="isSettingsOpen"
|
||||
class="fixed inset-0 z-50 bg-black/40 flex items-center justify-center p-8 backdrop-blur-sm"
|
||||
@click.self="isSettingsOpen = false"
|
||||
>
|
||||
<div class="bg-white rounded-3xl shadow-2xl w-full max-w-md overflow-hidden">
|
||||
<div class="p-6 border-b border-[#E5E5E7] flex justify-between items-center">
|
||||
<h2 class="text-xl font-semibold">Settings</h2>
|
||||
<button @click="isSettingsOpen = false" class="text-sec hover:text-main">
|
||||
<X :size="24" />
|
||||
</button>
|
||||
</div>
|
||||
<div class="p-8 space-y-6">
|
||||
<div class="space-y-2">
|
||||
<label class="text-sm font-medium text-sec">Save Path</label>
|
||||
<div class="flex gap-2">
|
||||
<input
|
||||
type="text"
|
||||
readonly
|
||||
:value="savePath"
|
||||
class="flex-1 bg-sidebar border border-[#E5E5E7] rounded-xl px-4 py-2 text-sm text-sec outline-none"
|
||||
/>
|
||||
<button
|
||||
@click="selectFolder"
|
||||
class="bg-sidebar border border-[#E5E5E7] p-2 rounded-xl hover:bg-[#E5E5E7] transition"
|
||||
>
|
||||
<FolderOpen :size="18" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<div class="font-medium">Merge Screens</div>
|
||||
<div class="text-xs text-sec">Combine all monitors into one image</div>
|
||||
</div>
|
||||
<button
|
||||
@click="mergeScreens = !mergeScreens; updateSettings()"
|
||||
class="w-12 h-6 rounded-full transition relative"
|
||||
:class="mergeScreens ? 'bg-[#007AFF]' : 'bg-[#E5E5E7]'"
|
||||
>
|
||||
<div
|
||||
class="absolute top-1 left-1 w-4 h-4 bg-white rounded-full transition-transform"
|
||||
:style="{ transform: mergeScreens ? 'translateX(24px)' : 'translateX(0)' }"
|
||||
></div>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="space-y-2">
|
||||
<div class="flex justify-between">
|
||||
<label class="text-sm font-medium">Retention Period</label>
|
||||
<span class="text-sm text-[#007AFF] font-semibold">{{ retainDays }} Days</span>
|
||||
</div>
|
||||
<input
|
||||
type="range"
|
||||
v-model.number="retainDays"
|
||||
min="1"
|
||||
max="90"
|
||||
@change="updateSettings"
|
||||
class="w-full h-1.5 bg-[#E5E5E7] rounded-lg appearance-none cursor-pointer accent-[#007AFF]"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="p-6 bg-sidebar border-t border-[#E5E5E7] text-center">
|
||||
<p class="text-xs text-sec">Changes are saved automatically.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Fullscreen Modal -->
|
||||
<div
|
||||
v-if="isFullscreen && selectedImage"
|
||||
class="fixed inset-0 z-50 bg-black/90 flex items-center justify-center p-8 backdrop-blur-sm"
|
||||
>
|
||||
<button
|
||||
@click="isFullscreen = false"
|
||||
class="absolute top-8 right-8 text-white/70 hover:text-white transition"
|
||||
>
|
||||
<X :size="32" />
|
||||
</button>
|
||||
<img
|
||||
:src="getSrc(selectedImage.path)"
|
||||
class="max-w-full max-h-full object-contain"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style>
|
||||
/* Custom scrollbar for timeline */
|
||||
.no-scrollbar::-webkit-scrollbar {
|
||||
width: 4px;
|
||||
}
|
||||
.no-scrollbar::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
}
|
||||
.no-scrollbar::-webkit-scrollbar-thumb {
|
||||
background-color: rgba(0,0,0,0.1);
|
||||
border-radius: 20px;
|
||||
}
|
||||
</style>
|
||||
35
src/assets/main.css
Normal file
@@ -0,0 +1,35 @@
|
||||
@import "tailwindcss";
|
||||
|
||||
:root {
|
||||
--primary-color: #007AFF;
|
||||
--primary-hover: #0063CC;
|
||||
--bg-light: #FBFBFD;
|
||||
--sidebar-bg: #F8FAFD;
|
||||
--text-main: #1D1D1F;
|
||||
--text-sec: #86868B;
|
||||
--border-color: #E5E5E7;
|
||||
--card-shadow: 0 12px 30px rgba(0, 0, 0, 0.04);
|
||||
--btn-shadow: 0 4px 12px rgba(0, 122, 255, 0.25);
|
||||
--radius-card: 24px;
|
||||
--radius-btn: 12px;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
||||
background-color: var(--bg-light);
|
||||
color: var(--text-main);
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
/* Base custom styles for utility-like usage */
|
||||
.bg-light { background-color: var(--bg-light); }
|
||||
.bg-sidebar { background-color: var(--sidebar-bg); }
|
||||
.text-main { color: var(--text-main); }
|
||||
.text-sec { color: var(--text-sec); }
|
||||
.border-main { border-color: var(--border-color); }
|
||||
1
src/assets/vue.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="37.07" height="36" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 198"><path fill="#41B883" d="M204.8 0H256L128 220.8L0 0h97.92L128 51.2L157.44 0h47.36Z"></path><path fill="#41B883" d="m0 0l128 220.8L256 0h-51.2L128 132.48L50.56 0H0Z"></path><path fill="#35495E" d="M50.56 0L128 133.12L204.8 0h-47.36L128 51.2L97.92 0H50.56Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 496 B |
5
src/main.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { createApp } from "vue";
|
||||
import "./assets/main.css";
|
||||
import App from "./App.vue";
|
||||
|
||||
createApp(App).mount("#app");
|
||||
7
src/vite-env.d.ts
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
/// <reference types="vite/client" />
|
||||
|
||||
declare module "*.vue" {
|
||||
import type { DefineComponent } from "vue";
|
||||
const component: DefineComponent<{}, {}, any>;
|
||||
export default component;
|
||||
}
|
||||
25
tsconfig.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"useDefineForClassFields": true,
|
||||
"module": "ESNext",
|
||||
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"noEmit": true,
|
||||
"jsx": "preserve",
|
||||
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"noFallthroughCasesInSwitch": true
|
||||
},
|
||||
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
|
||||
"references": [{ "path": "./tsconfig.node.json" }]
|
||||
}
|
||||
10
tsconfig.node.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"skipLibCheck": true,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "bundler",
|
||||
"allowSyntheticDefaultImports": true
|
||||
},
|
||||
"include": ["vite.config.ts"]
|
||||
}
|
||||
33
vite.config.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { defineConfig } from "vite";
|
||||
import vue from "@vitejs/plugin-vue";
|
||||
import tailwindcss from "@tailwindcss/vite";
|
||||
|
||||
// @ts-expect-error process is a nodejs global
|
||||
const host = process.env.TAURI_DEV_HOST;
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig(async () => ({
|
||||
plugins: [vue(), tailwindcss()],
|
||||
|
||||
// Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
|
||||
//
|
||||
// 1. prevent Vite from obscuring rust errors
|
||||
clearScreen: false,
|
||||
// 2. tauri expects a fixed port, fail if that port is not available
|
||||
server: {
|
||||
port: 1420,
|
||||
strictPort: true,
|
||||
host: host || false,
|
||||
hmr: host
|
||||
? {
|
||||
protocol: "ws",
|
||||
host,
|
||||
port: 1421,
|
||||
}
|
||||
: undefined,
|
||||
watch: {
|
||||
// 3. tell Vite to ignore watching `src-tauri`
|
||||
ignored: ["**/src-tauri/**"],
|
||||
},
|
||||
},
|
||||
}));
|
||||