Skip to content

Commit

Permalink
Merge pull request #107 from xianyunleo/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
xianyunleo authored Apr 26, 2024
2 parents b5ba359 + a906db2 commit e622879
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 66 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "eserver",
"productName": "EServer",
"version": "3.4.0",
"version": "3.6.0",
"description": "EServer",
"main": "./out/main/index.js",
"author": "xianyunleo",
Expand Down
1 change: 1 addition & 0 deletions src/main/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export default class Settings {
WebsiteDir: Path.Join(GetAppPath.getUserCoreDir(), 'www'),
OneClickServerList: ['Nginx', 'PHP-FPM', 'MySQL-5.7'],
AutoStartAndRestartServer: true,
AfterOpenAppStartServer: false,
};
}

Expand Down
90 changes: 57 additions & 33 deletions src/main/core/ServerControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,34 @@ import Path from "@/main/utils/Path";
import FileUtil from "@/main/utils/FileUtil";

export default class ServerControl {

static WinPHPCGI_ProcessName = 'php-cgi.exe';
static WinPHPFPM_ProcessName = 'php-cgi-spawner.exe';


/**
* SoftwareItem
* @param softItem {SoftwareItem}
* @param item {SoftwareItem}
* @returns {Promise<void>}
*/
static async start(softItem) {
const item = softItem;
let workPath = Software.getPath(item); //服务目录
let serverProcessPath = Path.Join(workPath, item.ServerProcessPath); //服务的进程目录
let options = {cwd: workPath, detached: true};

if (isWindows && item.ShellServerProcess) {
options = { cwd: workPath, shell: true } //使用shell,childProcess返回的pid是shell的pid
static async start(item) {
const workPath = Software.getPath(item) //服务目录
const serverProcessPath = this.getControlProcessPath(item)
const options = { cwd: workPath, detached: true }

if (item.ShellServerProcess) {
options.detached = false
options.shell = true //使用shell,childProcess返回的pid是shell的pid
}

if (!await FileUtil.Exists(serverProcessPath)) {
throw new Error(`${serverProcessPath} 文件不存在!`);
}

let args = [];

let args = []
if (item.StartServerArgs) {
args = item.StartServerArgs.map(arg => {
let argObj = {
ServerProcessPath: serverProcessPath,
WorkPath: workPath,
ConfPath: item.ConfPath ? Path.Join(workPath, item.ConfPath) : null,
ServerConfPath: item.ServerConfPath ? Path.Join(workPath, item.ServerConfPath) : null,
ExtraProcessPath: item.ExtraProcessPath ? Path.Join(workPath, item.ExtraProcessPath) : null,
};
return parseTemplateStrings(arg, argObj);
})
args = this.parseServerArgs(item, item.StartServerArgs)
}

item.isRunning = true;
item.errMsg = '';
item.isRunning = true
item.errMsg = ''

let childProcess = child_process.spawn(serverProcessPath, args, options);
const childProcess = child_process.spawn(serverProcessPath, args, options);

childProcess.stderr.on('data', (data) => {
console.log('stderr data',data?.toString())
Expand All @@ -67,13 +52,52 @@ export default class ServerControl {
item.pid = childProcess.pid;
}

static getControlProcessPath(item) {
const workPath = Software.getPath(item)
if (item.ControlProcessPath) {
return Path.Join(workPath, item.ControlProcessPath) //控制进程的目录
} else {
return Path.Join(workPath, item.ServerProcessPath) //服务进程的目录
}
}

/**
* SoftwareItem
* @param softItem{SoftwareItem}
*
* @param item{SoftwareItem}
* @returns {Promise<void>}
*/
static async stop(softItem) {
await ProcessExtend.kill(softItem.pid);
static async stop(item) {
const workPath = Software.getPath(item)
const options = { cwd: workPath, detached: true }
if (item.StopServerArgs) {
const args = this.parseServerArgs(item, item.StopServerArgs)
if (item.ShellServerProcess) {
options.detached = false
options.shell = true //使用shell,childProcess返回的pid是shell的pid
}
const serverProcessPath = this.getControlProcessPath(item)
child_process.spawn(serverProcessPath, args, options)
} else {
await ProcessExtend.kill(item.pid)
}
}

/**
*
* @param item{SoftwareItem}
* @param args{array}
*/
static parseServerArgs(item, args) {
const workPath = Software.getPath(item)
return args.map((arg) => {
const argObj = {
WorkPath: workPath.replaceSlash(),
ServerProcessPath: Path.Join(workPath, item.ServerProcessPath).replaceSlash(),
ConfPath: item.ConfPath ? Path.Join(workPath, item.ConfPath).replaceSlash() : null,
ServerConfPath: item.ServerConfPath ? Path.Join(workPath, item.ServerConfPath).replaceSlash() : null,
ExtraProcessPath: item.ExtraProcessPath ? Path.Join(workPath, item.ExtraProcessPath).replaceSlash() : null
}
return parseTemplateStrings(arg, argObj)
})
}
}
7 changes: 4 additions & 3 deletions src/renderer/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { isDev, isMacOS, isWindows } from '@/main/utils/utils'
import TitleBar from "./components/TitleBar.vue";
import SideBar from "./components/SideBar.vue";
import App from "@/main/App";
import { provide, reactive, ref, watch } from 'vue'
import { onMounted, provide, reactive, ref, watch } from 'vue'
import MessageBox from "@/renderer/utils/MessageBox";
import UserPwdModal from "@/renderer/components/UserPwdModal.vue";
import Software from "@/main/core/software/Software";
Expand All @@ -52,7 +52,8 @@ provide('GlobalProvide', { serverReactive })
const settings = Settings.getAll()
store.changeTheme(settings.ThemeMode, settings.ThemeColor)
store.settings = settings
;(async () => {
onMounted(async () => {
try {
if (await App.initFileExists() && !isDev) {
await App.checkInstall()
Expand All @@ -72,7 +73,7 @@ store.settings = settings
if (isWindows) {
stopIIS()
}
})()
})
async function initOrUpdate() {
if (isMacOS && process.arch === 'arm64' && !(await SystemExtend.isInstallRosetta())) {
Expand Down
26 changes: 21 additions & 5 deletions src/renderer/components/Settings/OneClickServer.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
<template>
<a-card size="small" :title="t('oneClickStartAndStop')" class="settings-card">
<a-row type="flex" align="middle" class="settings-card-row">
<a-col :span="24" class='flex-vertical-center'>
<a-card size="small" :title="t('Server')" class="settings-card">
<div class='settings-card-row flex-vertical-center'>
<span>{{mt('Server','ws','List')}}:</span>
<a-select
v-model:value="store.settings.OneClickServerList"
:options="oneClickServerOptions"
@change="oneClickServerChange"
mode="multiple" placeholder="请选择" style="flex: 1"
></a-select>
</a-col>
</a-row>
</div>

<div class='settings-card-row flex-vertical-center'>
<a-switch v-model:checked='store.settings.AutoStartAndRestartServer' @change='changeAutoStartAndRestartServer'
class='settings-switch' />
<span>{{ t('websiteAutoRestartText') }}</span>
</div>

<div class='settings-card-row flex-vertical-center'>
<a-switch v-model:checked='store.settings.AfterOpenAppStartServer' @change='changeAfterOpenAppStartServer'
class='settings-switch' />
<span>{{ t('afterOpenAppStartServer') }}</span>
</div>
</a-card>
</template>

Expand All @@ -37,6 +47,12 @@ oneClickServerOptions.unshift({label: 'PHP-FPM', value: 'PHP-FPM'});
const oneClickServerChange = () => {
store.setSettings('OneClickServerList')
}
const changeAutoStartAndRestartServer = () => {
store.setSettings('AutoStartAndRestartServer')
}
const changeAfterOpenAppStartServer = () => {
store.setSettings('AfterOpenAppStartServer')
}
</script>

<style scoped>
Expand Down
10 changes: 0 additions & 10 deletions src/renderer/components/Settings/Other.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@
<a-button @click='changeWebsiteDir' style='margin-left: 5px'>...</a-button>
</div>

<div class='settings-card-row flex-vertical-center'>
<a-switch v-model:checked='store.settings.AutoStartAndRestartServer' @change='changeAutoStartAndRestartServer'
class='settings-switch' />
<span>{{ t('websiteAutoRestartText') }}</span>
</div>

<a-row type='flex' align='middle' class='settings-card-row'>
<a-col :span='6' class='flex-vertical-center'>
<a-button @click='exitApp' type='primary'>{{ t('Exit') }} {{APP_NAME}}</a-button>
Expand Down Expand Up @@ -67,10 +61,6 @@ const changeWebsiteDir = () => {
})
}
const changeAutoStartAndRestartServer = () => {
store.setSettings('AutoStartAndRestartServer')
}
const exitApp = ()=>{
App.exit()
}
Expand Down
1 change: 1 addition & 0 deletions src/renderer/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const useMainStore = defineStore('main', {
settings: {},
customTheme: {},
websiteList: { showSecondDomainName: false, showNote: false },
afterOpenAppStartServerNum: 1,
}
},
getters: {
Expand Down
32 changes: 18 additions & 14 deletions src/renderer/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,6 @@ const PoweroffOutlined = createAsyncComponent(import('@ant-design/icons-vue'), '
const ReloadOutlined = createAsyncComponent(import('@ant-design/icons-vue'), 'ReloadOutlined')
const RightSquareFilled = createAsyncComponent(import('@ant-design/icons-vue'), 'RightSquareFilled')
onMounted(() => {
var timestamp2 = new Date().getTime();
console.log('home onMounted',timestamp2-timestamp)
})
const columns = [
{
title: t('Name'),
Expand All @@ -138,7 +134,24 @@ const columns = [
]
const store = useMainStore()
const { serverList } = storeToRefs(store)
const { serverList,afterOpenAppStartServerNum } = storeToRefs(store)
onMounted(async () => {
var timestamp2 = new Date().getTime()
console.log('home onMounted', timestamp2 - timestamp)
if (serverList.value) {
serverTableLoading.value = { tip: `${t('RefreshingServer')}...` }
await initServerListStatus()
serverTableLoading.value = false
}
if (Settings.get('AfterOpenAppStartServer') && afterOpenAppStartServerNum.value >= 1) {
afterOpenAppStartServerNum.value -= 1
oneClickStart()
}
})
const getProcessList = async () => {
let list;
Expand Down Expand Up @@ -178,15 +191,6 @@ const initServerListStatus = async () => {
await Promise.all(promiseArray)
};
(async () => {
if (serverList.value) {
serverTableLoading.value = { tip: `${t('RefreshingServer')}...`}
await initServerListStatus()
serverTableLoading.value = false
}
})()
const corePathClick = () => {
Native.openDirectory(GetAppPath.getUserCoreDir())
}
Expand Down
1 change: 1 addition & 0 deletions src/shared/i18n/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,5 @@ export default {
installPackageDownloadUrl: 'Download URL of installation package',
softwareUninstallErrorTip: 'Please open the file manager and manually delete the {0} directory',
mysqlResetRootAccountPwd: 'MySQL reset password for root account',
afterOpenAppStartServer: 'After opening the app, start the server',
}
1 change: 1 addition & 0 deletions src/shared/i18n/zh.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,5 @@ export default {
installPackageDownloadUrl: '安装包下载地址',
softwareUninstallErrorTip: '请打开文件管理器,手动删除{0}目录',
mysqlResetRootAccountPwd: 'MySQL 重置 root 账户的密码',
afterOpenAppStartServer: '打开软件后,启动服务',
}

0 comments on commit e622879

Please sign in to comment.