Skip to content

Commit c8e3241

Browse files
committed
feat: open directory with electron
1 parent 20ad31a commit c8e3241

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

app/components/Home.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ import {
66
Stack,
77
IStackTokens,
88
} from 'office-ui-fabric-react';
9+
import { remote } from 'electron';
910
import routes from '../constants/routes.json';
1011

12+
const { dialog } = remote;
13+
1114
export interface IButtonExampleProps {
1215
// These are set based on the toggles shown above the examples (not needed in real code)
1316
disabled?: boolean;
@@ -18,12 +21,19 @@ export interface IButtonExampleProps {
1821
const stackTokens: IStackTokens = { childrenGap: 40 };
1922

2023
export default function Home(): JSX.Element {
21-
const [state] = useState<string>('Hi');
24+
const [state] = useState<string>('Please select backup directory');
25+
const [directory, setDirectory] = useState<string>('t');
2226

2327
const alertClicked = (): void => {
2428
alert('Clicked');
2529
};
26-
30+
const onButtonClick = () => {
31+
const path = dialog.showOpenDialog({
32+
properties: ['openDirectory'],
33+
});
34+
// eslint-disable-next-line promise/catch-or-return
35+
path.then((res) => setDirectory(res.filePaths[0]));
36+
};
2737
useEffect(() => {
2838
// axios
2939
// .get('http://localhost:5000')
@@ -36,16 +46,17 @@ export default function Home(): JSX.Element {
3646
<h2>{state}</h2>
3747
<Stack horizontal tokens={stackTokens}>
3848
<DefaultButton
39-
text="Standard"
40-
onClick={alertClicked}
49+
text="Directory"
50+
onClick={onButtonClick}
4151
allowDisabledFocus
4252
/>
4353
<PrimaryButton
44-
text="Primary"
54+
text="BACKUP"
4555
onClick={alertClicked}
4656
allowDisabledFocus
4757
/>
4858
</Stack>
59+
<div>{directory}</div>
4960
<Link to={routes.COUNTER}>counter</Link>
5061
</div>
5162
);

app/main.dev.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,26 @@ const createWindow = async () => {
7171
return path.join(RESOURCES_PATH, ...paths);
7272
};
7373

74+
const webPreferences =
75+
(process.env.NODE_ENV === 'development' ||
76+
process.env.E2E_BUILD === 'true') &&
77+
process.env.ERB_SECURE !== 'true'
78+
? {
79+
nodeIntegration: true,
80+
}
81+
: {
82+
preload: path.join(__dirname, 'dist/renderer.prod.js'),
83+
};
84+
7485
mainWindow = new BrowserWindow({
7586
show: false,
7687
width: 1024,
7788
height: 728,
7889
icon: getAssetPath('icon.png'),
79-
webPreferences:
80-
(process.env.NODE_ENV === 'development' ||
81-
process.env.E2E_BUILD === 'true') &&
82-
process.env.ERB_SECURE !== 'true'
83-
? {
84-
nodeIntegration: true,
85-
}
86-
: {
87-
preload: path.join(__dirname, 'dist/renderer.prod.js'),
88-
},
90+
webPreferences: {
91+
...webPreferences,
92+
enableRemoteModule: true,
93+
},
8994
});
9095

9196
mainWindow.loadURL(`file://${__dirname}/app.html`);

0 commit comments

Comments
 (0)