fix: some issues on darwin (#440)
This commit is contained in:
parent
1dd9dd449a
commit
b40eea5afa
|
@ -39,8 +39,7 @@ jobs:
|
|||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
make build
|
||||
make copy
|
||||
make build copy
|
||||
sudo atest service install
|
||||
sudo atest service restart
|
||||
sudo atest service status
|
||||
|
@ -118,7 +117,7 @@ jobs:
|
|||
cache-dependency-path: console/atest-ui/package-lock.json
|
||||
- name: Build
|
||||
run: |
|
||||
make build-embed-ui
|
||||
make build-embed-ui copy
|
||||
sudo atest service install
|
||||
sudo atest service restart
|
||||
- name: Test
|
||||
|
|
|
@ -17,3 +17,5 @@ oryxBuildBinary
|
|||
/helm/api-testing/charts/
|
||||
console/atest-desktop/out
|
||||
console/atest-desktop/node_modules
|
||||
console/atest-desktop/atest
|
||||
console/atest-desktop/atest.exe
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
|
@ -1,10 +1,11 @@
|
|||
const { FusesPlugin } = require('@electron-forge/plugin-fuses');
|
||||
const { FuseV1Options, FuseVersion } = require('@electron/fuses');
|
||||
const path = require('node:path');
|
||||
|
||||
module.exports = {
|
||||
packagerConfig: {
|
||||
icon: 'api-testing.ico',
|
||||
asar: true,
|
||||
icon: path.join(__dirname, 'api-testing'),
|
||||
asar: true
|
||||
},
|
||||
rebuildConfig: {},
|
||||
makers: [
|
||||
|
@ -32,7 +33,7 @@ module.exports = {
|
|||
name: '@electron-forge/maker-dmg',
|
||||
config: {
|
||||
format: 'ULFO',
|
||||
icon: 'api-testing.ico'
|
||||
icon: path.join(__dirname, 'api-testing.png')
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
|
@ -17,6 +17,7 @@ Log output
|
|||
|
||||
<!-- You can also require other files to run in this process -->
|
||||
<script src="./renderer.js"></script>
|
||||
<script src="./api.js"></script>
|
||||
<script>
|
||||
const actionBut = document.getElementById('action');
|
||||
actionBut.addEventListener('click', (e) => {
|
||||
|
@ -35,7 +36,7 @@ actionBut.addEventListener('click', (e) => {
|
|||
|
||||
const openServerBut = document.getElementById('open-server-page');
|
||||
openServerBut.addEventListener('click', (e) => {
|
||||
window.location = 'http://localhost:8080'
|
||||
window.location = getHomePage()
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
@ -2,10 +2,20 @@
|
|||
|
||||
// Modules to control application life and create native browser window
|
||||
const { app, BrowserWindow, Menu, MenuItem } = require('electron')
|
||||
const log = require('electron-log/main');
|
||||
const path = require('node:path')
|
||||
const fs = require('node:fs')
|
||||
const server = require('./api')
|
||||
const spawn = require("child_process").spawn;
|
||||
const homedir = require('os').homedir();
|
||||
const atestHome = path.join(homedir, ".config", 'atest')
|
||||
|
||||
// setup log output
|
||||
log.initialize();
|
||||
log.transports.file.level = 'info';
|
||||
log.transports.file.resolvePathFn = () => path.join(atestHome, 'log.log');
|
||||
|
||||
app.dock.setIcon(path.join(__dirname, "api-testing.png"))
|
||||
const createWindow = () => {
|
||||
// Create the browser window.
|
||||
const mainWindow = new BrowserWindow({
|
||||
|
@ -20,12 +30,17 @@ const createWindow = () => {
|
|||
icon: path.join(__dirname, '/api-testing.ico'),
|
||||
})
|
||||
|
||||
server.control(() => {
|
||||
if (!isNaN(serverProcess.pid)) {
|
||||
// server process started by app
|
||||
mainWindow.loadURL(server.getHomePage())
|
||||
}, () => {
|
||||
// and load the index.html of the app.
|
||||
mainWindow.loadFile('index.html')
|
||||
})
|
||||
} else {
|
||||
server.control(() => {
|
||||
mainWindow.loadURL(server.getHomePage())
|
||||
}, () => {
|
||||
// and load the index.html of the app.
|
||||
mainWindow.loadFile('index.html')
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const menu = new Menu()
|
||||
|
@ -71,14 +86,55 @@ let serverProcess;
|
|||
// initialization and is ready to create browser windows.
|
||||
// Some APIs can only be used after this event occurs.
|
||||
app.whenReady().then(() => {
|
||||
const homedir = require('os').homedir();
|
||||
const homeData = path.join(atestHome, 'data')
|
||||
const homeBin = path.join(atestHome, 'bin')
|
||||
|
||||
serverProcess = spawn("atest", [
|
||||
fs.mkdirSync(homeData, {
|
||||
recursive: true
|
||||
})
|
||||
fs.mkdirSync(homeBin, {
|
||||
recursive: true
|
||||
})
|
||||
|
||||
// try to find the atest file first
|
||||
const serverFile = process.platform === "win32" ? "atest.exe" : "atest"
|
||||
const atestFromHome = path.join(homeBin, serverFile)
|
||||
const atestFromPkg = path.join(__dirname, serverFile)
|
||||
|
||||
if (!fs.existsSync(atestFromHome)) {
|
||||
log.info('cannot find from %s', atestFromHome)
|
||||
|
||||
const data = fs.readFileSync(atestFromPkg)
|
||||
log.info('start to write file with length %d', data.length)
|
||||
|
||||
try {
|
||||
fs.writeFileSync(atestFromHome, data);
|
||||
}
|
||||
catch (e) {
|
||||
log.error('Error Code: %s', e.code);
|
||||
}
|
||||
}
|
||||
fs.chmodSync(atestFromHome, 0o755);
|
||||
|
||||
serverProcess = spawn(atestFromHome, [
|
||||
"server",
|
||||
"--http-port", server.getPort(),
|
||||
// TODO below setting is not working
|
||||
"--local-storage", path.join(homedir, ".atest", "data", "*.yaml")
|
||||
"--local-storage", path.join(homeData, "*.yaml")
|
||||
]);
|
||||
serverProcess.stdout.on('data', (data) => {
|
||||
log.info(data.toString())
|
||||
if (data.toString().indexOf('Server is running') != -1) {
|
||||
BrowserWindow.getFocusedWindow().loadURL(server.getHomePage())
|
||||
}
|
||||
});
|
||||
serverProcess.stderr.on('data', (data) => {
|
||||
log.error(data.toString())
|
||||
});
|
||||
serverProcess.on('close', (code) => {
|
||||
log.log(`child process exited with code ${code}`);
|
||||
});
|
||||
log.info('start atest server as pid:', serverProcess.pid)
|
||||
log.info(serverProcess.spawnargs)
|
||||
|
||||
createWindow()
|
||||
|
||||
|
@ -101,6 +157,11 @@ app.on('window-all-closed', () => {
|
|||
}
|
||||
}
|
||||
})
|
||||
app.on('before-quit', () => {
|
||||
if (serverProcess) {
|
||||
serverProcess.kill();
|
||||
}
|
||||
})
|
||||
|
||||
// In this file you can include the rest of your app's specific main process
|
||||
// code. You can also put them in separate files and require them here.
|
|
@ -10,6 +10,7 @@
|
|||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"child_process": "^1.0.2",
|
||||
"electron-log": "^5.1.4",
|
||||
"electron-squirrel-startup": "^1.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -2807,6 +2808,14 @@
|
|||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/electron-log": {
|
||||
"version": "5.1.4",
|
||||
"resolved": "https://registry.npmmirror.com/electron-log/-/electron-log-5.1.4.tgz",
|
||||
"integrity": "sha512-P0RSXnwT3z+e89Z5uAcZDeN85/QjIgv764a93kqCi+wh2Jm22CCbc3AGDt4S8rsxAHWHB4Q0PGsQl3fw1AN0kQ==",
|
||||
"engines": {
|
||||
"node": ">= 14"
|
||||
}
|
||||
},
|
||||
"node_modules/electron-squirrel-startup": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmmirror.com/electron-squirrel-startup/-/electron-squirrel-startup-1.0.1.tgz",
|
||||
|
|
|
@ -29,11 +29,12 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"child_process": "^1.0.2",
|
||||
"electron-log": "^5.1.4",
|
||||
"electron-squirrel-startup": "^1.0.1"
|
||||
},
|
||||
"build": {
|
||||
"extraResources": [
|
||||
"./assets/atest.exe"
|
||||
"./assets/*"
|
||||
]
|
||||
},
|
||||
"optionalDependencies": {
|
||||
|
|
|
@ -75,6 +75,7 @@ include tools/make/ui.mk
|
|||
include tools/make/run.mk
|
||||
include tools/make/proto.mk
|
||||
include tools/make/test.mk
|
||||
include tools/make/desktop.mk
|
||||
|
||||
# Log the running target
|
||||
# \033[0;32m -> green
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
# Building docs makefile defined.
|
||||
#
|
||||
# All make targets related to docs are defined in this file.
|
||||
|
||||
##@ Desktop
|
||||
|
||||
.PHONY: desktop-start
|
||||
desktop-start: ## Start Electron Desktop
|
||||
desktop-start:
|
||||
cd console/atest-desktop && npm run start
|
||||
|
||||
desktop-package: ## Package Electron Desktop
|
||||
desktop-package: build.embed.ui
|
||||
cp ${OUTPUT_DIR}/${BINARY} console/atest-desktop
|
||||
cd console/atest-desktop && npm run package
|
|
@ -21,7 +21,7 @@ run-console:
|
|||
.PHONY: copy
|
||||
copy: ## Copy the binary to /usr/local/bin
|
||||
copy:
|
||||
sudo cp ${OUTPUT_DIR}/$(GOOS)/$(GOARCH)/atest /usr/local/bin/
|
||||
sudo cp $(OUTPUT_DIR)/$(OS)/$(ARCH)/${BINARY} /usr/local/bin/
|
||||
|
||||
.PHONY: copy-restart
|
||||
copy-restart: ## Copy the binary to /usr/local/bin and restart the service
|
||||
|
|
|
@ -16,8 +16,7 @@ build.ui:
|
|||
|
||||
.PHONY: build.embed.ui
|
||||
build.embed.ui: embed.ui
|
||||
GOOS=${GOOS} go build -a -ldflags "${BUILD_FLAGS}" -o ${OUTPUT_DIR}/embedui/${BINARY} ${ROOT_PACKAGE}/main.go
|
||||
cp ${OUTPUT_DIR}/embedui/${BINARY} /usr/local/bin/
|
||||
GOOS=${GOOS} go build -a -ldflags "${BUILD_FLAGS}" -o $(OUTPUT_DIR)/$(OS)/$(ARCH)/${BINARY} ${ROOT_PACKAGE}/main.go
|
||||
make clean.embed.ui
|
||||
|
||||
.PHONY: embed.ui
|
||||
|
|
Loading…
Reference in New Issue