Skip to content

Commit 1104021

Browse files
committed
feat: add sync halo info button
1 parent 9a7d267 commit 1104021

2 files changed

Lines changed: 62 additions & 5 deletions

File tree

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"name": "halo-discord-extension",
3-
"version": "2.3.0",
3+
"version": "2.4.0",
44
"description": "Receive Discord notifications for updates in Halo",
55
"author": "Elijah Olmos",
66
"license": "AGPL-3.0-only",
77
"type": "module",
88
"private": true,
99
"scripts": {
10-
"test:chrome": "rollup -c -w --configChrome",
11-
"test:firefox": "rollup -c -w --configFirefox",
10+
"dev:chrome": "rollup -c -w --configChrome",
11+
"dev:firefox": "rollup -c -w --configFirefox",
1212
"build": "pnpm run build:chrome && pnpm run build:firefox",
1313
"build:chrome": "rollup -c --configChrome",
1414
"build:firefox": "rollup -c --configFirefox"

src/popup/components/Navbar.svelte

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,42 @@
1414
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
1515
-->
1616
<script>
17+
import { stores } from '../../stores';
18+
import { setUserCookies } from '../../util/auth';
19+
import { validateCookie } from '../../util/halo';
20+
import { auth, getHaloCookies, isValidCookieObject } from '../../util/util';
21+
1722
export let user;
1823
1924
// ------- state -------
2025
let isDropdownOpen = false;
26+
let isSyncingInfo = false;
2127
2228
// daisyui dropdown stuff from https://svelte.dev/repl/4c5dfd34cc634774bd242725f0fc2dab
2329
const handleDropdownClick = () => (isDropdownOpen = !isDropdownOpen);
2430
const handleDropdownFocusLoss = ({ relatedTarget, currentTarget }) => {
2531
if (relatedTarget instanceof HTMLElement && currentTarget.contains(relatedTarget)) return;
2632
isDropdownOpen = false;
2733
};
34+
35+
const syncHaloInfo = async function () {
36+
if (isSyncingInfo) return;
37+
isSyncingInfo = true;
38+
try {
39+
console.log('sweeping cookies - manual');
40+
const cookies = await getHaloCookies();
41+
if (!isValidCookieObject(cookies)) throw new Error('Invalid cookie object');
42+
if (!(await validateCookie({ cookie: cookies }))) throw new Error('cookie failed validateCookie check');
43+
44+
stores.halo_cookies.update(cookies);
45+
!!auth.currentUser && (await setUserCookies({ uid: auth.currentUser.uid, cookies }));
46+
} catch (e) {
47+
console.error('[error] sweping cookies manual', e);
48+
alert('Failed to resync Halo info');
49+
} finally {
50+
isSyncingInfo = false;
51+
}
52+
};
2853
</script>
2954

3055
<div class="navbar">
@@ -48,8 +73,40 @@
4873
class="mt-3 p-2 shadow menu menu-compact dropdown-content rounded-box bg-base-200 w-52"
4974
style:visibility={isDropdownOpen ? 'visible' : 'hidden'}
5075
>
51-
<li><a>{user.username}#{user.discriminator}</a></li>
52-
<!-- <li><a>Logout</a></li> -->
76+
<li>
77+
<a>{user.username}#{user.discriminator} </a>
78+
</li>
79+
<li on:click={syncHaloInfo}>
80+
<a
81+
>Sync Halo Info
82+
{#if isSyncingInfo}
83+
<div class="badge badge-lg">
84+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 512 512"
85+
><circle cx="256" cy="256" r="48" /><circle cx="416" cy="256" r="48" /><circle
86+
cx="96"
87+
cy="256"
88+
r="48"
89+
/></svg
90+
>
91+
</div>
92+
{:else}
93+
<div class="badge badge-lg">
94+
<svg
95+
xmlns="http://www.w3.org/2000/svg"
96+
width="16"
97+
height="16"
98+
fill="currentColor"
99+
class="bi bi-check"
100+
viewBox="0 0 16 16"
101+
>
102+
<path
103+
d="M10.97 4.97a.75.75 0 0 1 1.07 1.05l-3.99 4.99a.75.75 0 0 1-1.08.02L4.324 8.384a.75.75 0 1 1 1.06-1.06l2.094 2.093 3.473-4.425a.267.267 0 0 1 .02-.022z"
104+
/>
105+
</svg>
106+
</div>
107+
{/if}
108+
</a>
109+
</li>
53110
</ul>
54111
</div>
55112
</div>

0 commit comments

Comments
 (0)