Skip to content

Commit d7deb74

Browse files
committed
🚧 WIP: app, basic style and states
1 parent 2a97ec2 commit d7deb74

34 files changed

+1059
-24
lines changed

.prettierignore

-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,3 @@ node_modules/
22
package.json
33
package-lock.json
44
yarn.lock
5-
6-
variables.scss

.stylelintrc

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"rule-empty-line-before": null,
4444
"selector-max-id": 0,
4545
"string-quotes": "single",
46+
"value-list-comma-newline-after": null,
4647
"value-list-max-empty-lines": null,
4748
"indentation": null
4849
}

app/scripts/gen-files.ts

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { GenFilesOptions, genFiles } from '@huiji/shared-utils';
22

33
const optionsList: GenFilesOptions[] = [
4+
// renderer
45
// components
56
{
67
comments: ['All components'],
@@ -32,6 +33,14 @@ const optionsList: GenFilesOptions[] = [
3233
patterns: ['src/renderer/utils/**/*.ts'],
3334
output: 'src/renderer/utils/index.ts',
3435
},
36+
37+
// main
38+
// utils
39+
{
40+
comments: ['All utils'],
41+
patterns: ['src/main/utils/**/*.ts'],
42+
output: 'src/main/utils/index.ts',
43+
},
3544
];
3645

3746
Promise.all(optionsList.map(genFiles)).catch((e: Error) => {

app/src/main/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './utils';

app/src/main/main.ts

+70-15
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,82 @@
1-
import { resolve } from 'path';
2-
import { app, BrowserWindow } from 'electron';
1+
import { app, BrowserWindow, Menu } from 'electron';
2+
import * as io from '@rimtrans/io';
3+
import * as utils from './utils';
34

45
const isDevelopment = process.env.NODE_ENV === 'development';
56

6-
export async function createWindow(): Promise<void> {
7-
const win = new BrowserWindow({
8-
width: 1440,
9-
height: 900,
10-
x: -1920,
11-
y: 0,
12-
alwaysOnTop: true,
7+
const { paths, browserWindowsSet, settings, storage, initStates } = utils.createStates();
8+
9+
async function setup(): Promise<void> {
10+
await initStates();
11+
}
12+
13+
async function dispose(): Promise<void> {
14+
browserWindowsSet.clear();
15+
await Promise.all([settings, storage].map(wrapper => wrapper.save()));
16+
}
17+
18+
function destroyWindow(browserWindow: BrowserWindow): void {
19+
const maximized = browserWindow.isMaximized();
20+
const [width, height] = browserWindow.getSize();
21+
const [x, y] = browserWindow.getPosition();
22+
23+
storage.set(
24+
{
25+
lastActiveWindowState: {
26+
maximized,
27+
width,
28+
height,
29+
x,
30+
y,
31+
},
32+
},
33+
false,
34+
);
35+
36+
browserWindowsSet.delete(browserWindow);
37+
}
38+
39+
async function createWindow(): Promise<void> {
40+
const {
41+
lastActiveWindowState: { maximized, width, height, x, y },
42+
} = storage.get();
43+
44+
const browserWindow = new BrowserWindow({
45+
width: width || undefined,
46+
height: height || undefined,
47+
x: x || undefined,
48+
y: y || undefined,
49+
50+
backgroundColor: '#fff',
51+
webPreferences: {
52+
nodeIntegration: true,
53+
},
1354
});
1455

15-
win.maximize();
56+
browserWindowsSet.add(browserWindow);
1657

17-
const userData = app.getPath('userData');
18-
const appName = app.getName();
58+
browserWindow.once('close', () => destroyWindow(browserWindow));
59+
60+
if (maximized) {
61+
browserWindow.maximize();
62+
}
1963

2064
if (isDevelopment) {
21-
await win.loadURL(`http://localhost:9421#/?appName=${appName}&userData=${userData}`);
65+
browserWindow.setAlwaysOnTop(true);
66+
await browserWindow.loadURL(`http://localhost:9421`);
2267
} else {
23-
await win.loadFile(resolve(__dirname, '..', 'renderer', 'index.html'));
68+
await browserWindow.loadFile(io.join(__dirname, '..', 'renderer', 'index.html'));
2469
}
2570
}
2671

27-
app.on('ready', createWindow);
72+
if (!isDevelopment) {
73+
Menu.setApplicationMenu(null);
74+
}
75+
76+
app.on('ready', async () => {
77+
await setup();
78+
await createWindow();
79+
});
80+
app.on('quit', async () => {
81+
await dispose();
82+
});

app/src/main/utils/constants.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export const USER_DATA = 'userData';
2+
3+
export const GLOBAL_KEY_PATHS = 'GLOBAL_VALUE_PATHS';
4+
5+
export const GLOBAL_KEY_SETTINGS = 'GLOBAL_VALUE_SETTINGS';
6+
export const FILENAME_SETTINGS = 'settings.json';
7+
8+
export const GLOBAL_KEY_STORAGE = 'GLOBAL_VALUE_STORAGE';
9+
export const FILENAME_STORAGE = 'storage.json';

app/src/main/utils/index.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Do not edit this file.
2+
// It is auto generated by script "scripts/gen-files.ts".
3+
// To update this file, please run command `yarn gen-files`.
4+
// tslint:disable
5+
6+
/**
7+
* All utils
8+
*/
9+
10+
export * from './constants';
11+
export * from './states/index';
12+
export * from './states/settings';
13+
export * from './states/storage';

0 commit comments

Comments
 (0)