workspace add servers

This commit is contained in:
zhandouxiaojiji committed 2020-11-19 20:34:49 +08:00
1 parent 32312fc40b
commit c7f65abccf
3 files changed
+76 -17

No files matched your search

+17
View File
@@ -303,9 +303,26 @@ export default class AppMenu {
}
private createToolsMenu() {
const serverItems: MenuItemConstructorOptions[] = [];
const curServerName = this.settings.serverName;
for (let model of this.settings.curWorkspace.getServers()) {
serverItems.push({
label: `${model.name} ${model.host}`,
type: 'checkbox',
checked: curServerName == model.name,
click: () => {
this.settings.serverName = model.name;
this.mainProcess.rebuildMenu();
}
})
}
return new MenuItem({
label: "开发工具",
submenu: [
{
label: "联调服务器",
submenu: serverItems,
},
{
label: "打开控制台",
accelerator: "Ctrl+Shift+I",
+45 -17
View File
@@ -1,5 +1,4 @@
import * as fs from "fs";
import { BehaviorNodeTypeModel } from "../common/BehaviorTreeModel";
import Workspace from "./Workspace";
export interface BehaviorNodeClassify {
@@ -10,6 +9,7 @@ export interface BehaviorNodeClassify {
export interface SettingsModel {
recentWorkspaces?: string[];
recentFiles?: string[];
serverName?: string;
nodeClassify?: BehaviorNodeClassify[];
}
@@ -22,7 +22,7 @@ const sampleNodeClassify: BehaviorNodeClassify[] = [
];
export default class Settings {
private settings: SettingsModel;
private model: SettingsModel;
curWorkspace?: Workspace;
constructor() {
@@ -33,21 +33,52 @@ export default class Settings {
return this.curWorkspace.getNodeConfPath();
}
get recentWorkspaces() {
return this.settings.recentWorkspaces;
return this.model.recentWorkspaces;
}
get recentFiles() {
return this.settings.recentFiles;
return this.model.recentFiles;
}
get nodeConfig() {
return this.curWorkspace.nodeConf;
}
get nodeClassify() {
return this.settings.nodeClassify;
return this.model.nodeClassify;
}
get serverModel() {
const servers = this.curWorkspace.getServers()
if (!servers) {
return;
}
for (let server of servers) {
if (server.name == this.model.serverName) {
return server;
}
}
return servers[0];
}
get serverName() {
const servers = this.curWorkspace.getServers()
if (!servers) {
return "";
}
for (let server of servers) {
if (server.name == this.model.serverName) {
return this.model.serverName;
}
}
if(servers[0]) {
return servers[0].name;
} else {
return ''
}
}
set serverName(name: string) {
this.model.serverName = name;
}
set(config: SettingsModel) {
this.settings = {
...this.settings,
this.model = {
...this.model,
...config,
};
this.save();
@@ -56,21 +87,21 @@ export default class Settings {
load() {
if (fs.existsSync(settingPath)) {
const str = fs.readFileSync(settingPath, "utf8");
this.settings = JSON.parse(str);
this.model = JSON.parse(str);
} else {
this.settings = {
this.model = {
recentWorkspaces: ["sample/workspace.json"],
recentFiles: [],
nodeClassify: sampleNodeClassify,
};
this.save();
}
this.curWorkspace = new Workspace(this.settings.recentWorkspaces[0]);
this.curWorkspace = new Workspace(this.model.recentWorkspaces[0]);
this.curWorkspace.load();
}
save() {
fs.writeFileSync(settingPath, JSON.stringify(this.settings, null, 2));
fs.writeFileSync(settingPath, JSON.stringify(this.model, null, 2));
}
getNodeConf(name: string) {
@@ -78,12 +109,9 @@ export default class Settings {
}
pushRecentWorkspace(path: string) {
if (this.settings.recentWorkspaces.indexOf(path) < 0) {
this.settings.recentWorkspaces.unshift(path);
console.log("push", path);
} else {
console.log("already in path", this.settings.recentWorkspaces, path);
}
if (this.model.recentWorkspaces.indexOf(path) < 0) {
this.model.recentWorkspaces.unshift(path);
this.save();
}
}
}
+14
View File
@@ -3,10 +3,16 @@ import { BehaviorNodeTypeModel } from "../common/BehaviorTreeModel";
import * as glob from "glob";
import * as path from "path";
export interface ServerModel {
name: string;
host: string;
}
export interface WorkspaceModel {
isRelative?: boolean;
nodeConfPath: string;
workdir: string;
servers?: ServerModel[];
}
const unknowNodeType: BehaviorNodeTypeModel = {
@@ -19,6 +25,7 @@ export default class Workspace {
private filepath: string;
private nodeConfPath: string;
private workdir: string;
private model: WorkspaceModel;
private name2conf: { [name: string]: BehaviorNodeTypeModel } = {};
private types: BehaviorNodeTypeModel[] = [];
@@ -42,6 +49,7 @@ export default class Workspace {
this.nodeConfPath = model.nodeConfPath;
this.workdir = model.workdir;
}
this.model = model;
this.initNodeConf();
} catch (error) {
@@ -77,6 +85,12 @@ export default class Workspace {
setWorkdir(workdir: string) {
this.workdir = workdir;
}
getServers() {
return this.model.servers || [];
}
getModel() {
return this.model;
}
writeAllTrees(outFilePath: string, cb?: (err: string) => void) {
if (!fs.existsSync(this.getWorkdir())) {