add Settings
This commit is contained in:
1 parent
3ed022af37
commit
a1adbe69c5
4 files changed
+160
-105
No files matched your search
@@ -1,3 +1,4 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
dist/
|
dist/
|
||||||
build/
|
build/
|
||||||
|
settings.json
|
||||||
+79
-75
@@ -1,84 +1,88 @@
|
|||||||
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 {
|
||||||
const menu: Menu = new Menu();
|
constructor(mainProcess: MainProcess) {
|
||||||
const fileMenu: MenuItem = new MenuItem({
|
const mainWindow = mainProcess.mainWindow;
|
||||||
label: "行为树",
|
const menu: Menu = new Menu();
|
||||||
submenu: [
|
const fileMenu: MenuItem = new MenuItem({
|
||||||
{
|
label: "行为树",
|
||||||
label: "打开文件",
|
submenu: [
|
||||||
accelerator: "Ctrl+O",
|
{
|
||||||
click: () => {
|
label: "打开文件",
|
||||||
(async () => {
|
accelerator: "Ctrl+O",
|
||||||
const res = await dialog.showOpenDialog({
|
click: () => {
|
||||||
properties: ['openFile'],
|
(async () => {
|
||||||
filters: [
|
const res = await dialog.showOpenDialog({
|
||||||
{name: "Json", extensions:['json']}
|
properties: ['openFile'],
|
||||||
]
|
filters: [
|
||||||
});
|
{ name: "Json", extensions: ['json'] }
|
||||||
mainWindow.webContents.send(MainEventType.OPEN_FILE, res.filePaths[0]);
|
]
|
||||||
})();
|
});
|
||||||
|
mainWindow.webContents.send(MainEventType.OPEN_FILE, res.filePaths[0]);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "打开目录",
|
||||||
|
accelerator: "Ctrl+Shift+O",
|
||||||
|
click: () => {
|
||||||
|
(async () => {
|
||||||
|
const res = await dialog.showOpenDialog({
|
||||||
|
properties: ['openDirectory']
|
||||||
|
});
|
||||||
|
if (res.filePaths.length > 0) {
|
||||||
|
mainWindow.webContents.send(MainEventType.OPEN_WORKSPACE, res.filePaths[0]);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ type: 'separator' },
|
||||||
|
{
|
||||||
|
label: "最近打开",
|
||||||
|
submenu: []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "最近目录",
|
||||||
|
submenu: [
|
||||||
|
{ label: "master" },
|
||||||
|
{ label: "分支0908" },
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{ type: 'separator' },
|
||||||
|
{
|
||||||
|
label: "关闭",
|
||||||
|
click: () => {
|
||||||
|
app.quit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
]
|
||||||
{
|
});
|
||||||
label: "打开目录",
|
|
||||||
accelerator: "Ctrl+Shift+O",
|
|
||||||
click: () => {
|
|
||||||
(async () => {
|
|
||||||
const res = await dialog.showOpenDialog({
|
|
||||||
properties: ['openDirectory']
|
|
||||||
});
|
|
||||||
if (res.filePaths.length > 0) {
|
|
||||||
mainWindow.webContents.send(MainEventType.OPEN_WORKSPACE, res.filePaths[0]);
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ type: 'separator' },
|
|
||||||
{
|
|
||||||
label: "最近打开",
|
|
||||||
submenu: []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: "最近目录",
|
|
||||||
submenu: [
|
|
||||||
{ label: "master" },
|
|
||||||
{ label: "分支0908" },
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{ type: 'separator' },
|
|
||||||
{
|
|
||||||
label: "关闭",
|
|
||||||
click: () => {
|
|
||||||
app.quit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
});
|
|
||||||
|
|
||||||
const toolsMenu: MenuItem = new MenuItem({
|
const toolsMenu: MenuItem = new MenuItem({
|
||||||
label: "开发工具",
|
label: "开发工具",
|
||||||
submenu: [
|
submenu: [
|
||||||
{
|
{
|
||||||
label: "重载",
|
label: "重载",
|
||||||
accelerator: "Ctrl+R",
|
accelerator: "Ctrl+R",
|
||||||
click: (_, browserWindow) => {
|
click: (_, browserWindow) => {
|
||||||
browserWindow.reload();
|
browserWindow.reload();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "打开控制台",
|
||||||
|
accelerator: "Ctrl+Shift+I",
|
||||||
|
click: (_, browserWindow) => {
|
||||||
|
browserWindow.webContents.toggleDevTools();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
]
|
||||||
{
|
});
|
||||||
label: "打开控制台",
|
|
||||||
accelerator: "Ctrl+Shift+I",
|
|
||||||
click: (_, browserWindow) => {
|
|
||||||
browserWindow.webContents.toggleDevTools();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
});
|
|
||||||
|
|
||||||
menu.append(fileMenu);
|
menu.append(fileMenu);
|
||||||
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
+42
-30
@@ -1,34 +1,46 @@
|
|||||||
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;
|
||||||
width: 1280,
|
constructor() {
|
||||||
height: 800,
|
nativeTheme.themeSource = 'dark';
|
||||||
webPreferences: {
|
app.on('ready', () => {
|
||||||
nodeIntegration: true
|
this.createWindow();
|
||||||
}
|
})
|
||||||
// fullscreenable:false,
|
app.on('window-all-closed', () => {
|
||||||
// maximizable:false
|
if (process.platform !== 'darwin') {
|
||||||
});
|
app.quit()
|
||||||
// mainWindow.webContents.openDevTools();
|
}
|
||||||
mainWindow.loadFile('index.html');
|
})
|
||||||
mainWindow.on('closed', function () {
|
app.on('activate', () => {
|
||||||
mainWindow = null
|
if (this.mainWindow === null) {
|
||||||
});
|
this.createWindow()
|
||||||
initMenu(mainWindow);
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
createWindow (){
|
||||||
|
this.settings = new Settings();
|
||||||
|
this.mainWindow = new BrowserWindow({
|
||||||
|
width: 1280,
|
||||||
|
height: 800,
|
||||||
|
webPreferences: {
|
||||||
|
nodeIntegration: true
|
||||||
|
}
|
||||||
|
// fullscreenable:false,
|
||||||
|
// maximizable:false
|
||||||
|
});
|
||||||
|
// mainWindow.webContents.openDevTools();
|
||||||
|
this.mainWindow.loadFile('index.html');
|
||||||
|
this.mainWindow.on('closed', function () {
|
||||||
|
this.mainWindow = null
|
||||||
|
});
|
||||||
|
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