Skip to content

Commit

Permalink
automatically swap back to stable if user does not have sub
Browse files Browse the repository at this point in the history
  • Loading branch information
NikhilNarayana committed Aug 15, 2023
1 parent b0c118a commit 9d0f324
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/renderer/containers/Header/UserMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DolphinLaunchType } from "@dolphin/types";
import AccountBoxIcon from "@mui/icons-material/AccountBox";
import EditIcon from "@mui/icons-material/Edit";
import LanguageIcon from "@mui/icons-material/Language";
Expand All @@ -11,6 +12,7 @@ import { ConfirmationModal } from "@/components/ConfirmationModal";
import type { IconMenuItem } from "@/components/IconMenu";
import { IconMenu } from "@/components/IconMenu";
import { useAccount } from "@/lib/hooks/useAccount";
import { useDolphinBeta } from "@/lib/hooks/useSettings";
import { useServices } from "@/services";
import type { AuthUser } from "@/services/auth/types";

Expand All @@ -27,6 +29,9 @@ export const UserMenu = ({ user, handleError }: { user: AuthUser; handleError: (
const [openLogoutPrompt, setOpenLogoutPrompt] = React.useState(false);
const [openNameChangePrompt, setOpenNameChangePrompt] = React.useState(false);
const [openActivationDialog, setOpenActivationDialog] = React.useState(false);
const [useNetplayBeta, setUseNetplayBeta] = useDolphinBeta(DolphinLaunchType.NETPLAY);
const [usePlaybackBeta, setUsePlaybackBeta] = useDolphinBeta(DolphinLaunchType.PLAYBACK);

const onLogout = async () => {
try {
await authService.logout();
Expand All @@ -35,6 +40,12 @@ export const UserMenu = ({ user, handleError }: { user: AuthUser; handleError: (
handleError(err);
} finally {
handleClose();
if (useNetplayBeta) {
await setUseNetplayBeta(false);
}
if (usePlaybackBeta) {
await setUsePlaybackBeta(false);
}
}
};

Expand Down
20 changes: 20 additions & 0 deletions src/renderer/lib/hooks/useApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import { useAccount } from "@/lib/hooks/useAccount";
import { useToasts } from "@/lib/hooks/useToasts";
import { useServices } from "@/services";
import type { AuthUser } from "@/services/auth/types";
import { SubscriptionTier } from "@/services/slippi/types";

import { useDesktopApp } from "./useQuickStart";
import { useDolphinBeta } from "./useSettings";

const log = window.electron.log;

Expand Down Expand Up @@ -42,6 +44,8 @@ export const useAppInitialization = () => {
const setServerError = useAccount((store) => store.setServerError);
const setDesktopAppExists = useDesktopApp((store) => store.setExists);
const setDesktopAppDolphinPath = useDesktopApp((store) => store.setDolphinPath);
const [useNetplayBeta, setUseNetplayBeta] = useDolphinBeta(DolphinLaunchType.NETPLAY);
const [usePlaybackBeta, setUsePlaybackBeta] = useDolphinBeta(DolphinLaunchType.PLAYBACK);

const initialize = async () => {
if (initializing || initialized) {
Expand Down Expand Up @@ -70,6 +74,15 @@ export const useAppInitialization = () => {
const userData = await slippiBackendService.fetchUserData();
setServerError(false);
setUserData(userData);
if (userData?.subscriptionTier === undefined || userData.subscriptionTier === SubscriptionTier.NONE) {
log.warn("user is not subscribed, removing use of beta builds");
if (useNetplayBeta) {
await setUseNetplayBeta(false);
}
if (usePlaybackBeta) {
await setUsePlaybackBeta(false);
}
}
} catch (err) {
setServerError(true);
log.warn(err);
Expand All @@ -78,6 +91,13 @@ export const useAppInitialization = () => {
connection or Slippi is experiencing some downtime. Playing online may or may not work.`;
showError(message);
}
} else {
if (useNetplayBeta) {
await setUseNetplayBeta(false);
}
if (usePlaybackBeta) {
await setUsePlaybackBeta(false);
}
}
})(),
);
Expand Down

0 comments on commit 9d0f324

Please sign in to comment.