Change service later
This commit is contained in:
parent
2d139acffb
commit
aa1ec94f5d
7 changed files with 46 additions and 6 deletions
2
@types/messageHandler.d.ts
vendored
2
@types/messageHandler.d.ts
vendored
|
|
@ -14,7 +14,7 @@ export interface MessageHandler {
|
|||
downloadItem: (data) => void,
|
||||
isDownloading: () => boolean,
|
||||
writeToClipboard: (text: string) => void,
|
||||
openFolder: (path: FolderTypes) => void
|
||||
openFolder: (path: FolderTypes) => void,
|
||||
}
|
||||
|
||||
export type FolderTypes = 'content' | 'config';
|
||||
|
|
|
|||
|
|
@ -883,7 +883,6 @@ export default class Crunchy implements ServiceClass {
|
|||
data: DownloadedMedia[],
|
||||
fileName: string
|
||||
} | undefined> {
|
||||
console.log(options.dlsubs);
|
||||
let mediaName = '...';
|
||||
let fileName;
|
||||
const variables: Variable[] = [];
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ export default (window: BrowserWindow) => {
|
|||
});
|
||||
|
||||
ipcMain.on('changeProvider', (ev) => {
|
||||
if (handler?.isDownloading())
|
||||
return ev.returnValue = false;
|
||||
handler = undefined;
|
||||
ev.returnValue = true;
|
||||
})
|
||||
|
|
|
|||
|
|
@ -2,10 +2,12 @@ import React from "react";
|
|||
import AuthButton from "./components/AuthButton";
|
||||
import { Box } from "@mui/material";
|
||||
import MainFrame from "./components/MainFrame/MainFrame";
|
||||
import LogoutButton from "./components/LogoutButton";
|
||||
|
||||
const Layout: React.FC = () => {
|
||||
return <Box>
|
||||
<Box sx={{ height: 50, mb: 4 }}>
|
||||
<Box sx={{ height: 50, mb: 4, display: 'flex', gap: 1 }}>
|
||||
<LogoutButton />
|
||||
<AuthButton />
|
||||
</Box>
|
||||
<MainFrame />
|
||||
|
|
|
|||
36
gui/react/src/components/LogoutButton.tsx
Normal file
36
gui/react/src/components/LogoutButton.tsx
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import { ExitToApp } from "@mui/icons-material";
|
||||
import { Button } from "@mui/material";
|
||||
import React from "react";
|
||||
import useStore from "../hooks/useStore";
|
||||
import { messageChannelContext } from "../provider/MessageChannel";
|
||||
import Require from "./Require";
|
||||
|
||||
const LogoutButton: React.FC = () => {
|
||||
const messageChannel = React.useContext(messageChannelContext);
|
||||
const [, dispatch] = useStore();
|
||||
|
||||
const logout = () => {
|
||||
if (messageChannel?.isDownloading())
|
||||
return alert('You are currently downloading. Please finish the download first.');
|
||||
if (messageChannel?.logout())
|
||||
dispatch({
|
||||
type: 'service',
|
||||
payload: undefined
|
||||
})
|
||||
else
|
||||
alert('Unable to change service');
|
||||
}
|
||||
|
||||
return <Require value={messageChannel}>
|
||||
<Button
|
||||
startIcon={<ExitToApp />}
|
||||
variant='contained'
|
||||
onClick={logout}
|
||||
>
|
||||
Service select
|
||||
</Button>
|
||||
</Require>
|
||||
|
||||
}
|
||||
|
||||
export default LogoutButton;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import React from "react";
|
||||
import { ExtendedProgress, ProgressData } from "../../../../../../@types/messageHandler";
|
||||
import { ExtendedProgress } from "../../../../../../@types/messageHandler";
|
||||
import { RandomEvent } from "../../../../../../@types/randomEvents";
|
||||
import useStore from "../../../hooks/useStore";
|
||||
import { messageChannelContext } from "../../../provider/MessageChannel";
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import type { Handler, RandomEvent, RandomEvents } from '../../../../@types/rand
|
|||
import { Backdrop, Typography } from '@mui/material';
|
||||
|
||||
|
||||
export type FrontEndMessanges = (MessageHandler & { randomEvents: RandomEventHandler });
|
||||
export type FrontEndMessanges = (MessageHandler & { randomEvents: RandomEventHandler, logout: () => boolean });
|
||||
|
||||
export class RandomEventHandler {
|
||||
private handler: {
|
||||
|
|
@ -81,7 +81,8 @@ const MessageChannelProvider: React.FC = ({ children }) => {
|
|||
downloadItem: (data) => ipcRenderer.invoke('downloadItem', data),
|
||||
isDownloading: () => ipcRenderer.sendSync('isDownloading'),
|
||||
writeToClipboard: async (data) => await ipcRenderer.invoke('writeToClipboard', data),
|
||||
openFolder: async (data) => await ipcRenderer.invoke('openFolder', data)
|
||||
openFolder: async (data) => await ipcRenderer.invoke('openFolder', data),
|
||||
logout: () => ipcRenderer.sendSync('changeProvider')
|
||||
}
|
||||
|
||||
return <messageChannelContext.Provider value={messageHandler}>
|
||||
|
|
|
|||
Loading…
Reference in a new issue