mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2025-12-05 18:20:39 -08:00
refactor: window open senders
This commit is contained in:
parent
e997811a2f
commit
0d1f6c7768
10 changed files with 35 additions and 101 deletions
|
|
@ -14,11 +14,10 @@ import ChevronRightIcon from '@material-ui/icons/ChevronRight';
|
|||
import { DateTimePicker } from '@material-ui/pickers';
|
||||
|
||||
import { format, isTomorrow, isToday, addMinutes, addHours, addDays, addWeeks } from 'date-fns';
|
||||
import { WindowNames } from '@services/windows/WindowProperties';
|
||||
|
||||
import connectComponent from '../../helpers/connect-component';
|
||||
|
||||
import { requestSetPreference, requestShowPreferencesWindow, requestShowNotification } from '../../senders';
|
||||
|
||||
import StatedMenu from '../shared/stated-menu';
|
||||
|
||||
import { updateShowDateTimePicker } from '../../state/notifications/actions';
|
||||
|
|
@ -197,8 +196,8 @@ const DialogPauseNotifications = (props: DialogPauseNotificationsProps) => {
|
|||
<ListItem button>
|
||||
<ListItemText
|
||||
primary={pauseNotificationsInfo.reason === 'scheduled' ? 'Adjust schedule...' : 'Pause notifications by schedule...'}
|
||||
onClick={() => {
|
||||
requestShowPreferencesWindow('notifications');
|
||||
onClick={async () => {
|
||||
await window.service.window.open(WindowNames.preferences, { gotoTab: 'notifications' });
|
||||
window.remote.closeCurrentWindow();
|
||||
}}
|
||||
/>
|
||||
|
|
@ -221,8 +220,8 @@ const DialogPauseNotifications = (props: DialogPauseNotificationsProps) => {
|
|||
<ListItem button>
|
||||
<ListItemText
|
||||
primary="Pause notifications by schedule..."
|
||||
onClick={() => {
|
||||
requestShowPreferencesWindow('notifications');
|
||||
onClick={async () => {
|
||||
await window.service.window.open(WindowNames.preferences, { gotoTab: 'notifications' });
|
||||
window.remote.closeCurrentWindow();
|
||||
}}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -58,26 +58,7 @@ import ListItemDefaultMailClient from './list-item-default-mail-client';
|
|||
import ListItemDefaultBrowser from './list-item-default-browser';
|
||||
import GitTokenForm, { getGithubToken, setGithubToken } from '../shared/git-token-form';
|
||||
import type { IUserInfo } from '@services/types';
|
||||
|
||||
import {
|
||||
requestCheckForUpdates,
|
||||
requestClearBrowsingData,
|
||||
requestOpen,
|
||||
requestQuit,
|
||||
requestRealignActiveWorkspace,
|
||||
requestResetPreferences,
|
||||
requestSetPreference,
|
||||
requestSetSystemPreference,
|
||||
requestShowAboutWindow,
|
||||
requestShowCodeInjectionWindow,
|
||||
requestShowCustomUserAgentWindow,
|
||||
requestShowNotification,
|
||||
requestShowNotificationsWindow,
|
||||
requestShowProxyWindow,
|
||||
requestShowRequireRestartDialog,
|
||||
requestShowSpellcheckLanguagesWindow,
|
||||
getLogFolderPath,
|
||||
} from '../../senders';
|
||||
import { WindowNames } from '@services/windows/WindowProperties';
|
||||
|
||||
const styles = (theme: any) => ({
|
||||
root: {
|
||||
|
|
@ -838,7 +819,7 @@ const Preferences = ({
|
|||
</Typography>
|
||||
<Paper elevation={0} className={classes.paper}>
|
||||
<List dense disablePadding>
|
||||
<ListItem button onClick={requestShowNotificationsWindow}>
|
||||
<ListItem button onClick={async () => await window.service.window.open(WindowNames.notifications)}>
|
||||
<ListItemText primary="Control notifications" />
|
||||
<ChevronRightIcon color="action" />
|
||||
</ListItem>
|
||||
|
|
@ -1004,7 +985,7 @@ const Preferences = ({
|
|||
{window.remote.getPlatform() !== 'darwin' && (
|
||||
<>
|
||||
<Divider />
|
||||
<ListItem button onClick={requestShowSpellcheckLanguagesWindow}>
|
||||
<ListItem button onClick={async () => await window.service.window.open(WindowNames.spellcheck)}>
|
||||
<ListItemText
|
||||
primary="Preferred spell checking languages"
|
||||
// @ts-expect-error ts-migrate(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
|
||||
|
|
@ -1066,7 +1047,7 @@ const Preferences = ({
|
|||
</Typography>
|
||||
<Paper elevation={0} className={classes.paper}>
|
||||
<List disablePadding dense>
|
||||
<ListItem button onClick={requestShowProxyWindow}>
|
||||
<ListItem button onClick={async () => await window.service.window.open(WindowNames.proxy)}>
|
||||
<ListItemText primary="Configure proxy settings (BETA)" />
|
||||
<ChevronRightIcon color="action" />
|
||||
</ListItem>
|
||||
|
|
@ -1209,12 +1190,12 @@ const Preferences = ({
|
|||
</Typography>
|
||||
<Paper elevation={0} className={classes.paper}>
|
||||
<List dense disablePadding>
|
||||
<ListItem button onClick={requestShowCustomUserAgentWindow}>
|
||||
<ListItem button onClick={async () => await window.service.window.open(WindowNames.userAgent)}>
|
||||
<ListItemText primary="Custom User Agent" secondary={customUserAgent || 'Not set'} classes={{ secondary: classes.secondaryEllipsis }} />
|
||||
<ChevronRightIcon color="action" />
|
||||
</ListItem>
|
||||
<Divider />
|
||||
<ListItem button onClick={() => requestShowCodeInjectionWindow('js')}>
|
||||
<ListItem button onClick={async () => await window.service.window.open(WindowNames.codeInjection, { codeInjectionType: 'js' })}>
|
||||
<ListItemText
|
||||
primary="JS Code Injection"
|
||||
secondary={jsCodeInjection ? `Set ${allowNodeInJsCodeInjection ? ' (with access to Node.JS & Electron APIs)' : ''}` : 'Not set'}
|
||||
|
|
@ -1222,7 +1203,7 @@ const Preferences = ({
|
|||
<ChevronRightIcon color="action" />
|
||||
</ListItem>
|
||||
<Divider />
|
||||
<ListItem button onClick={() => requestShowCodeInjectionWindow('css')}>
|
||||
<ListItem button onClick={async () => await window.service.window.open(WindowNames.codeInjection, { codeInjectionType: 'css' })}>
|
||||
<ListItemText primary="CSS Code Injection" secondary={cssCodeInjection ? 'Set' : 'Not set'} />
|
||||
<ChevronRightIcon color="action" />
|
||||
</ListItem>
|
||||
|
|
@ -1395,7 +1376,7 @@ const Preferences = ({
|
|||
</Typography>
|
||||
<Paper elevation={0} className={classes.paper}>
|
||||
<List dense disablePadding>
|
||||
<ListItem button onClick={requestShowAboutWindow}>
|
||||
<ListItem button onClick={async () => await window.service.window.open(WindowNames.about)}>
|
||||
<ListItemText primary="About" />
|
||||
<ChevronRightIcon color="action" />
|
||||
</ListItem>
|
||||
|
|
|
|||
|
|
@ -13,8 +13,9 @@ import NotificationsIcon from '@material-ui/icons/Notifications';
|
|||
import NotificationsPausedIcon from '@material-ui/icons/NotificationsPaused';
|
||||
import SettingsIcon from '@material-ui/icons/Settings';
|
||||
|
||||
// @ts-expect-error ts-migrate(2724) FIXME: '"../../../node_modules/react-sortable-hoc/types"'... Remove this comment to see the full error message
|
||||
import { sortableContainer, sortableElement } from 'react-sortable-hoc';
|
||||
import { WindowNames } from '@services/windows/WindowProperties';
|
||||
|
||||
import { SortableContainer as sortableContainer, SortableElement as sortableElement } from 'react-sortable-hoc';
|
||||
|
||||
import connectComponent from '../../helpers/connect-component';
|
||||
|
||||
|
|
@ -191,11 +192,11 @@ const SortableItem = withTranslation()(
|
|||
const template = [
|
||||
{
|
||||
label: t('WorkspaceSelector.EditWorkspace'),
|
||||
click: () => requestShowEditWorkspaceWindow(id),
|
||||
click: async () => await window.service.window.open(WindowNames.editWorkspace, { workspaceID: id }),
|
||||
},
|
||||
{
|
||||
label: t('WorkspaceSelector.RemoveWorkspace'),
|
||||
click: () => requestRemoveWorkspace(id),
|
||||
click: async () => await window.service.workspaceView.removeWorkspaceView(id),
|
||||
},
|
||||
];
|
||||
|
||||
|
|
@ -286,17 +287,21 @@ const Main = ({ classes, didFailLoad, isFullScreen, isLoading, navigationBar, sh
|
|||
<SortableItem key={`item-${workspace.id}`} index={index} value={{ index: index, workspace }} />
|
||||
))}
|
||||
</SortableContainer>
|
||||
{/* @ts-expect-error ts-migrate(2322) FIXME: Type '{ id: string; onClick: () => any; }' is not ... Remove this comment to see the full error message */}
|
||||
<WorkspaceSelector id="add" onClick={() => requestShowAddWorkspaceWindow()} />
|
||||
<WorkspaceSelector id="add" onClick={async () => await window.service.window.open(WindowNames.addWorkspace)} />
|
||||
</div>
|
||||
{!navigationBar && (
|
||||
<div className={classes.end}>
|
||||
<IconButton aria-label="Notifications" onClick={requestShowNotificationsWindow} className={classes.iconButton}>
|
||||
<IconButton
|
||||
aria-label="Notifications"
|
||||
onClick={async () => await window.service.window.open(WindowNames.notifications)}
|
||||
className={classes.iconButton}>
|
||||
{shouldPauseNotifications ? <NotificationsPausedIcon /> : <NotificationsIcon />}
|
||||
</IconButton>
|
||||
{window.meta.windowName === 'menubar' && (
|
||||
// @ts-expect-error ts-migrate(2554) FIXME: Expected 1 arguments, but got 0.
|
||||
<IconButton aria-label="Preferences" onClick={() => requestShowPreferencesWindow()} className={classes.iconButton}>
|
||||
<IconButton
|
||||
aria-label="Preferences"
|
||||
onClick={async () => await window.service.window.open(WindowNames.preferences)}
|
||||
className={classes.iconButton}>
|
||||
<SettingsIcon />
|
||||
</IconButton>
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ import NotificationsPausedIcon from '@material-ui/icons/NotificationsPaused';
|
|||
import RefreshIcon from '@material-ui/icons/Refresh';
|
||||
import SettingsIcon from '@material-ui/icons/SettingsSharp';
|
||||
import InputBase from '@material-ui/core/InputBase';
|
||||
|
||||
import { WindowNames } from '@services/windows/WindowProperties';
|
||||
import connectComponent from '../../helpers/connect-component';
|
||||
import isUrl from '../../helpers/is-url';
|
||||
import { updateAddressBarInfo } from '../../state/general/actions';
|
||||
|
|
@ -177,11 +179,10 @@ const NavigationBar = ({
|
|||
/>
|
||||
</div>
|
||||
<div>
|
||||
<IconButton aria-label="Notifications" onClick={requestShowNotificationsWindow} className={classes.iconButton}>
|
||||
<IconButton aria-label="Notifications" onClick={async () => await window.service.window.open(WindowNames.notifications)} className={classes.iconButton}>
|
||||
{shouldPauseNotifications ? <NotificationsPausedIcon className={classes.icon} /> : <NotificationsIcon className={classes.icon} />}
|
||||
</IconButton>
|
||||
{/* @ts-expect-error ts-migrate(2554) FIXME: Expected 1 arguments, but got 0. */}
|
||||
<IconButton aria-label="Preferences" className={classes.iconButton} onClick={() => requestShowPreferencesWindow()}>
|
||||
<IconButton aria-label="Preferences" className={classes.iconButton} onClick={async () => await window.service.window.open(WindowNames.preferences)}>
|
||||
<SettingsIcon className={classes.icon} />
|
||||
</IconButton>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -60,15 +60,6 @@ export enum PreferenceChannel {
|
|||
export enum WindowChannel {
|
||||
name = 'WindowChannel',
|
||||
requestShowRequireRestartDialog = 'request-show-require-restart-dialog',
|
||||
requestShowPreferencesWindow = 'request-show-preferences-window',
|
||||
requestShowAboutWindow = 'request-show-about-window',
|
||||
requestShowCustomUserAgentWindow = 'request-show-custom-user-agent-window',
|
||||
requestShowCodeInjectionWindow = 'request-show-code-injection-window',
|
||||
requestShowAddWorkspaceWindow = 'request-show-add-workspace-window',
|
||||
requestShowEditWorkspaceWindow = 'request-show-edit-workspace-window',
|
||||
requestShowNotificationsWindow = 'request-show-notifications-window',
|
||||
requestShowProxyWindow = 'request-show-proxy-window',
|
||||
requestShowSpellcheckLanguagesWindow = 'request-show-spellcheck-languages-window',
|
||||
}
|
||||
|
||||
export enum ThemeChannel {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { contextBridge, ipcRenderer } from 'electron';
|
||||
import { preloadBindings } from '@/services/libs/i18n/i18next-electron-fs-backend';
|
||||
import { preloadBindings } from '@services/libs/i18n/i18next-electron-fs-backend';
|
||||
|
||||
const i18n = {
|
||||
i18nextElectronBackend: preloadBindings(ipcRenderer),
|
||||
|
|
|
|||
|
|
@ -14,16 +14,6 @@ export const getShouldUseDarkColors = async (): Promise<void> => {
|
|||
|
||||
export const requestCheckForUpdates = async (isSilent: boolean) => await ipcRenderer.invoke('request-check-for-updates', isSilent);
|
||||
|
||||
export const requestShowAboutWindow = async () => await ipcRenderer.invoke('request-show-about-window');
|
||||
export const requestShowAddWorkspaceWindow = async () => await ipcRenderer.invoke('request-show-add-workspace-window');
|
||||
export const requestShowCodeInjectionWindow = async (type: string) => await ipcRenderer.invoke('request-show-code-injection-window', type);
|
||||
export const requestShowCustomUserAgentWindow = async () => await ipcRenderer.invoke('request-show-custom-user-agent-window');
|
||||
export const requestShowEditWorkspaceWindow = async (id: string) => await ipcRenderer.invoke('request-show-edit-workspace-window', id);
|
||||
export const requestShowNotificationsWindow = async () => await ipcRenderer.invoke('request-show-notifications-window');
|
||||
export const requestShowPreferencesWindow = async (scrollTo: string) => await ipcRenderer.invoke('request-show-preferences-window', scrollTo);
|
||||
export const requestShowProxyWindow = async () => await ipcRenderer.invoke('request-show-proxy-window');
|
||||
export const requestShowSpellcheckLanguagesWindow = async () => await ipcRenderer.invoke('request-show-spellcheck-languages-window');
|
||||
|
||||
// Notifications
|
||||
export const requestShowNotification = async (options: { title: string; body: string }) => await ipcRenderer.invoke('request-show-notification', options);
|
||||
export const requestUpdatePauseNotificationsInfo = async () => await ipcRenderer.invoke('request-update-pause-notifications-info');
|
||||
|
|
|
|||
|
|
@ -103,6 +103,7 @@ export interface WindowMeta extends Record<WindowNames, Record<string, unknown>
|
|||
[WindowNames.editWorkspace]: { workspaceID?: string };
|
||||
[WindowNames.openUrlWith]: { incomingUrl?: string };
|
||||
[WindowNames.main]: { forceClose?: boolean };
|
||||
[WindowNames.preferences]: { gotoTab?: string };
|
||||
}
|
||||
export type IPossibleWindowMeta = {
|
||||
windowName: WindowNames;
|
||||
|
|
|
|||
|
|
@ -60,40 +60,6 @@ export class Window implements IWindowService {
|
|||
}
|
||||
});
|
||||
|
||||
ipcMain.handle(WindowChannel.requestShowCodeInjectionWindow, (_event, codeInjectionType: CodeInjectionType) => {
|
||||
void this.open(WindowNames.codeInjection, { codeInjectionType }, (windowMeta: WindowMeta[WindowNames.codeInjection]) => {
|
||||
return codeInjectionType !== windowMeta.codeInjectionType;
|
||||
});
|
||||
});
|
||||
ipcMain.handle(WindowChannel.requestShowCustomUserAgentWindow, () => {
|
||||
void this.open(WindowNames.userAgent);
|
||||
});
|
||||
|
||||
ipcMain.handle(WindowChannel.requestShowAboutWindow, () => {
|
||||
void this.open(WindowNames.about);
|
||||
});
|
||||
ipcMain.handle(WindowChannel.requestShowPreferencesWindow, (_event, scrollTo: string) => {
|
||||
// FIXME: make scrollTo enum, and find places use this scrollTo
|
||||
void this.open(WindowNames.preferences, { scrollTo });
|
||||
});
|
||||
ipcMain.handle(WindowChannel.requestShowEditWorkspaceWindow, (_event, workspaceID: string) => {
|
||||
void this.open(WindowNames.editWorkspace, { workspaceID }, (windowMeta: WindowMeta[WindowNames.editWorkspace]) => {
|
||||
return workspaceID !== windowMeta.workspaceID;
|
||||
});
|
||||
});
|
||||
ipcMain.handle(WindowChannel.requestShowAddWorkspaceWindow, () => {
|
||||
void this.open(WindowNames.addWorkspace);
|
||||
});
|
||||
ipcMain.handle(WindowChannel.requestShowNotificationsWindow, () => {
|
||||
void this.open(WindowNames.notifications);
|
||||
});
|
||||
ipcMain.handle(WindowChannel.requestShowProxyWindow, () => {
|
||||
void this.open(WindowNames.proxy);
|
||||
});
|
||||
ipcMain.handle(WindowChannel.requestShowSpellcheckLanguagesWindow, () => {
|
||||
void this.open(WindowNames.spellcheck);
|
||||
});
|
||||
|
||||
ipcMain.handle('request-find-in-page', (_event, text: string, forward?: boolean, windowName: WindowNames = WindowNames.main) => {
|
||||
const mainWindow = this.get(windowName);
|
||||
const contents = mainWindow?.getBrowserView()?.webContents;
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
"compilerOptions": {
|
||||
"baseUrl": "./src",
|
||||
"paths": {
|
||||
"@/*": ["./*"],
|
||||
"@services/*": ["./services/*"]
|
||||
"@services/*": ["./services/*"],
|
||||
"@/*": ["./*"]
|
||||
},
|
||||
/* Basic Options */
|
||||
"target": "es2019" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue