Initial Commit

This commit is contained in:
2026-07-17 15:24:20 -04:00
commit 0ca889ad49
34 changed files with 5533 additions and 0 deletions
+24
View 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?
+3
View File
@@ -0,0 +1,3 @@
{
"recommendations": ["tauri-apps.tauri-vscode", "rust-lang.rust-analyzer"]
}
+7
View File
@@ -0,0 +1,7 @@
# Tauri + Vanilla
This template should help get you started developing with Tauri in vanilla HTML, CSS and Javascript.
## Recommended IDE Setup
- [VS Code](https://code.visualstudio.com/) + [Tauri](https://marketplace.visualstudio.com/items?itemName=tauri-apps.tauri-vscode) + [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer)
+7
View 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
+4406
View File
File diff suppressed because it is too large Load Diff
+18
View File
@@ -0,0 +1,18 @@
[package]
name = "discord-presence"
version = "0.1.0"
edition = "2021"
[dependencies]
tauri = { version = "2", features = [] }
tauri-build = { version = "2", features = [] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
discord-rich-presence = "0.2"
[build-dependencies]
tauri-build = { version = "2", features = [] }
[profile.release]
strip = true
lto = true
+3
View File
@@ -0,0 +1,3 @@
fn main() {
tauri_build::build()
}
+8
View File
@@ -0,0 +1,8 @@
{
"identifier": "default",
"description": "Default capabilities for the app",
"windows": ["main"],
"permissions": [
"core:default"
]
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 974 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 903 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

+74
View File
@@ -0,0 +1,74 @@
use discord_rich_presence::{activity, DiscordIpc, DiscordIpcClient};
use std::sync::Mutex;
use std::time::{SystemTime, UNIX_EPOCH};
use tauri::State;
struct Discord(Mutex<Option<DiscordIpcClient>>);
unsafe impl Send for Discord {}
unsafe impl Sync for Discord {}
struct StartTime(Mutex<i64>);
#[tauri::command]
fn connect(app_id: String, discord: State<Discord>, start: State<StartTime>) -> Result<String, String> {
let mut guard = discord.0.lock().map_err(|e| e.to_string())?;
if let Some(ref mut old) = *guard {
old.close().ok();
}
let mut client = DiscordIpcClient::new(&app_id).map_err(|e| e.to_string())?;
client.connect().map_err(|_| "Could not connect — is Discord running?".to_string())?;
let now = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs() as i64;
*start.0.lock().unwrap() = now;
*guard = Some(client);
Ok("Connected".into())
}
#[tauri::command]
fn disconnect(discord: State<Discord>) -> Result<String, String> {
let mut guard = discord.0.lock().map_err(|e| e.to_string())?;
if let Some(ref mut client) = *guard {
client.close().map_err(|e| e.to_string())?;
}
*guard = None;
Ok("Disconnected".into())
}
#[tauri::command]
fn set_activity(
status: String,
details: String,
show_time: bool,
elapsed_seconds: Option<i64>,
discord: State<Discord>,
start: State<StartTime>,
) -> Result<String, String> {
let mut guard = discord.0.lock().map_err(|e| e.to_string())?;
let client = guard.as_mut().ok_or_else(|| "Not connected to Discord".to_string())?;
let mut act = activity::Activity::new();
if show_time {
let now = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs() as i64;
let start_at = now - elapsed_seconds.unwrap_or(0);
act = act.timestamps(activity::Timestamps::new().start(start_at));
}
if !status.is_empty() { act = act.state(&status); }
if !details.is_empty() { act = act.details(&details); }
client.set_activity(act).map_err(|e| e.to_string())?;
Ok("Activity set".into())
}
#[tauri::command]
fn clear_activity(discord: State<Discord>) -> Result<String, String> {
let mut guard = discord.0.lock().map_err(|e| e.to_string())?;
let client = guard.as_mut().ok_or_else(|| "Not connected to Discord".to_string())?;
client.clear_activity().map_err(|e| e.to_string())?;
Ok("Cleared".into())
}
pub fn run() {
tauri::Builder::default()
.manage(Discord(Mutex::new(None)))
.manage(StartTime(Mutex::new(0)))
.invoke_handler(tauri::generate_handler![connect, disconnect, set_activity, clear_activity])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
+5
View File
@@ -0,0 +1,5 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
fn main() {
discord_presence::run();
}
+25
View File
@@ -0,0 +1,25 @@
{
"$schema": "https://raw.githubusercontent.com/tauri-apps/tauri/dev/crates/tauri-utils/schema.json",
"productName": "Discord Presence",
"version": "0.1.0",
"identifier": "org.racooncity.discord-presence",
"build": {
"frontendDist": "../ui"
},
"app": {
"withGlobalTauri": true,
"windows": [
{
"title": "Discord Presence",
"width": 460,
"height": 620,
"resizable": true,
"decorations": true,
"center": true
}
],
"security": {
"csp": "null"
}
}
}
+1
View 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="32" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path fill="#F7DF1E" d="M0 0h256v256H0V0Z"></path><path d="m67.312 213.932l19.59-11.856c3.78 6.701 7.218 12.371 15.465 12.371c7.905 0 12.89-3.092 12.89-15.12v-81.798h24.057v82.138c0 24.917-14.606 36.259-35.916 36.259c-19.245 0-30.416-9.967-36.087-21.996m85.07-2.576l19.588-11.341c5.157 8.421 11.859 14.607 23.715 14.607c9.969 0 16.325-4.984 16.325-11.858c0-8.248-6.53-11.17-17.528-15.98l-6.013-2.58c-17.357-7.387-28.87-16.667-28.87-36.257c0-18.044 13.747-31.792 35.228-31.792c15.294 0 26.292 5.328 34.196 19.247l-18.732 12.03c-4.125-7.389-8.591-10.31-15.465-10.31c-7.046 0-11.514 4.468-11.514 10.31c0 7.217 4.468 10.14 14.778 14.608l6.014 2.577c20.45 8.765 31.963 17.7 31.963 37.804c0 21.654-17.012 33.51-39.867 33.51c-22.339 0-36.774-10.654-43.819-24.574"></path></svg>

After

Width:  |  Height:  |  Size: 995 B

+6
View 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

+154
View File
@@ -0,0 +1,154 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Discord Presence</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet" />
<script>
tailwind.config = {
theme: {
extend: {
fontFamily: { sans: ['Inter', 'system-ui', 'sans-serif'] },
colors: {
surface: { 900: '#0c0e14', 800: '#13161e', 700: '#1a1e2a', 600: '#242938' },
accent: { DEFAULT: '#7c6fef', light: '#9b8ff5', dim: '#5a4fcf' },
}
}
}
}
</script>
<style>
body { background: #0c0e14; }
input:focus { outline: none; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; }
.status-dot.on { background: #34d399; box-shadow: 0 0 6px #34d39966; }
.status-dot.off { background: #64748b; }
.btn-primary {
background: linear-gradient(135deg, #7c6fef, #5a4fcf);
transition: all 0.15s ease;
}
.btn-primary:hover { filter: brightness(1.15); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.4; pointer-events: none; }
.input-field {
background: #1a1e2a;
border: 1px solid #242938;
transition: border-color 0.15s ease;
}
.input-field:focus { border-color: #7c6fef; }
.preview-card {
background: #13161e;
border-left: 3px solid #7c6fef;
}
.toast {
animation: toast-in 0.25s ease, toast-out 0.3s ease 2.2s forwards;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-4px); } }
</style>
</head>
<body class="font-sans text-slate-200 select-none overflow-hidden h-screen flex flex-col">
<!-- Header -->
<header class="flex items-center gap-3 px-5 pt-5 pb-3">
<div class="w-8 h-8 rounded-lg bg-accent/20 flex items-center justify-center">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#7c6fef" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="10"/><polygon points="10 8 16 12 10 16 10 8"/>
</svg>
</div>
<h1 class="text-base font-semibold tracking-tight">Discord Presence</h1>
<div class="flex-1"></div>
<div class="flex items-center gap-2">
<div id="statusDot" class="status-dot off"></div>
<span id="statusLabel" class="text-xs text-slate-500">Disconnected</span>
</div>
</header>
<main class="flex-1 overflow-y-auto px-5 pb-5 space-y-4">
<!-- Connection -->
<section class="bg-surface-800 rounded-xl p-4 space-y-3">
<label class="block text-xs font-medium text-slate-400 uppercase tracking-wider">Application ID</label>
<div class="flex gap-2">
<input
id="appId"
type="text"
placeholder="Paste your Discord Application ID"
class="input-field flex-1 rounded-lg px-3 py-2 text-sm text-slate-200 placeholder-slate-600"
/>
<button id="connectBtn" onclick="toggleConnection()"
class="btn-primary text-white text-sm font-medium px-4 py-2 rounded-lg">
Connect
</button>
</div>
</section>
<!-- Activity -->
<section class="bg-surface-800 rounded-xl p-4 space-y-3">
<label class="block text-xs font-medium text-slate-400 uppercase tracking-wider">Activity</label>
<div>
<label class="block text-xs text-slate-500 mb-1">Status</label>
<input
id="statusInput"
type="text"
placeholder="Whatever you want"
maxlength="128"
class="input-field w-full rounded-lg px-3 py-2 text-sm text-slate-200 placeholder-slate-600"
/>
</div>
<div>
<label class="block text-xs text-slate-500 mb-1">Details</label>
<input
id="detailsInput"
type="text"
placeholder="Optional second line"
maxlength="128"
class="input-field w-full rounded-lg px-3 py-2 text-sm text-slate-200 placeholder-slate-600"
/>
</div>
<div class="flex items-center justify-between pt-1">
<label class="flex items-center gap-2 cursor-pointer">
<input id="showTime" type="checkbox" checked
class="w-4 h-4 rounded bg-surface-700 border-surface-600 text-accent focus:ring-accent/40 cursor-pointer" />
<span class="text-sm text-slate-400">Show elapsed time</span>
</label>
</div>
<div class="flex gap-2 pt-1">
<button onclick="setActivity()" id="setBtn" disabled
class="btn-primary flex-1 text-white text-sm font-medium px-4 py-2 rounded-lg">
Set Status
</button>
<button onclick="clearActivity()" id="clearBtn" disabled
class="flex-1 text-sm font-medium px-4 py-2 rounded-lg bg-surface-700 text-slate-400 hover:bg-surface-600 hover:text-slate-200 transition-colors disabled:opacity-30 disabled:pointer-events-none">
Clear
</button>
</div>
</section>
<!-- Live Preview -->
<section class="bg-surface-800 rounded-xl p-4 space-y-2">
<label class="block text-xs font-medium text-slate-400 uppercase tracking-wider">Preview</label>
<div class="preview-card rounded-lg p-3 space-y-1">
<div class="text-[11px] font-semibold text-slate-500 uppercase tracking-wide">Playing</div>
<div id="previewTitle" class="text-sm font-semibold text-slate-200"></div>
<div id="previewStatus" class="text-xs text-slate-400 hidden"></div>
<div id="previewDetails" class="text-xs text-slate-400 hidden"></div>
<div id="previewTime" class="text-xs text-slate-500 hidden">00:00 elapsed</div>
</div>
</section>
</main>
<!-- Toast container -->
<div id="toastContainer" class="fixed bottom-4 left-1/2 -translate-x-1/2 z-50 space-y-2"></div>
<script src="main.js"></script>
</body>
</html>
+191
View File
@@ -0,0 +1,191 @@
const { invoke } = window.__TAURI__.core;
// ── State ──────────────────────────────────────────────
let connected = false;
let timerStart = null;
let timerInterval = null;
// ── Elements ───────────────────────────────────────────
const appIdInput = document.getElementById("appId");
const statusInput = document.getElementById("statusInput");
const detailsInput = document.getElementById("detailsInput");
const showTimeCheck = document.getElementById("showTime");
const connectBtn = document.getElementById("connectBtn");
const setBtn = document.getElementById("setBtn");
const clearBtn = document.getElementById("clearBtn");
const statusDot = document.getElementById("statusDot");
const statusLabel = document.getElementById("statusLabel");
const previewTitle = document.getElementById("previewTitle");
const previewStatus = document.getElementById("previewStatus");
const previewDetails = document.getElementById("previewDetails");
const previewTime = document.getElementById("previewTime");
// ── Connection ─────────────────────────────────────────
async function toggleConnection() {
if (connected) {
try {
await invoke("disconnect");
setConnected(false);
toast("Disconnected", "neutral");
} catch (e) {
toast(e, "error");
}
} else {
const appId = appIdInput.value.trim();
if (!appId) {
toast("Paste your Application ID first", "error");
appIdInput.focus();
return;
}
connectBtn.textContent = "Connecting…";
connectBtn.disabled = true;
try {
await invoke("connect", { appId });
setConnected(true);
toast("Connected to Discord", "success");
} catch (e) {
toast(e, "error");
} finally {
connectBtn.disabled = false;
}
}
}
function setConnected(state) {
connected = state;
connectBtn.textContent = state ? "Disconnect" : "Connect";
statusDot.className = `status-dot ${state ? "on" : "off"}`;
statusLabel.textContent = state ? "Connected" : "Disconnected";
setBtn.disabled = !state;
clearBtn.disabled = !state;
appIdInput.disabled = state;
if (state) {
timerStart = Date.now();
startTimer();
} else {
stopTimer();
timerStart = null;
}
}
// ── Activity ───────────────────────────────────────────
async function setActivity() {
const status = statusInput.value.trim();
const details = detailsInput.value.trim();
const showTime = showTimeCheck.checked;
if (!status && !details) {
toast("Type something first", "error");
statusInput.focus();
return;
}
try {
await invoke("set_activity", { status, details, showTime });
updatePreview(status, details, showTime);
toast("Status updated", "success");
} catch (e) {
toast(e, "error");
}
}
async function clearActivity() {
try {
await invoke("clear_activity");
resetPreview();
toast("Presence cleared", "neutral");
} catch (e) {
toast(e, "error");
}
}
// ── Preview ────────────────────────────────────────────
function updatePreview(status, details, showTime) {
previewTitle.textContent = appIdInput.value ? "Your App Name" : "—";
if (status) {
previewStatus.textContent = status;
previewStatus.classList.remove("hidden");
} else {
previewStatus.classList.add("hidden");
}
if (details) {
previewDetails.textContent = details;
previewDetails.classList.remove("hidden");
} else {
previewDetails.classList.add("hidden");
}
if (showTime) {
previewTime.classList.remove("hidden");
} else {
previewTime.classList.add("hidden");
}
}
function resetPreview() {
previewTitle.textContent = "—";
previewStatus.classList.add("hidden");
previewDetails.classList.add("hidden");
previewTime.classList.add("hidden");
}
// Live-update the preview as you type
statusInput.addEventListener("input", () => {
if (previewStatus.textContent || statusInput.value) {
previewStatus.textContent = statusInput.value || "";
previewStatus.classList.toggle("hidden", !statusInput.value);
}
});
detailsInput.addEventListener("input", () => {
if (previewDetails.textContent || detailsInput.value) {
previewDetails.textContent = detailsInput.value || "";
previewDetails.classList.toggle("hidden", !detailsInput.value);
}
});
// Submit on Enter from either input
statusInput.addEventListener("keydown", (e) => { if (e.key === "Enter" && connected) setActivity(); });
detailsInput.addEventListener("keydown", (e) => { if (e.key === "Enter" && connected) setActivity(); });
appIdInput.addEventListener("keydown", (e) => { if (e.key === "Enter" && !connected) toggleConnection(); });
// ── Timer ──────────────────────────────────────────────
function startTimer() {
stopTimer();
timerInterval = setInterval(() => {
if (!timerStart) return;
const elapsed = Math.floor((Date.now() - timerStart) / 1000);
const h = Math.floor(elapsed / 3600);
const m = Math.floor((elapsed % 3600) / 60);
const s = elapsed % 60;
const parts = [];
if (h > 0) parts.push(String(h).padStart(2, "0"));
parts.push(String(m).padStart(2, "0"));
parts.push(String(s).padStart(2, "0"));
previewTime.textContent = parts.join(":") + " elapsed";
}, 1000);
}
function stopTimer() {
if (timerInterval) {
clearInterval(timerInterval);
timerInterval = null;
}
}
// ── Toast ──────────────────────────────────────────────
function toast(msg, type = "neutral") {
const container = document.getElementById("toastContainer");
const colors = {
success: "bg-emerald-900/80 border-emerald-700/50 text-emerald-200",
error: "bg-rose-900/80 border-rose-700/50 text-rose-200",
neutral: "bg-surface-700/90 border-surface-600/50 text-slate-300",
};
const el = document.createElement("div");
el.className = `toast text-xs px-4 py-2 rounded-lg border backdrop-blur-sm ${colors[type] || colors.neutral}`;
el.textContent = msg;
container.appendChild(el);
setTimeout(() => el.remove(), 2600);
}
+112
View File
@@ -0,0 +1,112 @@
.logo.vanilla:hover {
filter: drop-shadow(0 0 2em #ffe21c);
}
:root {
font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
font-size: 16px;
line-height: 24px;
font-weight: 400;
color: #0f0f0f;
background-color: #f6f6f6;
font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
-webkit-text-size-adjust: 100%;
}
.container {
margin: 0;
padding-top: 10vh;
display: flex;
flex-direction: column;
justify-content: center;
text-align: center;
}
.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: 0.75s;
}
.logo.tauri:hover {
filter: drop-shadow(0 0 2em #24c8db);
}
.row {
display: flex;
justify-content: center;
}
a {
font-weight: 500;
color: #646cff;
text-decoration: inherit;
}
a:hover {
color: #535bf2;
}
h1 {
text-align: center;
}
input,
button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
color: #0f0f0f;
background-color: #ffffff;
transition: border-color 0.25s;
box-shadow: 0 2px 2px rgba(0, 0, 0, 0.2);
}
button {
cursor: pointer;
}
button:hover {
border-color: #396cd8;
}
button:active {
border-color: #396cd8;
background-color: #e8e8e8;
}
input,
button {
outline: none;
}
#greet-input {
margin-right: 5px;
}
@media (prefers-color-scheme: dark) {
:root {
color: #f6f6f6;
background-color: #2f2f2f;
}
a:hover {
color: #24c8db;
}
input,
button {
color: #ffffff;
background-color: #0f0f0f98;
}
button:active {
background-color: #0f0f0f69;
}
}
+295
View File
@@ -0,0 +1,295 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Discord Presence</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet" />
<script>
tailwind.config = {
theme: {
extend: {
fontFamily: { sans: ['Inter', 'system-ui', 'sans-serif'] },
colors: {
surface: { 900: '#0c0e14', 800: '#13161e', 700: '#1a1e2a', 600: '#242938' },
accent: { DEFAULT: '#7c6fef', light: '#9b8ff5', dim: '#5a4fcf' },
}
}
}
}
</script>
<style>
body { background: #0c0e14; }
input:focus { outline: none; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; }
.status-dot.on { background: #34d399; box-shadow: 0 0 6px #34d39966; }
.status-dot.off { background: #64748b; }
.btn-primary {
background: linear-gradient(135deg, #7c6fef, #5a4fcf);
transition: all 0.15s ease;
}
.btn-primary:hover { filter: brightness(1.15); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.4; pointer-events: none; }
.input-field {
background: #1a1e2a;
border: 1px solid #242938;
transition: border-color 0.15s ease;
}
.input-field:focus { border-color: #7c6fef; }
.preview-card {
background: #13161e;
border-left: 3px solid #7c6fef;
}
.toast {
animation: toast-in 0.25s ease, toast-out 0.3s ease 2.2s forwards;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-4px); } }
/* Help modal */
.modal-backdrop {
background: rgba(0, 0, 0, 0.7);
backdrop-filter: blur(4px);
animation: fade-in 0.15s ease;
}
.modal-content {
animation: slide-up 0.2s ease;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-up { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
.step-number {
width: 22px; height: 22px;
background: linear-gradient(135deg, #7c6fef, #5a4fcf);
border-radius: 50%;
display: flex; align-items: center; justify-content: center;
font-size: 11px; font-weight: 700;
flex-shrink: 0;
}
/* Hide number spinners */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; }
</style>
</head>
<body class="font-sans text-slate-200 select-none overflow-hidden h-screen flex flex-col">
<!-- Header -->
<header class="flex items-center gap-3 px-5 pt-5 pb-3">
<div class="w-8 h-8 rounded-lg bg-accent/20 flex items-center justify-center">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#7c6fef" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="10"/><polygon points="10 8 16 12 10 16 10 8"/>
</svg>
</div>
<h1 class="text-base font-semibold tracking-tight">Discord Presence</h1>
<div class="flex-1"></div>
<button onclick="openHelp()"
class="w-7 h-7 rounded-lg bg-surface-700 hover:bg-surface-600 flex items-center justify-center text-slate-400 hover:text-slate-200 transition-colors text-xs font-bold"
title="Setup guide">?</button>
<div class="flex items-center gap-2 ml-1">
<div id="statusDot" class="status-dot off"></div>
<span id="statusLabel" class="text-xs text-slate-500">Disconnected</span>
</div>
</header>
<main class="flex-1 overflow-y-auto px-5 pb-5 space-y-4">
<!-- Connection -->
<section class="bg-surface-800 rounded-xl p-4 space-y-3">
<label class="block text-xs font-medium text-slate-400 uppercase tracking-wider">Application ID</label>
<div class="flex gap-2">
<input
id="appId"
type="text"
placeholder="Paste your Discord Application ID"
class="input-field flex-1 rounded-lg px-3 py-2 text-sm text-slate-200 placeholder-slate-600"
/>
<button id="connectBtn" onclick="toggleConnection()"
class="btn-primary text-white text-sm font-medium px-4 py-2 rounded-lg">
Connect
</button>
</div>
</section>
<!-- Activity -->
<section class="bg-surface-800 rounded-xl p-4 space-y-3">
<label class="block text-xs font-medium text-slate-400 uppercase tracking-wider">Activity</label>
<div>
<label class="block text-xs text-slate-500 mb-1">Status</label>
<input
id="statusInput"
type="text"
placeholder="Whatever you want"
maxlength="128"
class="input-field w-full rounded-lg px-3 py-2 text-sm text-slate-200 placeholder-slate-600"
/>
</div>
<div>
<label class="block text-xs text-slate-500 mb-1">Details</label>
<input
id="detailsInput"
type="text"
placeholder="Optional second line"
maxlength="128"
class="input-field w-full rounded-lg px-3 py-2 text-sm text-slate-200 placeholder-slate-600"
/>
</div>
<div class="flex items-center justify-between pt-1">
<label class="flex items-center gap-2 cursor-pointer">
<input id="showTime" type="checkbox" checked
class="w-4 h-4 rounded bg-surface-700 border-surface-600 text-accent focus:ring-accent/40 cursor-pointer" />
<span class="text-sm text-slate-400">Show elapsed time</span>
</label>
</div>
<div id="timeInputs" class="flex gap-2 pt-1">
<div class="flex-1">
<label class="block text-xs text-slate-500 mb-1">Hours</label>
<input id="elapsedHours" type="number" min="0" value="0" placeholder="0"
class="input-field w-full rounded-lg px-3 py-2 text-sm text-slate-200 placeholder-slate-600" />
</div>
<div class="flex-1">
<label class="block text-xs text-slate-500 mb-1">Minutes</label>
<input id="elapsedMins" type="number" min="0" max="59" value="0" placeholder="0"
class="input-field w-full rounded-lg px-3 py-2 text-sm text-slate-200 placeholder-slate-600" />
</div>
</div>
<div class="flex gap-2 pt-1">
<button onclick="setActivity()" id="setBtn" disabled
class="btn-primary flex-1 text-white text-sm font-medium px-4 py-2 rounded-lg">
Set Status
</button>
<button onclick="clearActivity()" id="clearBtn" disabled
class="flex-1 text-sm font-medium px-4 py-2 rounded-lg bg-surface-700 text-slate-400 hover:bg-surface-600 hover:text-slate-200 transition-colors disabled:opacity-30 disabled:pointer-events-none">
Clear
</button>
</div>
</section>
<!-- Live Preview -->
<section class="bg-surface-800 rounded-xl p-4 space-y-2">
<label class="block text-xs font-medium text-slate-400 uppercase tracking-wider">Preview</label>
<div class="preview-card rounded-lg p-3 space-y-1">
<div class="text-[11px] font-semibold text-slate-500 uppercase tracking-wide">Playing</div>
<div id="previewTitle" class="text-sm font-semibold text-slate-200"></div>
<div id="previewStatus" class="text-xs text-slate-400 hidden"></div>
<div id="previewDetails" class="text-xs text-slate-400 hidden"></div>
<div id="previewTime" class="text-xs text-slate-500 hidden">00:00 elapsed</div>
</div>
</section>
</main>
<!-- Help Modal -->
<div id="helpModal" class="fixed inset-0 z-50 hidden">
<div class="modal-backdrop absolute inset-0" onclick="closeHelp()"></div>
<div class="modal-content absolute inset-4 top-8 bottom-8 bg-surface-800 rounded-2xl border border-surface-600 flex flex-col overflow-hidden">
<!-- Modal header -->
<div class="flex items-center justify-between px-5 py-4 border-b border-surface-600">
<h2 class="text-sm font-semibold">Setup Guide</h2>
<button onclick="closeHelp()"
class="w-7 h-7 rounded-lg bg-surface-700 hover:bg-surface-600 flex items-center justify-center text-slate-400 hover:text-slate-200 transition-colors text-lg leading-none">
&times;
</button>
</div>
<!-- Modal body -->
<div class="flex-1 overflow-y-auto px-5 py-4 space-y-6">
<!-- Section: Create an Application -->
<div class="space-y-3">
<h3 class="text-xs font-semibold text-accent uppercase tracking-wider">Create a Discord Application</h3>
<p class="text-xs text-slate-400 leading-relaxed">
Each application you create becomes a "game" Discord can display on your profile.
The application name is what shows as <span class="text-slate-200 font-medium">Playing X</span> — so name it whatever you want people to see.
</p>
<div class="space-y-3">
<div class="flex gap-3 items-start">
<div class="step-number">1</div>
<p class="text-sm text-slate-300 pt-0.5">Go to <span class="text-accent font-medium">discord.com/developers/applications</span> and log in.</p>
</div>
<div class="flex gap-3 items-start">
<div class="step-number">2</div>
<p class="text-sm text-slate-300 pt-0.5">Click <span class="text-slate-200 font-medium">New Application</span> in the top right.</p>
</div>
<div class="flex gap-3 items-start">
<div class="step-number">3</div>
<p class="text-sm text-slate-300 pt-0.5">Name it whatever you want to show as your "game" — this is the title that appears on your profile.</p>
</div>
<div class="flex gap-3 items-start">
<div class="step-number">4</div>
<p class="text-sm text-slate-300 pt-0.5">On the <span class="text-slate-200 font-medium">General Information</span> page, copy the <span class="text-slate-200 font-medium">Application ID</span> (the long number near the top).</p>
</div>
</div>
</div>
<!-- Section: Using the App -->
<div class="space-y-3">
<h3 class="text-xs font-semibold text-accent uppercase tracking-wider">Using the App</h3>
<div class="space-y-3">
<div class="flex gap-3 items-start">
<div class="step-number">1</div>
<p class="text-sm text-slate-300 pt-0.5">Paste the Application ID and click <span class="text-slate-200 font-medium">Connect</span>. Discord must be running on the same machine.</p>
</div>
<div class="flex gap-3 items-start">
<div class="step-number">2</div>
<p class="text-sm text-slate-300 pt-0.5">Type whatever you want in <span class="text-slate-200 font-medium">Status</span> and <span class="text-slate-200 font-medium">Details</span> (both optional). Hit <span class="text-slate-200 font-medium">Set Status</span>.</p>
</div>
<div class="flex gap-3 items-start">
<div class="step-number">3</div>
<p class="text-sm text-slate-300 pt-0.5">Use <span class="text-slate-200 font-medium">Clear</span> to remove the presence, or <span class="text-slate-200 font-medium">Disconnect</span> to drop the connection entirely.</p>
</div>
</div>
</div>
<!-- Section: Elapsed Time -->
<div class="space-y-3">
<h3 class="text-xs font-semibold text-accent uppercase tracking-wider">Elapsed Time</h3>
<p class="text-xs text-slate-400 leading-relaxed">
The timer shows how long you've been "playing." Leave hours and minutes at 0 to start from now,
or set a custom value to fake a longer session. Setting 48 hours makes it look like you've been at it for two days straight.
</p>
</div>
<!-- Section: Tips -->
<div class="space-y-3">
<h3 class="text-xs font-semibold text-accent uppercase tracking-wider">Tips</h3>
<div class="bg-surface-700 rounded-lg p-3 space-y-2">
<p class="text-xs text-slate-400 leading-relaxed">
<span class="text-slate-300 font-medium">Changing the title:</span>
The "Playing" title is locked to the Application name. To change it, rename the app in the developer portal,
then disconnect and reconnect. Discord may take a minute to update.
</p>
<p class="text-xs text-slate-400 leading-relaxed">
<span class="text-slate-300 font-medium">Multiple titles:</span>
Create several Applications with different names and swap between their IDs to quickly change what you're "playing."
</p>
<p class="text-xs text-slate-400 leading-relaxed">
<span class="text-slate-300 font-medium">Ghost entries:</span>
If old game names linger, go to Discord → Settings → Activity Settings → Registered Games and remove them.
</p>
<p class="text-xs text-slate-400 leading-relaxed">
<span class="text-slate-300 font-medium">No bot token needed.</span>
This uses Discord's local IPC socket, not the bot gateway. No permissions, no OAuth, no server required.
</p>
</div>
</div>
</div>
</div>
</div>
<!-- Toast container -->
<div id="toastContainer" class="fixed bottom-4 left-1/2 -translate-x-1/2 z-40 space-y-2"></div>
<script src="main.js"></script>
</body>
</html>
+194
View File
@@ -0,0 +1,194 @@
const { invoke } = window.__TAURI__.core;
let connected = false;
let timerStart = null;
let timerInterval = null;
const appIdInput = document.getElementById("appId");
const statusInput = document.getElementById("statusInput");
const detailsInput = document.getElementById("detailsInput");
const showTimeCheck = document.getElementById("showTime");
const connectBtn = document.getElementById("connectBtn");
const setBtn = document.getElementById("setBtn");
const clearBtn = document.getElementById("clearBtn");
const statusDot = document.getElementById("statusDot");
const statusLabel = document.getElementById("statusLabel");
const previewTitle = document.getElementById("previewTitle");
const previewStatus = document.getElementById("previewStatus");
const previewDetails = document.getElementById("previewDetails");
const previewTime = document.getElementById("previewTime");
async function toggleConnection() {
if (connected) {
try {
await invoke("disconnect");
setConnected(false);
toast("Disconnected", "neutral");
} catch (e) {
toast(e, "error");
}
} else {
const appId = appIdInput.value.trim();
if (!appId) {
toast("Paste your Application ID first", "error");
appIdInput.focus();
return;
}
connectBtn.textContent = "Connecting…";
connectBtn.disabled = true;
try {
await invoke("connect", { appId });
setConnected(true);
toast("Connected to Discord", "success");
} catch (e) {
toast(e, "error");
} finally {
connectBtn.disabled = false;
}
}
}
function setConnected(state) {
connected = state;
connectBtn.textContent = state ? "Disconnect" : "Connect";
statusDot.className = `status-dot ${state ? "on" : "off"}`;
statusLabel.textContent = state ? "Connected" : "Disconnected";
setBtn.disabled = !state;
clearBtn.disabled = !state;
appIdInput.disabled = state;
if (state) {
timerStart = Date.now();
startTimer();
} else {
stopTimer();
timerStart = null;
}
}
async function setActivity() {
const status = statusInput.value.trim();
const details = detailsInput.value.trim();
const showTime = showTimeCheck.checked;
const hours = parseInt(document.getElementById("elapsedHours").value) || 0;
const mins = parseInt(document.getElementById("elapsedMins").value) || 0;
const elapsedSeconds = (hours * 3600) + (mins * 60);
try {
await invoke("set_activity", { status, details, showTime, elapsedSeconds });
if (elapsedSeconds > 0) {
timerStart = Date.now() - (elapsedSeconds * 1000);
}
updatePreview(status, details, showTime);
toast("Status updated", "success");
} catch (e) {
toast(e, "error");
}
}
async function clearActivity() {
try {
await invoke("clear_activity");
resetPreview();
toast("Presence cleared", "neutral");
} catch (e) {
toast(e, "error");
}
}
function updatePreview(status, details, showTime) {
previewTitle.textContent = appIdInput.value ? "Your App Name" : "—";
if (status) {
previewStatus.textContent = status;
previewStatus.classList.remove("hidden");
} else {
previewStatus.classList.add("hidden");
}
if (details) {
previewDetails.textContent = details;
previewDetails.classList.remove("hidden");
} else {
previewDetails.classList.add("hidden");
}
if (showTime) {
previewTime.classList.remove("hidden");
} else {
previewTime.classList.add("hidden");
}
}
function resetPreview() {
previewTitle.textContent = "—";
previewStatus.classList.add("hidden");
previewDetails.classList.add("hidden");
previewTime.classList.add("hidden");
}
statusInput.addEventListener("input", () => {
if (previewStatus.textContent || statusInput.value) {
previewStatus.textContent = statusInput.value || "";
previewStatus.classList.toggle("hidden", !statusInput.value);
}
});
detailsInput.addEventListener("input", () => {
if (previewDetails.textContent || detailsInput.value) {
previewDetails.textContent = detailsInput.value || "";
previewDetails.classList.toggle("hidden", !detailsInput.value);
}
});
statusInput.addEventListener("keydown", (e) => { if (e.key === "Enter" && connected) setActivity(); });
detailsInput.addEventListener("keydown", (e) => { if (e.key === "Enter" && connected) setActivity(); });
appIdInput.addEventListener("keydown", (e) => { if (e.key === "Enter" && !connected) toggleConnection(); });
function startTimer() {
stopTimer();
timerInterval = setInterval(() => {
if (!timerStart) return;
const elapsed = Math.floor((Date.now() - timerStart) / 1000);
const h = Math.floor(elapsed / 3600);
const m = Math.floor((elapsed % 3600) / 60);
const s = elapsed % 60;
const parts = [];
if (h > 0) parts.push(String(h).padStart(2, "0"));
parts.push(String(m).padStart(2, "0"));
parts.push(String(s).padStart(2, "0"));
previewTime.textContent = parts.join(":") + " elapsed";
}, 1000);
}
function stopTimer() {
if (timerInterval) {
clearInterval(timerInterval);
timerInterval = null;
}
}
function openHelp() {
document.getElementById("helpModal").classList.remove("hidden");
}
function closeHelp() {
document.getElementById("helpModal").classList.add("hidden");
}
document.addEventListener("keydown", (e) => {
if (e.key === "Escape") closeHelp();
});
function toast(msg, type = "neutral") {
const container = document.getElementById("toastContainer");
const colors = {
success: "bg-emerald-900/80 border-emerald-700/50 text-emerald-200",
error: "bg-rose-900/80 border-rose-700/50 text-rose-200",
neutral: "bg-surface-700/90 border-surface-600/50 text-slate-300",
};
const el = document.createElement("div");
el.className = `toast text-xs px-4 py-2 rounded-lg border backdrop-blur-sm ${colors[type] || colors.neutral}`;
el.textContent = msg;
container.appendChild(el);
setTimeout(() => el.remove(), 2600);
}