add Settings
This commit is contained in:
1 parent
3ed022af37
commit
a1adbe69c5
4 files changed
+77
-22
No files matched your search
@@ -1,3 +1,4 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
dist/
|
dist/
|
||||||
build/
|
build/
|
||||||
|
settings.json
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
import { BrowserView, Menu, app, shell, dialog, BrowserWindow, MenuItem } from 'electron';
|
import { BrowserView, Menu, app, shell, dialog, BrowserWindow, MenuItem } from 'electron';
|
||||||
import MainEventType from '../common/MainEventType';
|
import MainEventType from '../common/MainEventType';
|
||||||
|
import { MainProcess } from './main';
|
||||||
|
|
||||||
export function initMenu(mainWindow: BrowserWindow) {
|
export default class AppMenu {
|
||||||
|
constructor(mainProcess: MainProcess) {
|
||||||
|
const mainWindow = mainProcess.mainWindow;
|
||||||
const menu: Menu = new Menu();
|
const menu: Menu = new Menu();
|
||||||
const fileMenu: MenuItem = new MenuItem({
|
const fileMenu: MenuItem = new MenuItem({
|
||||||
label: "行为树",
|
label: "行为树",
|
||||||
@@ -14,7 +17,7 @@ export function initMenu(mainWindow: BrowserWindow) {
|
|||||||
const res = await dialog.showOpenDialog({
|
const res = await dialog.showOpenDialog({
|
||||||
properties: ['openFile'],
|
properties: ['openFile'],
|
||||||
filters: [
|
filters: [
|
||||||
{name: "Json", extensions:['json']}
|
{ name: "Json", extensions: ['json'] }
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
mainWindow.webContents.send(MainEventType.OPEN_FILE, res.filePaths[0]);
|
mainWindow.webContents.send(MainEventType.OPEN_FILE, res.filePaths[0]);
|
||||||
@@ -81,4 +84,5 @@ export function initMenu(mainWindow: BrowserWindow) {
|
|||||||
menu.append(toolsMenu);
|
menu.append(toolsMenu);
|
||||||
|
|
||||||
Menu.setApplicationMenu(menu);
|
Menu.setApplicationMenu(menu);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import * as fs from 'fs';
|
||||||
|
|
||||||
|
const settingPath = 'settings.json';
|
||||||
|
|
||||||
|
export interface SettingsModel {
|
||||||
|
recentWorkspaces: string[];
|
||||||
|
recentFiles: string[];
|
||||||
|
nodeConfigPath: string; // 节点配置路径
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class Settings {
|
||||||
|
private settings: SettingsModel;
|
||||||
|
constructor() {
|
||||||
|
if(fs.existsSync(settingPath)) {
|
||||||
|
const str = fs.readFileSync(settingPath, 'utf8');
|
||||||
|
this.settings = JSON.parse(str);
|
||||||
|
} else {
|
||||||
|
this.settings = {
|
||||||
|
recentWorkspaces: [],
|
||||||
|
recentFiles: [],
|
||||||
|
nodeConfigPath: ''
|
||||||
|
};
|
||||||
|
this.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
set(config: any) {
|
||||||
|
this.settings = {
|
||||||
|
...this.settings,
|
||||||
|
...config
|
||||||
|
};
|
||||||
|
this.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
save() {
|
||||||
|
fs.writeFileSync(settingPath, JSON.stringify(this.settings, null, 2));
|
||||||
|
}
|
||||||
|
}
|
||||||
+32
-20
@@ -1,10 +1,31 @@
|
|||||||
import { app, BrowserWindow, Menu, MenuItem, dialog, nativeTheme } from 'electron';
|
import { app, BrowserWindow, Menu, MenuItem, dialog, nativeTheme } from 'electron';
|
||||||
import {initMenu} from './AppMenu'
|
import AppMenu from './AppMenu'
|
||||||
|
import Settings from './Settings';
|
||||||
|
|
||||||
let mainWindow: BrowserWindow = null;
|
export class MainProcess {
|
||||||
nativeTheme.themeSource = 'dark';
|
mainWindow: BrowserWindow;
|
||||||
let createWindow = function () {
|
appMenu: AppMenu;
|
||||||
mainWindow = new BrowserWindow({
|
settings: Settings;
|
||||||
|
constructor() {
|
||||||
|
nativeTheme.themeSource = 'dark';
|
||||||
|
app.on('ready', () => {
|
||||||
|
this.createWindow();
|
||||||
|
})
|
||||||
|
app.on('window-all-closed', () => {
|
||||||
|
if (process.platform !== 'darwin') {
|
||||||
|
app.quit()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
app.on('activate', () => {
|
||||||
|
if (this.mainWindow === null) {
|
||||||
|
this.createWindow()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
createWindow (){
|
||||||
|
this.settings = new Settings();
|
||||||
|
this.mainWindow = new BrowserWindow({
|
||||||
width: 1280,
|
width: 1280,
|
||||||
height: 800,
|
height: 800,
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
@@ -14,21 +35,12 @@ let createWindow = function () {
|
|||||||
// maximizable:false
|
// maximizable:false
|
||||||
});
|
});
|
||||||
// mainWindow.webContents.openDevTools();
|
// mainWindow.webContents.openDevTools();
|
||||||
mainWindow.loadFile('index.html');
|
this.mainWindow.loadFile('index.html');
|
||||||
mainWindow.on('closed', function () {
|
this.mainWindow.on('closed', function () {
|
||||||
mainWindow = null
|
this.mainWindow = null
|
||||||
});
|
});
|
||||||
initMenu(mainWindow);
|
this.appMenu = new AppMenu(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
app.on('ready', createWindow)
|
|
||||||
app.on('window-all-closed', () => {
|
|
||||||
if (process.platform !== 'darwin') {
|
|
||||||
app.quit()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
app.on('activate', () => {
|
new MainProcess();
|
||||||
if (mainWindow === null) {
|
|
||||||
createWindow()
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Reference in new issue
Block a user