Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add setting to choose process stdin encoding #13

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,15 @@ if (configVersion < 1) {
args: config.get('args.casparcg', ''),
health: config.get('health.casparcg', true) ? 'casparcg' : undefined,
autoStart: true,
sendCommands: 'utf16le',
})
processes.push({
id: 'scanner',
name: 'Media Scanner',
exeName: 'scanner.exe',
args: config.get('args.media-scanner', ''),
autoStart: true,
sendCommands: undefined,
})

if (config.store.exe) {
Expand All @@ -93,6 +95,21 @@ if (configVersion < 1) {
config.delete('exe')
config.delete('health')
}
if (configVersion < 2) {
const processes = config.get('processes')
for (let process of processes) {
if (!('sendCommands' in process)) {
if (process.id === 'scanner') {
process.sendCommands = undefined
} else {
process.sendCommands = 'utf8'
}
}
}

config.set('processes', processes)
config.set('version', 2)
}

let mainWindow
const winURL = !isProduction ? `http://localhost:9080` : `file://${__dirname}/index.html`
Expand Down
15 changes: 12 additions & 3 deletions src/main/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export class ProcessMonitor {

this.logFile = !!this.config.logMode

this.pipeStatus(this.currentStatus) // update showSendCommand

if (changed) {
if (this.healthMon) {
this.healthMon.stop()
Expand Down Expand Up @@ -175,8 +177,8 @@ export class ProcessMonitor {
}

sendCommand(command) {
if (this.process) {
this.process.write(command)
if (this.process && this.config.sendCommands) {
this.process.write(command, this.config.sendCommands)
}
}

Expand Down Expand Up @@ -212,7 +214,14 @@ export class ProcessMonitor {
}
pipeStatus(status) {
this.currentStatus = status
this.ipcWrapper.send('process.status', JSON.stringify({ id: this.id, status: status }))
this.ipcWrapper.send(
'process.status',
JSON.stringify({
id: this.id,
status: status,
showCommandSend: !!this.config.sendCommands,
})
)
}

ensureLogFileHandleCorrect() {
Expand Down
4 changes: 2 additions & 2 deletions src/main/respawn/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ Monitor.prototype.start = function () {
if (this.status === 'running') this.emit('start')
}

Monitor.prototype.write = function (command) {
Monitor.prototype.write = function (command, encoding) {
if (this.status === 'running' && this.child && this.child.stdin) {
this.child.stdin.write(command + '\n')
this.child.stdin.write(command + '\n', encoding)
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/renderer/components/ProcessTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
{{ l.content }}
</li>
</ul>
<b-form ref="commandForm" @submit.prevent="onSubmit">
<b-form ref="commandForm" @submit.prevent="onSubmit" v-bind:class="{ hidden: !data.showCommandSend }">
<b-input-group>
<b-form-input placeholder="Enter a command" id="command"></b-form-input>
<b-button type="submit">Send</b-button>
Expand Down Expand Up @@ -103,4 +103,8 @@ export default {
#log-panel li.log.warning {
color: orange;
}

.hidden {
display: none;
}
</style>
14 changes: 14 additions & 0 deletions src/renderer/components/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
{ key: 'exeName', label: 'Executable' },
{ key: 'args', label: 'Arguments' },
{ key: 'health', label: 'Health Check' },
{ key: 'sendCommands', label: 'Send Commands' },
{ key: 'log', label: 'Save log' },
{ key: 'start', label: 'Auto start' },
'actions',
Expand Down Expand Up @@ -70,6 +71,14 @@
class="mb-3"
/>
</template>
<template #cell(sendCommands)="data">
<b-form-select
:id="'sendCommands' + data.index"
v-model="config.processes[data.index].sendCommands"
:options="sendCommandsOptions"
class="mb-3"
/>
</template>
<template #cell(log)="data">
<b-form-checkbox :id="'processLog' + data.index" v-model="config.processes[data.index].logMode" />
</template>
Expand Down Expand Up @@ -169,6 +178,11 @@ export default {
{ value: undefined, text: 'None' },
{ value: 'casparcg', text: 'CasparCG Ping' },
],
sendCommandsOptions: [
{ value: undefined, text: 'Disabled' },
{ value: 'utf8', text: 'Generic process' },
{ value: 'utf16le', text: 'CasparCG 2.4+' },
],
config: {
api: {
staticPaths: [],
Expand Down
4 changes: 3 additions & 1 deletion src/renderer/store/modules/Process.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ function ensureStateExists(state, id) {
state[id] = {
log: [],
status: 'unknown',
showCommandSend: false,
}
}
}
Expand All @@ -31,10 +32,11 @@ const mutations = {
state[id].log.splice(0)
},

SET_STATUS(state, { id, status }) {
SET_STATUS(state, { id, status, showCommandSend }) {
ensureStateExists(state, id)

state[id].status = status
state[id].showCommandSend = showCommandSend
},
}

Expand Down