4646 large
4747 >
4848 fas fa-list
49- </v-icon >Processes list <v-spacer />
49+ </v-icon >Processes list
50+ <v-spacer />
5051 </div >
5152 <div class =" item" >
5253 <div class =" name" >
9394 <tr
9495 v-for =" item in process"
9596 :key =" item.pid"
97+ @click =" askKill(item.pid, item.name)"
9698 >
9799 <td >{{ item.name }}</td >
98- <td >{{ item.pcpu.toFixed(3 ) }}%</td >
99- <td >{{ item.pmem.toFixed(3 ) }}%</td >
100+ <td >{{ item.pcpu.toFixed(2 ) }}%</td >
101+ <td >{{ item.pmem.toFixed(2 ) }}%</td >
100102 </tr >
101103 </tbody >
102104 </template >
113115 <div class="e-nuxt-button" @click="openURL('https://electronjs.org/docs')">
114116 Electron.js
115117 </div>
116- </div> -->
118+ </div>-->
117119 </div >
118120</template >
119121
120122<script >
121- import { remote } from " electron" ;
123+ const dialog = require ( " electron" ). remote . dialog ;
122124const { currentLoad , processes } = require (" systeminformation" );
123125
124126export default {
125- data () {
127+ data () {
126128 return {
127- radio: " name " ,
129+ radio: " cpu " ,
128130 avgLoad: 0 ,
129131 idleLoad: 0 ,
130132 currentLoad: 0 ,
@@ -139,25 +141,78 @@ export default {
139141 var data;
140142 data = await processes ();
141143 this .process = [];
142- for (let pro of data .list ) {
143- this .process .push (pro);
144- }
144+ this .process = data .list ;
145+ this .process = this .process .filter (el => el .name !== " System Idle Process" );
145146 if (this .radio === " cpu" ) {
146- this .process .sort (function (a , b ){return b .pcpu - a .pcpu ;});
147+ this .process .sort (function (a , b ) {
148+ return b .pcpu - a .pcpu ;
149+ });
147150 } else if (this .radio === " mem" ) {
148- this .process .sort (function (a , b ){return b .pmem - a .pmem ;});
151+ this .process .sort (function (a , b ) {
152+ return b .pmem - a .pmem ;
153+ });
149154 } else {
150- this .process .sort (function (a , b ){
151- if (a .name < b .name ) { return - 1 ; }
152- if (a .name > b .name ) { return 1 ; }
155+ this .process .sort (function (a , b ) {
156+ if (a .name < b .name ) {
157+ return - 1 ;
158+ }
159+ if (a .name > b .name ) {
160+ return 1 ;
161+ }
153162 return 0 ;
154163 });
155164 }
156165 data = await currentLoad ();
157166 this .avgLoad = data .avgload ;
158167 this .currentLoad = data .currentload ;
159168 this .idleLoad = data .currentload_idle ;
160- setTimeout (res => this .checkSys (), 2000 );
169+ setTimeout (() => this .checkSys (), 2000 );
170+ },
171+ askKill (pid , name ) {
172+ if (name .includes (" System Companion" )) {
173+ dialog .showMessageBox (null , {
174+ type: " info" ,
175+ message: " Sorry you can't kill System Companion from here."
176+ });
177+ } else {
178+ dialog .showMessageBox (
179+ null ,
180+ {
181+ type: " question" ,
182+ title: " Process kill" ,
183+ message: ` Do you want to kill ${ name} ?` ,
184+ buttons: [" No" , " Yes" ]
185+ },
186+ response => {
187+ if (response === 1 ) {
188+ this .processKill (pid, name);
189+ }
190+ }
191+ );
192+ }
193+ },
194+ processKill (pid , name ) {
195+ try {
196+ var done = process .kill (pid);
197+ if (done >= 0 ) {
198+ dialog .showMessageBox (null , {
199+ type: " info" ,
200+ title: " Process kill" ,
201+ message: ` ${ name} as been killed`
202+ });
203+ } else {
204+ this .cantKill (name);
205+ }
206+ } catch (error) {
207+ this .cantKill (name);
208+ }
209+ },
210+ cantKill (name ) {
211+ dialog .showMessageBox (null , {
212+ type: " info" ,
213+ title: " Process kill" ,
214+ message: ` ${ name} can't be killed, try run System Companion as Admin`
215+ });
161216 }
162217 }
163218};
0 commit comments