From fe4516df005fd80bdfb8ad7269d27eed7790b530 Mon Sep 17 00:00:00 2001 From: whyour Date: Sun, 28 Jul 2024 18:40:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=89=A7=E8=A1=8C=20task=5Fb?= =?UTF-8?q?efore=20=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E9=A1=BA=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shell/preload/sitecustomize.js | 14 +++++--------- shell/preload/sitecustomize.py | 21 +++++++++------------ 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/shell/preload/sitecustomize.js b/shell/preload/sitecustomize.js index 7464483b..3cbe3aac 100644 --- a/shell/preload/sitecustomize.js +++ b/shell/preload/sitecustomize.js @@ -1,13 +1,5 @@ const { execSync } = require('child_process'); -const { sendNotify } = require('./notify.js'); require(`./env.js`); - -function initGlobal() { - global.QLAPI = { - notify: sendNotify, - }; -} - function expandRange(rangeStr, max) { const tempRangeStr = rangeStr .trim() @@ -76,8 +68,12 @@ function run() { } try { - initGlobal(); run(); + + const { sendNotify } = require('./notify.js'); + global.QLAPI = { + notify: sendNotify, + }; } catch (error) { console.log(`run builtin code error: `, error, '\n'); } diff --git a/shell/preload/sitecustomize.py b/shell/preload/sitecustomize.py index f9d426a9..09eba43b 100644 --- a/shell/preload/sitecustomize.py +++ b/shell/preload/sitecustomize.py @@ -5,17 +5,6 @@ import json import builtins import sys import env -from notify import send - - -class BaseApi: - def notify(self, *args, **kwargs): - return send(*args, **kwargs) - - -def init_global(): - QLAPI = BaseApi() - builtins.QLAPI = QLAPI def try_parse_int(value): @@ -92,7 +81,15 @@ def run(): try: - init_global() run() + + from notify import send + + class BaseApi: + def notify(self, *args, **kwargs): + return send(*args, **kwargs) + + QLAPI = BaseApi() + builtins.QLAPI = QLAPI except Exception as error: print(f"run builtin code error: {error}\n")