Skip to content

Commit 1fa8f72

Browse files
Merge pull request #25 from calebsmithdev/issue-14
Notifications can now be enabled separately
2 parents 62c6083 + 2b879d7 commit 1fa8f72

4 files changed

Lines changed: 47 additions & 4 deletions

File tree

src-tauri/tauri.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
},
4242
"productName": "Wowthing Sync",
4343
"mainBinaryName": "Wowthing Sync",
44-
"version": "1.0.1",
44+
"version": "1.0.2",
4545
"identifier": "com.calebsmithdev.wowthing-sync",
4646
"plugins": {
4747
"updater": {

src/composables/useNotifications.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,36 @@
1+
import { info } from "@tauri-apps/plugin-log";
12
import { isPermissionGranted, requestPermission, sendNotification } from "@tauri-apps/plugin-notification";
3+
import { NOTIFICATIONS_ENABLED } from "~/constants";
24

35
export const useNotifications = () => {
6+
const _notificationsEnabled = ref(false);
7+
8+
const getValue = async (): Promise<void> => {
9+
const value = await getStorageItem<boolean>(NOTIFICATIONS_ENABLED)
10+
_notificationsEnabled.value = value ?? false;
11+
}
12+
13+
const setValue = async (value: boolean): Promise<void> => {
14+
await saveStorageItem(NOTIFICATIONS_ENABLED, value)
15+
_notificationsEnabled.value = value;
16+
17+
if (value) {
18+
let permissionGranted = await isPermissionGranted();
19+
20+
if (!permissionGranted) {
21+
const permission = await requestPermission();
22+
permissionGranted = permission === 'granted';
23+
}
24+
}
25+
send({ title: 'Notifications enabled', body: 'You will now receive notifications' });
26+
info(`Option for enabling notifications: ${_notificationsEnabled.value}`);
27+
}
28+
429
const send = async (options) => {
30+
if(!notificationsEnabled.value) {
31+
return;
32+
}
33+
534
let permissionGranted = await isPermissionGranted();
635

736
if (!permissionGranted) {
@@ -14,7 +43,17 @@ export const useNotifications = () => {
1443
}
1544
};
1645

46+
const notificationsEnabled = computed({
47+
get: () => _notificationsEnabled.value,
48+
set: (value: boolean) => setValue(value),
49+
});
50+
51+
onMounted(() => {
52+
getValue();
53+
});
54+
1755
return {
56+
notificationsEnabled,
1857
send
1958
}
2059
}

src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export const API_KEY = 'api-key'
22
export const AUTO_START = 'auto-start'
3+
export const NOTIFICATIONS_ENABLED = 'notifications-enabled'
34
export const PROGRAM_FOLDER = 'program-folder'
45
export const LAST_UPDATED = 'last-updated';
56
export const LAST_STARTED_DATE = 'last-started-date';

src/pages/settings.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
<div class="container pt-5">
33
<h1 class="mb-5">Settings</h1>
44

5-
<UCheckbox label="Launch WoWthing Sync when you start your computer" v-model="autoStart" class="mb-6" />
6-
75
<UFormGroup label="API Key" name="apiKey" help="Visit Settings -> Account to find your API Key." class="mb-6">
86
<UInput v-model="apiKey" autocomplete="off" :ui="{ icon: { trailing: { pointer: '' } } }" :type="showPassword ? 'text' : 'password'">
97
<template #trailing>
@@ -18,13 +16,17 @@
1816
</UInput>
1917
</UFormGroup>
2018

21-
<UFormGroup label='World of Warcraft "_retail_" Folder' name="folder">
19+
<UFormGroup label='World of Warcraft "_retail_" Folder' name="folder" class="mb-6">
2220
<UInput v-model="folder" readonly @click="openFolderDialog">
2321
<template #trailing>
2422
<span class="text-gray-500 dark:text-gray-400 text-xs">Choose Directory</span>
2523
</template>
2624
</UInput>
2725
</UFormGroup>
26+
27+
<UCheckbox label="Enable desktop notifications" v-model="notificationsEnabled" class="mb-2" />
28+
29+
<UCheckbox label="Launch WoWthing Sync when you start your computer" v-model="autoStart" class="mb-2" />
2830
</div>
2931
</template>
3032

@@ -36,6 +38,7 @@
3638
const autoStart = useAutoStart();
3739
const { folder, getDefaultPath } = useProgramFolder();
3840
const showPassword = ref(false);
41+
const { notificationsEnabled } = useNotifications();
3942
4043
const openFolderDialog = async () => {
4144
const defaultPath = await getDefaultPath();

0 commit comments

Comments
 (0)