@mytools-all/mytools-computer-assistant 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 MyTools Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,17 @@
1
- # Temporary Holding Version
1
+ # 电脑助手
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 版本 0.1.1,独立 MyTools 插件。依赖公开 system.resources 能力,需配合本次更新的主程序。旧宿主会明确降级到原始进程排行并提示更新。
4
+
5
+ 展示 CPU、物理内存、交换/页面文件、逐网卡上传下载、磁盘余量、进程 CPU/内存前 20、硬件与系统信息。最近一分钟曲线只保存在当前会话中,不保存进程历史或上传信息。GPU 和温度首版不支持。
6
+
7
+ 默认每秒刷新,可改为 2/5 秒。仅打开且可见时监控;隐藏、关闭或手动暂停后停止采样。首次或长时间暂停后的 CPU/网速需要第二次采样才能显示。所有调用走公开能力,不直调 Tauri、不依赖其他插件或宿主源码。
8
+
9
+ 资源提醒默认关闭。用户开启后连续 3 次达到阈值才提醒;系统通知最多每 5 分钟一次,通知失败仍在页面显示。不结束进程、不清理或删除文件,不在关闭插件后后台监控。
10
+
11
+ 资源排行默认按应用汇总,可展开全部关联 PID,或切换按进程查看;可搜索名称/PID,按 CPU 或所选内存口径排序。同一路径程序的父子进程合并,独立实例和不同安装路径保持分开;同一服务程序的客户端经 Windows 服务配置核实后合并。因此应用分组是可解释的近似,不保证完全复现 Windows 任务管理器的分组。
12
+
13
+ 内存默认使用私有工作集,接近任务管理器常用内存列,另可选择包含共享部分的工作集。后者合计可能重复计算共享页。私有工作集来自 Windows 原生 PROCESS_MEMORY_COUNTERS_EX2.PrivateWorkingSetSize,不使用私有提交量冒充;受保护进程或不支持该接口的旧系统显示不可用,部分可读的应用显示已知下限和覆盖数量,排序也按该下限。整机内存卡片仍表示系统整体物理内存使用量,不等于进程列之和。
14
+
15
+ CPU 统一按整机 0—100% 显示。网络按单个网卡展示,避免 VPN/虚拟网卡累计产生重复流量。磁盘容量数据可能有短暂缓存,不表示硬盘实时读写速度。
16
+
17
+ 开发:npm install --ignore-scripts、npm test、npm pack。通过 MyTools 开发者页面安装 tgz。源目录与安装目录独立,修改后需重新安装。通过 npm 安装 @mytools-all/mytools-computer-assistant@0.1.1。插件遵循 MIT LICENSE。
package/app.mjs ADDED
@@ -0,0 +1,83 @@
1
+ import {defaults,preferences,bytes,pct,violations,appendSample,duration} from './model.mjs';
2
+ import {detailed,rankedRows,memoryText} from './ranking.mjs';
3
+ export function createAssistant(doc,api){
4
+ const $=id=>doc.getElementById(id),win=doc.defaultView;
5
+ let prefs={...defaults},sample=null,history=[],timer,busy=false,disposed=false,paused=false,blocked=false,consecutive=0,lastAlert=0,notificationBlocked=false,active=false,initialized=false,networkChosen=false;
6
+ const status=(message,error=false)=>{if(!disposed){$('status').textContent=message;$('status').dataset.error=String(error);}};
7
+ const call=async(id,args={})=>{if(!api)throw Error('请从 MyTools 打开电脑助手');return api.call(id,args);};
8
+ const expanded=new Set();
9
+ function element(tag,text){const n=doc.createElement(tag);if(text!==undefined)n.textContent=text;return n;}
10
+ function line(parent,cells){const tr=element('tr');for(const cell of cells)tr.append(element('td',cell));parent.append(tr);}
11
+ function chart(id,values){const svg=$(id);svg.replaceChildren();if(!values.length)return;const poly=doc.createElementNS('http://www.w3.org/2000/svg','polyline');poly.setAttribute('fill','none');poly.setAttribute('stroke','currentColor');poly.setAttribute('stroke-width','2');poly.setAttribute('points',values.map((v,i)=>(i*600/Math.max(1,values.length-1)).toFixed(2)+','+(100-Math.min(100,Math.max(0,v))).toFixed(2)).join(' '));svg.append(poly);}
12
+ function render(){if(!sample)return;const m=sample.machine;
13
+ $('cpu').textContent=sample.warming?'采样中…':pct(m.cpu);$('memory').textContent=pct(m.totalMemory?100*m.usedMemory/m.totalMemory:0);$('memory-detail').textContent=bytes(m.usedMemory)+' / '+bytes(m.totalMemory);$('swap').textContent=bytes(m.usedSwap)+' / '+bytes(m.totalSwap);$('uptime').textContent=duration(m.uptime);
14
+ const current=$('network').value,names=sample.networks.map(n=>n.name);if(!names.includes(current)||$('network').options.length!==names.length){$('network').replaceChildren(...names.map(name=>{const o=element('option',name);o.value=name;return o;}));$('network').value=names.includes(current)?current:[...sample.networks].sort((a,b)=>(b.receivedPerSecond+b.transmittedPerSecond)-(a.receivedPerSecond+a.transmittedPerSecond))[0]?.name||'';}
15
+ if(!networkChosen&&!sample.warming){const suggested=[...sample.networks].sort((a,b)=>(b.receivedPerSecond+b.transmittedPerSecond)-(a.receivedPerSecond+a.transmittedPerSecond))[0];if(suggested&&suggested.receivedPerSecond+suggested.transmittedPerSecond>0){$('network').value=suggested.name;networkChosen=true;}}
16
+ const network=sample.networks.find(n=>n.name===$('network').value);$('download').textContent=network?bytes(network.receivedPerSecond)+'/s':'不可用';$('upload').textContent=network?bytes(network.transmittedPerSecond)+'/s':'不可用';
17
+ chart('cpu-chart',history.map(s=>s.machine.cpu));chart('memory-chart',history.map(s=>s.machine.totalMemory?100*s.machine.usedMemory/s.machine.totalMemory:0));
18
+ $('disks').replaceChildren();for(const disk of sample.disks)line($('disks'),[disk.mount,bytes(disk.total-disk.available),bytes(disk.available),bytes(disk.total)]);
19
+ renderProcesses();
20
+ $('hardware').replaceChildren();for(const [name,value] of [['处理器',m.cpuName],['逻辑处理器',String(m.cores)],['物理内存',bytes(m.totalMemory)],['系统',m.os||'不可用'],['运行时长',duration(m.uptime)],['GPU 使用率','首版不支持'],['温度','首版不支持']])line($('hardware'),[name,value]);
21
+ $('updated').textContent='更新于 '+new Date(sample.sampledAt).toLocaleTimeString();
22
+ }
23
+ function renderProcesses(){
24
+ if(!sample)return;
25
+ const supported=detailed(sample);
26
+ $('process-mode').disabled=!supported;
27
+ $('memory-metric').disabled=!supported;
28
+ if(!supported){$('process-mode').value='processes';$('memory-metric').value='working';}
29
+ $('process-warning').hidden=supported;
30
+ const mode=$('process-mode').value,metric=$('memory-metric').value;
31
+ $('process-memory-heading').textContent=metric==='private'?'私有工作集':'工作集(含共享)';
32
+ $('process-identity-heading').textContent=mode==='apps'?'主 PID / 分组依据':'PID / 身份';
33
+ $('process-note').textContent=metric==='private'
34
+ ?'私有工作集用于接近任务管理器常用内存列;不包含可共享页,不是私有提交量。无法读取时标为不可用;部分应用按已读取的下限排序。应用分组依据同路径进程树或已核实的服务配置,不保证与 Windows 应用分组完全一致。'
35
+ :'工作集包含共享页,应用合计可能重复计算共享内存,不能直接对比任务管理器默认内存列。同名但不同路径或独立实例保持分开。';
36
+ const rows=rankedRows(sample,{mode,metric,sort:$('process-sort').value,query:$('process-query').value});
37
+ const focus=doc.activeElement?.dataset?.group;
38
+ $('processes').replaceChildren();
39
+ for(const row of rows){
40
+ const tr=element('tr'),name=element('td');
41
+ if(mode==='apps'&&supported){
42
+ const toggle=element('button',row.name+'('+row.processCount+' 个进程)');
43
+ toggle.className='group-toggle';toggle.dataset.group=row.id;toggle.setAttribute('aria-expanded',String(expanded.has(row.id)));
44
+ toggle.onclick=()=>{if(expanded.has(row.id))expanded.delete(row.id);else expanded.add(row.id);renderProcesses();};
45
+ name.append(toggle);
46
+ }else name.textContent=row.name;
47
+ tr.append(name,element('td',String(row.pid??row.rootPid)+' · '+(mode==='apps'?(row.association==='verified-service-executable'?'服务与客户端':row.processCount>1?'同路径进程树':'独立进程'):(row.role||'进程'))),element('td',sample.warming?'采样中':pct(row.cpu)),element('td',memoryText(row,metric)));
48
+ $('processes').append(tr);
49
+ if(mode==='apps'&&expanded.has(row.id)){
50
+ const detail=element('tr'),cell=element('td'),table=element('table'),head=element('thead'),body=element('tbody');
51
+ cell.colSpan=4;cell.className='group-details';line(head,['进程 / 身份','PID','CPU',metric==='private'?'私有工作集':'工作集(含共享)']);
52
+ for(const p of row.processes)line(body,[p.name+' · '+p.role,String(p.pid),sample.warming?'采样中':pct(p.cpu),memoryText(p,metric)]);
53
+ table.append(head,body);cell.append(table);detail.append(cell);$('processes').append(detail);
54
+ }
55
+ }
56
+ $('process-empty').hidden=rows.length>0;
57
+ if(focus)for(const button of $('processes').querySelectorAll('button[data-group]'))if(button.dataset.group===focus)button.focus({preventScroll:true});
58
+ if(expanded.size>2000){const live=new Set((sample.applications||[]).map(g=>g.id));for(const id of expanded)if(!live.has(id))expanded.delete(id);}
59
+ }
60
+ function stop(){active=false;if(timer)win.clearTimeout(timer);timer=undefined;}
61
+ async function poll(){if(disposed||paused||blocked||doc.hidden||busy||!active)return;if(timer)win.clearTimeout(timer);timer=undefined;busy=true;
62
+ try{const value=await call('system.resources');if(disposed||!active)return;if(!value||value.version!==1||!value.machine||!Array.isArray(value.disks)||!Array.isArray(value.networks)||!Array.isArray(value.topMemory)||!Array.isArray(value.topCpu))throw Error('主程序暂不支持资源统计,请更新 MyTools');const fresh=sample?.sampledAt!==value.sampledAt;sample=value;history=appendSample(history,value);render();status(value.warming?'正在建立 CPU / 网速采样基线,下一次刷新后显示实时数据':'实时监控中 · 关闭或隐藏插件后暂停采样');
63
+ if(fresh&&prefs.alerts){const reasons=violations(sample,prefs);consecutive=reasons.length?consecutive+1:0;if(consecutive>=3){$('alert').hidden=false;$('alert').textContent=reasons.join(';');if(Date.now()-lastAlert>=300000){lastAlert=Date.now();if(!notificationBlocked)try{await call('system.notify',{title:'电脑助手资源提醒',body:reasons.join(';')});}catch{notificationBlocked=true;status('系统通知不可用,仍在当前页面显示提醒',true);}}}else $('alert').hidden=true;}
64
+ }catch(e){blocked=true;status(e.message||String(e),true);$('retry').hidden=false;}
65
+ finally{busy=false;if(active&&!disposed&&!paused&&!blocked&&!doc.hidden)timer=win.setTimeout(()=>void poll(),prefs.interval);}
66
+ }
67
+ function start(){if(disposed||paused||blocked||doc.hidden)return;active=true;void poll();}
68
+ $('pause').onclick=()=>{paused=!paused;$('pause').textContent=paused?'继续监控':'暂停监控';if(paused){stop();status('监控已暂停');}else start();};
69
+ $('retry').onclick=()=>{blocked=false;$('retry').hidden=true;start();};$('network').onchange=()=>{networkChosen=true;render();};
70
+ for(const id of ['process-sort','process-mode','memory-metric'])$(id).onchange=renderProcesses;
71
+ $('process-query').oninput=renderProcesses;
72
+ for(const name of ['overview','process','hardware','settings'])$('tab-'+name).onclick=()=>{for(const tab of ['overview','process','hardware','settings']){$('page-'+tab).hidden=tab!==name;$('tab-'+tab).classList.toggle('active',tab===name);}};
73
+ function fillSettings(){$('interval').value=String(prefs.interval);$('alerts').checked=prefs.alerts;$('cpu-threshold').value=String(prefs.cpu);$('memory-threshold').value=String(prefs.memory);$('disk-threshold').value=String(prefs.diskGb);}
74
+ $('settings-form').onsubmit=async e=>{e.preventDefault();$('save').disabled=true;try{const next=preferences({interval:Number($('interval').value),alerts:$('alerts').checked,cpu:Number($('cpu-threshold').value),memory:Number($('memory-threshold').value),diskGb:Number($('disk-threshold').value)});await call('storage.set',{key:'computer-assistant.settings.v1',value:next});prefs=next;consecutive=0;notificationBlocked=false;if(!prefs.alerts)$('alert').hidden=true;status('监控设置已保存');stop();start();}catch(error){status(error.message||String(error),true);}finally{$('save').disabled=false;}};
75
+ doc.addEventListener('visibilitychange',()=>{if(doc.hidden)stop();else start();});
76
+ function dispose(){disposed=true;stop();}win.addEventListener('pagehide',dispose);win.addEventListener('beforeunload',dispose);
77
+ $('theme').onclick=()=>{const theme=doc.documentElement.dataset.theme==='dark'?'light':'dark';doc.documentElement.dataset.theme=theme;try{win.localStorage.setItem('computer-assistant.theme',theme);}catch{}};
78
+ try{doc.documentElement.dataset.theme=win.localStorage.getItem('computer-assistant.theme')||(win.matchMedia('(prefers-color-scheme: dark)').matches?'dark':'light');}catch{}
79
+ async function init(){if(initialized||disposed)return;initialized=true;try{prefs=preferences(await call('storage.get',{key:'computer-assistant.settings.v1'}));}catch(e){status(e.message||String(e),true);}fillSettings();start();}
80
+ fillSettings();if(api)api.onPluginReady(init);else status('预览模式:请从 MyTools 打开电脑助手');
81
+ return {poll,start,stop,dispose,get busy(){return busy;}};
82
+ }
83
+ if(typeof document!=='undefined')createAssistant(document,window.mytools);
package/icon.svg ADDED
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><rect x="3" y="7" width="58" height="43" rx="9" fill="#3275ce"/><path d="M13 34h9l6-14 9 24 6-10h9M25 56h14M32 50v6" fill="none" stroke="#fff" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/></svg>
package/index.html ADDED
@@ -0,0 +1,14 @@
1
+ <!doctype html><html lang="zh-CN"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>电脑助手</title><link rel="stylesheet" href="style.css"></head><body><main><header><h1>电脑助手</h1><nav><button id="tab-overview" class="active">概览</button><button id="tab-process">进程排行</button><button id="tab-hardware">硬件信息</button><button id="tab-settings">设置</button></nav><button id="theme" aria-label="切换主题">◐</button><button id="pause">暂停监控</button></header><p id="alert" class="alert" role="status" hidden></p><section id="page-overview"><div class="cards"><article><span>CPU</span><strong id="cpu">—</strong></article><article><span>内存</span><strong id="memory">—</strong><small id="memory-detail"></small></article><article><span>交换 / 页面文件</span><strong id="swap">—</strong></article><article><span>系统运行时长</span><strong id="uptime">—</strong></article></div><div class="charts"><article><h2>CPU · 最近一分钟</h2><svg id="cpu-chart" viewBox="0 0 600 100" role="img" aria-label="CPU 变化曲线"></svg></article><article><h2>内存 · 最近一分钟</h2><svg id="memory-chart" viewBox="0 0 600 100" role="img" aria-label="内存变化曲线"></svg></article></div><div class="network-row"><label>网卡 <select id="network" aria-label="选择监控网卡"></select></label><span>下载 <b id="download">—</b></span><span>上传 <b id="upload">—</b></span></div><p class="note">逐网卡统计,不累加虚拟网卡或 VPN,避免重复计算。首次采样或长时间暂停后需要等待下一次刷新。</p><h2>磁盘空间</h2><table><thead><tr><th>挂载点</th><th>已用</th><th>可用</th><th>容量</th></tr></thead><tbody id="disks"></tbody></table></section><section id="page-process" hidden>
2
+ <div class="row"><h2>资源排行(前 20)</h2></div>
3
+ <div class="ranking-controls">
4
+ <label>查看方式 <select id="process-mode"><option value="apps">按应用汇总</option><option value="processes">按进程查看</option></select></label>
5
+ <label>内存口径 <select id="memory-metric"><option value="private">私有工作集</option><option value="working">工作集(含共享)</option></select></label>
6
+ <label>排序 <select id="process-sort" aria-label="进程排序"><option value="memory">按内存</option><option value="cpu">按 CPU</option></select></label>
7
+ <input id="process-query" placeholder="搜索名称或 PID…" aria-label="搜索名称或 PID">
8
+ </div>
9
+ <p id="process-warning" class="alert" hidden>当前主程序未提供应用汇总和私有内存,请更新 MyTools;暂时只显示旧版进程工作集排行。</p>
10
+ <p id="process-note" class="note"></p>
11
+ <p class="note">CPU 按整机 0—100% 显示;点击应用名称展开全部关联进程。仅展示数据,不结束进程。</p>
12
+ <table><thead><tr><th>应用 / 进程</th><th id="process-identity-heading">主 PID / 分组依据</th><th>CPU</th><th id="process-memory-heading">私有工作集</th></tr></thead><tbody id="processes"></tbody></table>
13
+ <p id="process-empty" class="note" hidden>没有匹配的应用或进程。</p>
14
+ </section><section id="page-hardware" hidden><h2>硬件与系统</h2><table><tbody id="hardware"></tbody></table></section><section id="page-settings" hidden><h2>监控设置</h2><form id="settings-form"><label>刷新间隔 <select id="interval"><option value="1000">1 秒</option><option value="2000">2 秒</option><option value="5000">5 秒</option></select></label><label><input id="alerts" type="checkbox">开启资源占用提醒(默认关闭)</label><label>CPU 阈值 % <input id="cpu-threshold" type="number" min="20" max="100" required></label><label>内存阈值 % <input id="memory-threshold" type="number" min="20" max="100" required></label><label>磁盘剩余阈值 GiB <input id="disk-threshold" type="number" min="1" max="1000" required></label><p class="note">仅插件打开且可见时监控。连续 3 次采样达到提醒条件后显示,系统通知最多每 5 分钟一次;隐藏或关闭插件后不后台提醒。GPU 与温度暂不支持。</p><button id="save">保存设置</button></form></section><footer><span id="status" role="status" aria-live="polite">正在初始化…</span><button id="retry" hidden>重试连接</button><small id="updated"></small></footer></main><script type="module" src="app.mjs"></script></body></html>
package/model.mjs ADDED
@@ -0,0 +1,7 @@
1
+ export const defaults={interval:1000,alerts:false,cpu:90,memory:90,diskGb:10};
2
+ export function preferences(value){if(value==null)return {...defaults};if(typeof value!=='object'||![1000,2000,5000].includes(value.interval)||typeof value.alerts!=='boolean'||!Number.isFinite(value.cpu)||value.cpu<20||value.cpu>100||!Number.isFinite(value.memory)||value.memory<20||value.memory>100||!Number.isFinite(value.diskGb)||value.diskGb<1||value.diskGb>1000)throw Error('监控设置格式无效,已使用默认值,未覆盖原设置');return {interval:value.interval,alerts:value.alerts,cpu:value.cpu,memory:value.memory,diskGb:value.diskGb};}
3
+ export function bytes(value){if(!Number.isFinite(value))return '不可用';value=Math.max(0,value);if(value<1024)return Math.round(value)+' B';const n=Math.min(4,Math.floor(Math.log(value)/Math.log(1024)));return (value/1024**n).toFixed(1)+' '+['B','KiB','MiB','GiB','TiB'][n];}
4
+ export function pct(value){return Number.isFinite(value)?Math.min(100,Math.max(0,value)).toFixed(1)+'%':'不可用';}
5
+ export function violations(sample,prefs){const m=sample.machine,items=[];if(!sample.warming&&m.cpu>=prefs.cpu)items.push('CPU 使用率偏高');if(m.totalMemory>0&&100*m.usedMemory/m.totalMemory>=prefs.memory)items.push('内存使用率偏高');for(const disk of sample.disks||[])if(disk.total>0&&disk.available<prefs.diskGb*1024**3)items.push(disk.mount+' 可用空间不足');return items;}
6
+ export function appendSample(history,sample){if(history.some(s=>s.sampledAt===sample.sampledAt))return history;return [...history.filter(s=>s.sampledAt>=sample.sampledAt-60000),sample].slice(-61);}
7
+ export function duration(seconds){const hours=Math.floor(seconds/3600);return Math.floor(hours/24)+' 天 '+hours%24+' 时 '+Math.floor(seconds%3600/60)+' 分';}
package/package.json CHANGED
@@ -1,6 +1,36 @@
1
1
  {
2
2
  "name": "@mytools-all/mytools-computer-assistant",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
4
+ "description": "轻量的本机资源监控与可选提醒",
5
+ "type": "module",
6
+ "main": "index.html",
7
+ "license": "MIT",
8
+ "files": [
9
+ "plugin.json",
10
+ "index.html",
11
+ "app.mjs",
12
+ "model.mjs",
13
+ "style.css",
14
+ "icon.svg",
15
+ "README.md",
16
+ "LICENSE",
17
+ "ranking.mjs"
18
+ ],
19
+ "devDependencies": {
20
+ "happy-dom": "21.0.4"
21
+ },
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/mytools-all/mytools-computer-assistant.git"
28
+ },
29
+ "homepage": "https://github.com/mytools-all/mytools-computer-assistant#readme",
30
+ "bugs": {
31
+ "url": "https://github.com/mytools-all/mytools-computer-assistant/issues"
32
+ },
33
+ "scripts": {
34
+ "test": "node --test"
35
+ }
6
36
  }
package/plugin.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "mytools-computer-assistant",
3
+ "pluginName": "电脑助手",
4
+ "description": "本机 CPU、内存、网速与磁盘空间监控,支持进程排行和可选提醒",
5
+ "version": "0.1.1",
6
+ "apiVersion": 1,
7
+ "main": "index.html",
8
+ "icon": "icon.svg",
9
+ "author": "MyTools",
10
+ "capabilities": [
11
+ "system.resources",
12
+ "storage.get",
13
+ "storage.set",
14
+ "system.notify"
15
+ ],
16
+ "features": [
17
+ {
18
+ "code": "monitor",
19
+ "explain": "打开电脑助手",
20
+ "cmds": [
21
+ "电脑助手",
22
+ "资源监控",
23
+ "系统监控",
24
+ "CPU",
25
+ "内存监控"
26
+ ]
27
+ }
28
+ ]
29
+ }
package/ranking.mjs ADDED
@@ -0,0 +1,33 @@
1
+ import {bytes} from './model.mjs';
2
+
3
+ export function detailed(sample) {
4
+ return sample?.processDetailsVersion === 2 && Array.isArray(sample.applications);
5
+ }
6
+
7
+ export function processRows(sample) {
8
+ if (detailed(sample)) return sample.applications.flatMap(group => group.processes);
9
+ return [...new Map([...(sample?.topMemory || []), ...(sample?.topCpu || [])].map(row => [row.pid, row])).values()];
10
+ }
11
+
12
+ export function memoryValue(row, metric) {
13
+ if (metric === 'working') return row.memory;
14
+ if (Number.isFinite(row.privateMemory)) return row.privateMemory;
15
+ return row.privateMemoryKnown > 0 ? row.knownPrivateMemory : -1;
16
+ }
17
+
18
+ export function memoryText(row, metric) {
19
+ if (metric === 'working') return bytes(row.memory);
20
+ if (Number.isFinite(row.privateMemory)) return bytes(row.privateMemory);
21
+ if (row.privateMemoryKnown > 0) return bytes(row.knownPrivateMemory) + '(部分 ' + row.privateMemoryKnown + '/' + row.processCount + ')';
22
+ return '不可用';
23
+ }
24
+
25
+ export function rankedRows(sample, {mode = 'apps', metric = 'private', sort = 'memory', query = ''} = {}) {
26
+ const source = mode === 'apps' && detailed(sample) ? sample.applications : processRows(sample);
27
+ const needle = query.trim().toLowerCase();
28
+ const filtered = source.filter(row => !needle || [row.name, row.pid ?? row.rootPid, row.role || '', ...(row.processes || []).map(p => p.name + ' ' + p.pid)].join(' ').toLowerCase().includes(needle));
29
+ return [...filtered].sort((a, b) => {
30
+ const delta = sort === 'cpu' ? b.cpu - a.cpu : memoryValue(b, metric) - memoryValue(a, metric);
31
+ return delta || String(a.id ?? a.pid).localeCompare(String(b.id ?? b.pid));
32
+ }).slice(0, 20);
33
+ }
package/style.css ADDED
@@ -0,0 +1,3 @@
1
+ :root{color-scheme:dark;--bg:#171d25;--fg:#e8edf5;--surface:#202936;--line:#ffffff18;--dim:#a5b1c2;--accent:#83b9ff;--warning:#efbb69}html[data-theme=light]{color-scheme:light;--bg:#f5f7fa;--fg:#263244;--surface:#fff;--line:#dce3ec;--dim:#5f6e82;--accent:#3275ce;--warning:#9e6010}*{box-sizing:border-box}body{margin:0;font:14px "Segoe UI","Microsoft YaHei",sans-serif;background:var(--bg);color:var(--fg)}main{max-width:1400px;margin:auto;padding:16px}header,nav,.row,.network-row,footer{display:flex;gap:12px;align-items:center;flex-wrap:wrap}header{border-bottom:1px solid var(--line);padding-bottom:14px}header h1{font-size:19px;margin:0 12px 0 0}nav{flex:1}button,input,select{font:inherit;color:var(--fg);background:var(--surface);border:1px solid var(--line);border-radius:7px;padding:8px}button{cursor:pointer}.active{border-color:var(--accent);color:var(--accent)}button:disabled{opacity:.6}input:focus-visible,button:focus-visible,select:focus-visible{outline:2px solid var(--accent)}section{padding-top:16px}[hidden]{display:none!important}.cards{display:grid;grid-template-columns:repeat(auto-fit,minmax(150px,1fr));gap:12px}article{background:var(--surface);border:1px solid var(--line);padding:16px;border-radius:10px}.cards span,small,.note{color:var(--dim);font-size:12px}.cards strong{display:block;font-size:23px;margin:8px 0}.charts{display:grid;grid-template-columns:1fr 1fr;gap:12px;margin:14px 0}.charts svg{display:block;width:100%;height:100px;color:var(--accent);background:linear-gradient(transparent 49%,var(--line) 50%,transparent 51%)}h2{font-size:15px}table{width:100%;border-collapse:collapse;font-size:13px}th,td{text-align:left;border-bottom:1px solid var(--line);padding:10px;overflow-wrap:anywhere}.note{line-height:1.7}.row{justify-content:space-between}form{display:grid;gap:14px;max-width:650px}form label{display:flex;align-items:center;gap:10px}footer{border-top:1px solid var(--line);padding-top:14px;margin-top:20px;font-size:12px}#status{flex:1}#status[data-error=true]{color:#ef8787}.alert{border:1px solid var(--warning);color:var(--warning);padding:12px;border-radius:8px}@media(max-width:650px){.charts{grid-template-columns:1fr}.cards{grid-template-columns:1fr 1fr}main{padding:12px}header{gap:8px}nav{order:3;flex-basis:100%}}
2
+
3
+ .ranking-controls{display:flex;align-items:center;flex-wrap:wrap;gap:12px}.ranking-controls label{display:flex;align-items:center;gap:6px}.ranking-controls input{min-width:160px;flex:1}.group-toggle{text-align:left;border-color:transparent;padding:5px;color:var(--accent)}.group-toggle[aria-expanded=true]{border-color:var(--line)}.group-details{background:var(--surface);padding:10px 18px}.group-details table{font-size:12px}.group-details thead{color:var(--dim)}