Skip to content

Commit

Permalink
Merge pull request #1080 from chat2db/refactor-electron
Browse files Browse the repository at this point in the history
fix:electron build
  • Loading branch information
shanhexi authored Jan 8, 2024
2 parents c471f59 + ece57d4 commit 6e37204
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 8 deletions.
2 changes: 1 addition & 1 deletion chat2db-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"asar": false,
"files": [
"dist/**/*",
"src/main/preload.js",
"src/main",
"src/main/main.js",
"versions/**/*",
"package.json",
Expand Down
15 changes: 10 additions & 5 deletions chat2db-client/src/blocks/AppTitleBar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { memo } from 'react';
import styles from './index.less';
import classnames from 'classnames';
import CustomLayout from '@/components/CustomLayout';
import Iconfont from '@/components/Iconfont';
import { useCommonStore } from '@/store/common';

// import Iconfont from '@/components/Iconfont';

interface IProps {
className?: string;
Expand All @@ -11,6 +12,12 @@ interface IProps {
export default memo<IProps>((props) => {
const { className } = props;

const { appTitleBarRightComponent } = useCommonStore((state) => {
return {
appTitleBarRightComponent: state.appTitleBarRightComponent,
};
});

const handleDoubleClick = () => {
window.electronApi?.setMaximize();
};
Expand All @@ -19,9 +26,7 @@ export default memo<IProps>((props) => {
<div className={classnames(styles.appTitleBar, className)} onDoubleClick={handleDoubleClick}>
<div />
<div className={styles.appName}>Chat2DB Community</div>
<div>
<CustomLayout />
</div>
<div>{appTitleBarRightComponent}</div>
{/* <div className={styles.windowsCloseBar}>
<div>
<Iconfont code="icon-minimize" />
Expand Down
11 changes: 10 additions & 1 deletion chat2db-client/src/pages/main/workspace/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import classnames from 'classnames';

import { useWorkspaceStore } from '@/pages/main/workspace/store';
import { setPanelLeftWidth } from '@/pages/main/workspace/store/config';
import { setAppTitleBarRightComponent } from '@/store/common/appTitleBarConfig';

import DraggableContainer from '@/components/DraggableContainer';
import WorkspaceLeft from './components/WorkspaceLeft';
import WorkspaceRight from './components/WorkspaceRight';
import CustomLayout from '@/components/CustomLayout';

import useMonacoTheme from '@/components/MonacoEditor/useMonacoTheme';
import shortcutKeyCreateConsole from './functions/shortcutKeyCreateConsole';
Expand All @@ -24,8 +26,15 @@ const workspacePage = memo(() => {

// 编辑器的主题
useMonacoTheme();
// 快捷键

useEffect(() => {
setAppTitleBarRightComponent(<CustomLayout />);
return () => {
setAppTitleBarRightComponent(null);
};
}, []);

// 快捷键
useEffect(() => {
shortcutKeyCreateConsole();
}, []);
Expand Down
15 changes: 15 additions & 0 deletions chat2db-client/src/store/common/appTitleBarConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import { useCommonStore } from './index';
export interface IAppTitleBarConfig {
appTitleBarRightComponent: React.ReactNode | null;
}

export const initAppTitleBarConfig = {
appTitleBarRightComponent: null,
};

export const setAppTitleBarRightComponent: (appTitleBarRightComponent: React.ReactNode | null) => void = (
appTitleBarRightComponent,
) => {
return useCommonStore.setState({ appTitleBarRightComponent });
};
4 changes: 3 additions & 1 deletion chat2db-client/src/store/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ import { StoreApi } from 'zustand';

import { initCopyFocusedContent, ICopyFocusedContent } from './copyFocusedContent';
import { initComponentsContent, IComponentsContent } from './components';
import { initAppTitleBarConfig, IAppTitleBarConfig } from './appTitleBarConfig';

export type IStore = ICopyFocusedContent & IComponentsContent;
export type IStore = ICopyFocusedContent & IComponentsContent & IAppTitleBarConfig;

export const useCommonStore: UseBoundStoreWithEqualityFn<StoreApi<IStore>> = createWithEqualityFn(
devtools(
() => ({
...initCopyFocusedContent,
...initComponentsContent,
...initAppTitleBarConfig
}),
),
shallow
Expand Down

0 comments on commit 6e37204

Please sign in to comment.