forked from AtomicSponge/script-tray
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed62f5a
commit 00409c6
Showing
9 changed files
with
275 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* | ||
* @author Matthew Evans | ||
* @module script-tray | ||
* @see README.md | ||
* @copyright MIT see LICENSE.md | ||
* | ||
*/ | ||
|
||
import { EventEmitter } from 'node:events' | ||
|
||
import type { ChildProcess } from 'node:child_process' | ||
|
||
export class ProcessManager extends EventEmitter { | ||
#dataBuffer:Array<ProcessManagerData> | ||
#processBuffer:Array<ChildProcess> | ||
|
||
/** Create a new ProcessManager object */ | ||
constructor() { | ||
super() | ||
this.#dataBuffer = [] | ||
this.#processBuffer = [] | ||
|
||
// Listen for write events | ||
this.on('process-manager-add', (data, proc) => { | ||
this.#dataBuffer.push(data) | ||
this.#processBuffer.push(proc) | ||
this.emit('process-manager-updated') | ||
}) | ||
|
||
// Listen for remove events | ||
this.on('process-manager-remove', (pid) => { | ||
this.#dataBuffer = this.#dataBuffer.filter(proc => { proc.pid !== pid }) | ||
this.#processBuffer = this.#processBuffer.filter(proc => { proc.pid !== pid }) | ||
this.emit('process-manager-updated') | ||
}) | ||
} | ||
|
||
/** | ||
* Read the ProcessManager buffer | ||
* @returns The list of running processes | ||
*/ | ||
read():Array<ProcessManagerData> { | ||
return this.#dataBuffer | ||
} | ||
|
||
/** | ||
* Terminate a running process by its Process ID | ||
* @param pid Process ID to terminate | ||
*/ | ||
term(pid:number):void { | ||
this.#processBuffer.forEach(proc => { | ||
if (proc.pid === pid) proc.kill() | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
<script type="module" src="/renderer/jobmgr.ts"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<!-- | ||
script-tray | ||
By: Matthew Evans | ||
See LICENSE.md | ||
--> | ||
|
||
<script setup lang="ts"> | ||
import { ref, onMounted } from 'vue' | ||
|
||
const _runningJobs = ref() | ||
|
||
/** | ||
* Terminate running job button | ||
* @param pid Process ID to terminate | ||
*/ | ||
const termJob = (pid:number) => { | ||
window.jobMgrAPI.termProcess(pid) | ||
} | ||
|
||
onMounted(() => { | ||
window.jobMgrAPI.onReceiveData((runningJobs:ProcessManagerData) => { | ||
_runningJobs.value = runningJobs | ||
}) | ||
}) | ||
</script> | ||
|
||
<template> | ||
<section> | ||
<table> | ||
<tr> | ||
<th class="pid">PID</th> | ||
<th class="label">Label</th> | ||
<th>Command</th> | ||
<th class="time">Start time</th> | ||
<th class="term"> </th> | ||
</tr> | ||
<tr v-for="item in _runningJobs"> | ||
<td>{{ item.pid }}</td> | ||
<td>{{ item.label }}</td> | ||
<td>{{ item.command }}</td> | ||
<td>{{ item.start }}</td> | ||
<td> | ||
<button @click="termJob(item.pid)">TERM</button> | ||
</td> | ||
</tr> | ||
</table> | ||
</section> | ||
</template> | ||
|
||
<style lang="stylus" scoped> | ||
section | ||
overflow auto | ||
padding-top 4px | ||
padding-left 4px | ||
padding-right 4px | ||
padding-bottom 4px | ||
table | ||
width 100% | ||
border-collapse collapse | ||
border 1px solid rgb(100, 100, 100, 0.1) | ||
th | ||
padding 4px | ||
background-color rgb(80, 80, 80, 0.1) | ||
text-align left | ||
.pid | ||
width 60px | ||
.label | ||
width 160px | ||
.time | ||
width 220px | ||
.term | ||
width 50px | ||
tr:nth-child(odd) | ||
background-color rgb(60, 60, 60, 0.1) | ||
td | ||
padding 4px | ||
button | ||
vertical-align top | ||
font-size 0.6em | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* | ||
* @author Matthew Evans | ||
* @module script-tray | ||
* @see README.md | ||
* @copyright MIT see LICENSE.md | ||
* | ||
*/ | ||
|
||
import { createApp } from 'vue' | ||
import JobMgrApp from './JobMgr.vue' | ||
import './style.styl' | ||
|
||
createApp(JobMgrApp).mount('#app') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import path from 'node:path' | ||
import { defineConfig } from 'vite' | ||
import renderer from 'vite-plugin-electron-renderer' | ||
import vue from '@vitejs/plugin-vue' | ||
|
||
export default defineConfig({ | ||
plugins: [ renderer(), vue() ], | ||
build: { | ||
outDir: 'dist', | ||
emptyOutDir: false, | ||
minify: false, | ||
rollupOptions: { input: path.join(__dirname, 'html/jobmgr.html') } | ||
}, | ||
esbuild: { | ||
target: 'esnext' | ||
} | ||
}) |