# -*- coding: utf-8 -*- u"""重载 EasyEDA 客户端页面(skill §9k/§9s):关对话框 → 删铺铜边框 → 存盘 → reload → 等 windowId 变掉。""" import json, os, sys, time, urllib.request HERE = os.path.dirname(os.path.abspath(__file__)); sys.path.insert(0, HERE) from eda import run, port JS = u""" const sleep = ms => new Promise(r => setTimeout(r, ms)); const nat = b => { const o={bubbles:true,cancelable:true,view:window,button:0}; for (const t of ['pointerdown','mousedown','pointerup','mouseup','click']) b.dispatchEvent(new (t.startsWith('pointer')?PointerEvent:MouseEvent)(t,o)); }; for (const b of document.querySelectorAll('button')) if ((b.innerText||'').trim()==='取消' && b.offsetParent!==null) { nat(b); await sleep(800); } await eda.dmt_EditorControl.openDocument('f126ffb29c92f9b2'); await sleep(1200); let n = 0; for (const o of await eda.pcb_PrimitivePour.getAll()) { await eda.pcb_PrimitivePour.delete(o.primitiveId); n++; } await eda.pcb_Document.save(); await sleep(1500); window.onbeforeunload = null; setTimeout(() => location.reload(true), 300); return {deletedPours: n}; """ def wid(): try: with urllib.request.urlopen('http://127.0.0.1:%d/health' % port(), timeout=3) as r: return json.loads(r.read()).get('activeWindowId') except Exception: return None w0 = wid() r = run(JS, timeout=60) print(u'重载前 windowId %s,删铺铜边框 %s' % (w0, (r.get('result') or {}).get('deletedPours'))) for i in range(30): time.sleep(5) w = wid() if w and w != w0: print(u'已重载,新 windowId %s(%d s)' % (w, (i + 1) * 5)); time.sleep(10); sys.exit(0) sys.exit(u'!! 150 s 内 windowId 没变,重载没成功')