Skip to content

Commit

Permalink
Stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Hacksore committed Nov 12, 2023
1 parent 0147906 commit 831be45
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 75 deletions.
15 changes: 10 additions & 5 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
extern crate objc;

use tauri::{
generate_handler, CustomMenuItem, Manager, RunEvent, State, SystemTray, SystemTrayEvent,
SystemTrayMenu, Window, ActivationPolicy,
generate_handler, ActivationPolicy, App, CustomMenuItem, Manager, RunEvent, State, SystemTray,
SystemTrayEvent, SystemTrayMenu, Window,
};

#[cfg(target_os = "macos")]
Expand Down Expand Up @@ -60,6 +60,12 @@ fn get_clickthrough(clickthrough: State<'_, Clickthrough>) -> bool {
clickthrough.0.load(std::sync::atomic::Ordering::Relaxed)
}

#[cfg(target_os = "macos")]
fn apply_macos_specifics(app: &mut App, window: &Window) {
window.set_transparent_titlebar(true, true);
app.set_activation_policy(ActivationPolicy::Accessory);
}

fn main() {
// System tray configuration
let tray = SystemTray::new().with_menu(
Expand All @@ -84,9 +90,8 @@ fn main() {

window.set_always_on_top(true);

#[cfg(target_os = "macos")]
window.set_transparent_titlebar(true, true);
app.set_activation_policy(ActivationPolicy::Accessory);
// add mac things
apply_macos_specifics(app, &window);

// Open dev tools only when in dev mode
#[cfg(debug_assertions)]
Expand Down
14 changes: 6 additions & 8 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@ function App() {
className={`text-white h-screen select-none ${border} border-transparent border-2 rounded-lg bg-zinc-900}`}
>
<NavBar clickthrough={clickthrough} />
<div className="container">
<Routes>
<Route path="/" Component={Main} />
<Route path="/channel" Component={Channel} />
<Route path="/settings" Component={Settings} />
<Route path="/error" Component={Error} />
</Routes>
</div>
<Routes>
<Route path="/" Component={Main} />
<Route path="/channel" Component={Channel} />
<Route path="/settings" Component={Settings} />
<Route path="/error" Component={Error} />
</Routes>
</div>
);
}
Expand Down
19 changes: 14 additions & 5 deletions src/rpc/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,13 @@ class SocketManager {
public currentChannelId = null;
public tokenStore: TokenStore | null = null;
public navigate: NavigateFunction | null = null;
public isConnected = false;

/**
* Setup the websocket connection and listen for messages
*/
async init(navigate: NavigateFunction) {
if (this.socket) {
// make sure to disconnect the socket if init is called again
this.socket.disconnect();
}
this.disconnect();

this.tokenStore = new TokenStore();
this.navigate = navigate;
Expand All @@ -83,13 +81,21 @@ class SocketManager {
},
});

this.isConnected = true;

this.socket.addListener(this.onMessage.bind(this));
} catch (e) {
console.log(e);
this.isConnected = false;
this.navigate?.("/error");
}
}

public disconnect() {
this.socket?.disconnect();
this.isConnected = false;
}

// we have to call the store to get the latest values
private get store(): AppState & AppActions {
return appStore.getState();
Expand Down Expand Up @@ -138,6 +144,7 @@ class SocketManager {

const payload: DiscordPayload = JSON.parse(event.data);

console.log(payload);
// either the token is good and valid and we can login otherwise prompt them approve
if (payload.evt === RPCEvent.READY) {
const acessToken = this.tokenStore?.accessToken;
Expand Down Expand Up @@ -225,7 +232,9 @@ class SocketManager {
payload.cmd === RPCCommand.AUTHENTICATE &&
payload.evt === RPCEvent.ERROR
) {
// TODO: haandle moar errors
if (payload.data.code === 5000) {
}

if (payload.data.code === 4009) {
this.tokenStore?.removeAccessToken();
}
Expand Down
39 changes: 23 additions & 16 deletions src/views/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,30 @@ export const Main = () => {

return (
<div className="h-screen p-2 bg-zinc-800">
<div className="pt-1 mb-3 font-bold text-2xl text-center">
<p>Authorize Discord</p>
</div>
{!socket?.isConnected ? (
<div className="flex items-center justify-center h-full">
<div className="animate-spin rounded-full h-32 w-32 border-t-2 border-b-2 border-white"></div>
</div>
) : (
<>
<div className="pt-1 mb-3 font-bold text-2xl text-center">
<p>Authorize Discord</p>
</div>

<img src="/img/login.png" alt="login" className="w-full" />

<div className="pt-8 text-2xl flex items-center flex-col justify-center">
<p>Request Prompt again</p>
<Button
onClick={() => {
socket?.init(navigate);
}}
className="bg-blue-800 p-2 rounded-md"
>
Authorize Discord
</Button>
</div>
<img src="/img/login.png" alt="login" className="w-full" />
<div className="pt-8 text-2xl flex items-center flex-col justify-center">
<p>Request Prompt again</p>
<Button
onClick={() => {
socket?.init(navigate);
}}
className="bg-blue-800 p-2 rounded-md"
>
Authorize Discord
</Button>
</div>
</>
)}
</div>
);
};
96 changes: 55 additions & 41 deletions src/views/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,70 @@ import { usePaths } from "../use-paths";
import { Button } from "../components/ui/button";
import { useAppStore } from "../store";
import { shell } from "@tauri-apps/api";
import { LogicalSize, appWindow } from "@tauri-apps/api/window";
import { useEffect } from "react";

export const Settings = () => {
const navigate = useNavigate();
const paths = usePaths();
const { me, setMe } = useAppStore();

useEffect(() => {
appWindow.outerSize().then((size) => {
appWindow.setSize(new LogicalSize(size.width, 700));
});
}, []);

return (
<div className="flex flex-col bg-zinc-800 min-h-screen p-4 pt-4 pb-4">
<h1 className="text-xl font-bold">Settings</h1>
<div className="flex flex-col justify-between bg-zinc-800 h-full p-4 pt-4 pb-14">
<div>
<h1 className="text-xl font-bold">Settings</h1>

<h2 className="text-lg font-bold mt-4">Directories</h2>
<div className="flex gap-4">
<Button
className="w-full"
disabled
onClick={async () => {
if (!paths.logDir) return;
await shell.open(paths.logDir);
}}
>
Open Log Dir
</Button>
<Button
className="w-full"
onClick={async () => {
if (!paths.configDir) return;
await shell.open(paths.configDir);
}}
>
Open App Dir
</Button>
</div>
<h2 className="text-lg font-bold mt-4">Discord</h2>
<div className="">
<pre>{JSON.stringify({ id: me?.id }, null, 2)}</pre>
<Button
disabled={!me?.id}
className="w-full"
intent="danger"
onClick={() => {
localStorage.removeItem("discord_access_token");
setMe(null);
navigate("/");
}}
>
logout
</Button>
</div>
<div>
<h2 className="text-lg font-bold mt-4">Directories</h2>
<div className="flex gap-4">
<Button
className="w-full"
disabled
onClick={async () => {
if (!paths.logDir) return;
await shell.open(paths.logDir);
}}
>
Open Log Dir
</Button>
<Button
className="w-full"
onClick={async () => {
if (!paths.configDir) return;
await shell.open(paths.configDir);
}}
>
Open App Dir
</Button>
</div>
</div>
<div>
<h2 className="text-lg font-bold mt-4">Discord</h2>
<div className="">
<pre>{JSON.stringify({ id: me?.id }, null, 2)}</pre>
<Button
disabled={!me?.id}
className="w-full"
intent="danger"
onClick={() => {
localStorage.removeItem("discord_access_token");
setMe(null);
navigate("/");
}}
>
logout
</Button>
</div>
</div>

<hr className="my-8 border-gray-700" />
<hr className="my-8 border-gray-700" />
</div>
<div className="">
<Button
className="w-full"
Expand Down

0 comments on commit 831be45

Please sign in to comment.