mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-11 05:46:17 +00:00
feat: add workwonders
This commit is contained in:
@@ -91,6 +91,7 @@
|
|||||||
"user-agents": "^1.1.387",
|
"user-agents": "^1.1.387",
|
||||||
"uuid": "^13.0.0",
|
"uuid": "^13.0.0",
|
||||||
"winreg": "^1.2.5",
|
"winreg": "^1.2.5",
|
||||||
|
"workwonders-sdk": "0.0.9",
|
||||||
"ws": "^8.18.1",
|
"ws": "^8.18.1",
|
||||||
"yaml": "^2.6.1",
|
"yaml": "^2.6.1",
|
||||||
"yup": "^1.5.0"
|
"yup": "^1.5.0"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useCallback, useEffect, useRef, useState } from "react";
|
import { useCallback, useEffect, useRef, useState } from "react";
|
||||||
import { Sidebar, BottomPanel, Header, Toast } from "@renderer/components";
|
import { Sidebar, BottomPanel, Header, Toast } from "@renderer/components";
|
||||||
|
import { WorkWondersSdk } from "workwonders-sdk";
|
||||||
import {
|
import {
|
||||||
useAppDispatch,
|
useAppDispatch,
|
||||||
useAppSelector,
|
useAppSelector,
|
||||||
@@ -52,6 +52,8 @@ export function App() {
|
|||||||
|
|
||||||
const { clearDownload, setLastPacket } = useDownload();
|
const { clearDownload, setLastPacket } = useDownload();
|
||||||
|
|
||||||
|
const wokwondersRef = useRef<WorkWondersSdk | null>(null);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
hasActiveSubscription,
|
hasActiveSubscription,
|
||||||
fetchUserDetails,
|
fetchUserDetails,
|
||||||
@@ -114,7 +116,24 @@ export function App() {
|
|||||||
return () => unsubscribe();
|
return () => unsubscribe();
|
||||||
}, [updateLibrary]);
|
}, [updateLibrary]);
|
||||||
|
|
||||||
useEffect(() => {
|
const setupWorkWonders = useCallback(
|
||||||
|
async (token?: string, locale?: string) => {
|
||||||
|
if (wokwondersRef.current) return;
|
||||||
|
|
||||||
|
wokwondersRef.current = new WorkWondersSdk();
|
||||||
|
await wokwondersRef.current.init({
|
||||||
|
organization: "hydra",
|
||||||
|
token,
|
||||||
|
locale,
|
||||||
|
});
|
||||||
|
|
||||||
|
await wokwondersRef.current.initChangelogWidget();
|
||||||
|
wokwondersRef.current.initChangelogWidgetMini();
|
||||||
|
},
|
||||||
|
[wokwondersRef]
|
||||||
|
);
|
||||||
|
|
||||||
|
const setupExternalResources = useCallback(async () => {
|
||||||
const cachedUserDetails = window.localStorage.getItem("userDetails");
|
const cachedUserDetails = window.localStorage.getItem("userDetails");
|
||||||
|
|
||||||
if (cachedUserDetails) {
|
if (cachedUserDetails) {
|
||||||
@@ -125,21 +144,26 @@ export function App() {
|
|||||||
dispatch(setProfileBackground(profileBackground));
|
dispatch(setProfileBackground(profileBackground));
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchUserDetails()
|
const userPreferences = await window.electron.getUserPreferences();
|
||||||
.then((response) => {
|
const userDetails = await fetchUserDetails().catch(() => null);
|
||||||
if (response) {
|
|
||||||
updateUserDetails(response);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
if (document.getElementById("external-resources")) return;
|
|
||||||
|
|
||||||
const $script = document.createElement("script");
|
if (userDetails) {
|
||||||
$script.id = "external-resources";
|
updateUserDetails(userDetails);
|
||||||
$script.src = `${import.meta.env.RENDERER_VITE_EXTERNAL_RESOURCES_URL}/bundle.js?t=${Date.now()}`;
|
}
|
||||||
document.head.appendChild($script);
|
|
||||||
});
|
setupWorkWonders(userDetails?.workwondersJwt, userPreferences?.language);
|
||||||
}, [fetchUserDetails, updateUserDetails, dispatch]);
|
|
||||||
|
if (!document.getElementById("external-resources")) {
|
||||||
|
const $script = document.createElement("script");
|
||||||
|
$script.id = "external-resources";
|
||||||
|
$script.src = `${import.meta.env.RENDERER_VITE_EXTERNAL_RESOURCES_URL}/bundle.js?t=${Date.now()}`;
|
||||||
|
document.head.appendChild($script);
|
||||||
|
}
|
||||||
|
}, [fetchUserDetails, updateUserDetails, dispatch, setupWorkWonders]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setupExternalResources();
|
||||||
|
}, [setupExternalResources]);
|
||||||
|
|
||||||
const onSignIn = useCallback(() => {
|
const onSignIn = useCallback(() => {
|
||||||
fetchUserDetails().then((response) => {
|
fetchUserDetails().then((response) => {
|
||||||
@@ -203,6 +227,7 @@ export function App() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (contentRef.current) contentRef.current.scrollTop = 0;
|
if (contentRef.current) contentRef.current.scrollTop = 0;
|
||||||
|
wokwondersRef.current?.notifyUrlChange();
|
||||||
}, [location.pathname, location.search]);
|
}, [location.pathname, location.search]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ export function useUserDetails() {
|
|||||||
username: userDetails?.username || "",
|
username: userDetails?.username || "",
|
||||||
subscription: userDetails?.subscription || null,
|
subscription: userDetails?.subscription || null,
|
||||||
featurebaseJwt: userDetails?.featurebaseJwt || "",
|
featurebaseJwt: userDetails?.featurebaseJwt || "",
|
||||||
|
workwondersJwt: userDetails?.workwondersJwt || "",
|
||||||
karma: userDetails?.karma || 0,
|
karma: userDetails?.karma || 0,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -187,6 +187,7 @@ export interface UserDetails {
|
|||||||
profileVisibility: ProfileVisibility;
|
profileVisibility: ProfileVisibility;
|
||||||
bio: string;
|
bio: string;
|
||||||
featurebaseJwt: string;
|
featurebaseJwt: string;
|
||||||
|
workwondersJwt: string;
|
||||||
subscription: Subscription | null;
|
subscription: Subscription | null;
|
||||||
karma: number;
|
karma: number;
|
||||||
quirks?: {
|
quirks?: {
|
||||||
|
|||||||
12
yarn.lock
12
yarn.lock
@@ -6354,6 +6354,11 @@ keyv@^4.0.0, keyv@^4.5.3:
|
|||||||
dependencies:
|
dependencies:
|
||||||
json-buffer "3.0.1"
|
json-buffer "3.0.1"
|
||||||
|
|
||||||
|
ky@^1.11.0:
|
||||||
|
version "1.14.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/ky/-/ky-1.14.1.tgz#16f20b3bf3939abcc04e2a9613f47360fe5f64c9"
|
||||||
|
integrity sha512-hYje4L9JCmpEQBtudo+v52X5X8tgWXUYyPcxKSuxQNboqufecl9VMWjGiucAFH060AwPXHZuH+WB2rrqfkmafw==
|
||||||
|
|
||||||
language-subtag-registry@^0.3.20:
|
language-subtag-registry@^0.3.20:
|
||||||
version "0.3.23"
|
version "0.3.23"
|
||||||
resolved "https://registry.yarnpkg.com/language-subtag-registry/-/language-subtag-registry-0.3.23.tgz#23529e04d9e3b74679d70142df3fd2eb6ec572e7"
|
resolved "https://registry.yarnpkg.com/language-subtag-registry/-/language-subtag-registry-0.3.23.tgz#23529e04d9e3b74679d70142df3fd2eb6ec572e7"
|
||||||
@@ -9123,6 +9128,13 @@ word-wrap@^1.2.5:
|
|||||||
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.5.tgz#d2c45c6dd4fbce621a66f136cbe328afd0410b34"
|
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.5.tgz#d2c45c6dd4fbce621a66f136cbe328afd0410b34"
|
||||||
integrity sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==
|
integrity sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==
|
||||||
|
|
||||||
|
workwonders-sdk@0.0.9:
|
||||||
|
version "0.0.9"
|
||||||
|
resolved "https://registry.yarnpkg.com/workwonders-sdk/-/workwonders-sdk-0.0.9.tgz#ec2cf8f47304cc9c52b273383443f3978cd381a1"
|
||||||
|
integrity sha512-ZhzOXL+/Vq9wCzneE8NUvL3RVIaFMygFtjO5BKXSXsP1iSq2jZ9l3xedmxwZyyTvMYN5t4oIwCwFE0NWujtH9A==
|
||||||
|
dependencies:
|
||||||
|
ky "^1.11.0"
|
||||||
|
|
||||||
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
|
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
|
||||||
version "7.0.0"
|
version "7.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
|
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
|
||||||
|
|||||||
Reference in New Issue
Block a user