Skip to content

Commit

Permalink
wip: discord rich presence using rust integration
Browse files Browse the repository at this point in the history
  • Loading branch information
lmaosoggypancakes committed Jun 18, 2023
1 parent f5b8a68 commit 4a3de9d
Show file tree
Hide file tree
Showing 12 changed files with 207 additions and 73 deletions.
8 changes: 8 additions & 0 deletions layouts/learn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@
</article>
</App>
</template>

<script setup lang="ts">
import App from "./app.vue";
import { Activity } from "~/types";
onMounted(() => {
setDiscordActivity(Activity.docs);
});
</script>
178 changes: 178 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@pinia-plugin-persistedstate/nuxt": "^1.1.1",
"@pinia/nuxt": "^0.4.9",
"@tauri-apps/api": "^1.4.0",
"@tauri-apps/cli": "^1.4.0",
"@vueuse/motion": "^2.0.0-beta.25",
"axios": "^1.3.4",
"discord-rpc": "^4.0.1",
Expand Down
4 changes: 4 additions & 0 deletions pages/app/account.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,14 @@
import { UserEdit, PlayerGame, User, GameStatus, Activity } from "@/types";
import { Popover, PopoverButton, PopoverPanel } from "@headlessui/vue";
import axios from "axios";
definePageMeta({
middleware: ["auth"],
layout: "app",
});
onMounted(() => {
setDiscordActivity(Activity.avatar);
});
const config = useRuntimeConfig();
const auth = useAuth();
const user = useUser();
Expand Down
3 changes: 3 additions & 0 deletions pages/app/play/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ import {
} from "@headlessui/vue";
import axios from "axios";
onMounted(() => {
setDiscordActivity(Activity.playing);
});
const MAX_SCORE = 20;
const router = useRouter();
const auth = useAuth();
Expand Down
1 change: 1 addition & 0 deletions pages/app/play/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const status = reactive({
});
const disabled = computed(() => Object.values(status).some((a) => !!a));
const matchmake = async (difficulty: Difficulty) => {
setDiscordActivity(Activity.matchmaking);
status.connecting = true;
const socket = io(`${config.public.apiUrl}/matchmake`, {
auth: {
Expand Down
4 changes: 4 additions & 0 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@

<script setup>
definePageMeta({ layout: "index" });
import { Activity } from "~/types";
onMounted(() => {
setDiscordActivity(Activity.index);
});
</script>
22 changes: 0 additions & 22 deletions src-tauri/Cargo.lock

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

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ tauri-build = { version = "1.2.1", features = [] }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.2.4", features = ["shell-open", "shell-sidecar"] }
tauri = { version = "1.2.4", features = ["shell-open"] }
discord-presence = "0.5.15"
once_cell = "1.18.0"

Expand Down
49 changes: 2 additions & 47 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,56 +41,11 @@ fn main() {
}

#[tauri::command]
fn avatar() {
fn set_discord_activity(details: String) {
unsafe {

DRPC.set_activity(|a| {
a.details("Editing Avatar").assets(|ass| {
ass.large_image("logo")
})
.timestamps(|time| {
time.start(time::SystemTime::now().duration_since(time::UNIX_EPOCH).expect("Error").as_secs())
})
});
}
}

#[tauri::command]
fn matchmaking() {
unsafe {

DRPC.set_activity(|a| {
a.details("In queue (1 of 2)").assets(|ass| {
ass.large_image("logo")
})
.timestamps(|time| {
time.start(time::SystemTime::now().duration_since(time::UNIX_EPOCH).expect("Error").as_secs())
})
});
}
}

#[tauri::command]
fn docs() {
unsafe {

DRPC.set_activity(|a| {
a.details("Browsing Documentation").assets(|ass| {
ass.large_image("logo")
})
.timestamps(|time| {
time.start(time::SystemTime::now().duration_since(time::UNIX_EPOCH).expect("Error").as_secs())
})
});
}
}

#[tauri::command]
fn playing() {
unsafe {

DRPC.set_activity(|a| {
a.details("In Match").assets(|ass| {
a.details(details).assets(|ass| {
ass.large_image("logo")
})
.timestamps(|time| {
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"allowlist": {
"shell": {
"open": true,
"sidecar": true,
"sidecar": false,
"scope": []
}
},
Expand Down
6 changes: 4 additions & 2 deletions utils/discord.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { invoke } from "@tauri-apps/api/tauri";
import { Activity } from "~/types";
const setDiscordActivity = (a: Activity) => {
return null;
export const setDiscordActivity = (a: Activity) => {
if (!window.__TAURI_IPC__) return;
invoke("set_discord_activity", { details: a });
};

1 comment on commit 4a3de9d

@vercel
Copy link

@vercel vercel bot commented on 4a3de9d Jun 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.