first commit

This commit is contained in:
编码猿
2024-09-27 01:20:28 +08:00
commit ddc91bf4e2
137 changed files with 4017 additions and 0 deletions

1
app/util/.pydio Normal file
View File

@@ -0,0 +1 @@
14205bf4-de6f-41ec-b85a-a2ffdea1a0be

0
app/util/__init__.py Executable file
View File

View File

@@ -0,0 +1 @@
b4375dff-038b-459e-8990-080bb06da3fc

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

7
app/util/apple_script.py Executable file
View File

@@ -0,0 +1,7 @@
from app.util.shell_execute import execute
class AppleScript:
@staticmethod
def exec(code: str, timeout=None):
stat, out, err = execute('/usr/bin/osascript', code, timeout)
return stat, out, err

34
app/util/shell_execute.py Executable file
View File

@@ -0,0 +1,34 @@
import base64
import json
import os
import sys
import time
import traceback
from io import StringIO
from subprocess import PIPE, Popen, TimeoutExpired
def popen(cmd, sys_env=True, **kwargs):
if sys_env and kwargs.get('env') is not None:
kwargs['env'] = os.environ.copy().update(kwargs['env'])
return Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, encoding='utf-8', **kwargs)
def execute(cmd, input_str=None, timeout=None, **kwargs):
p = popen(cmd, **kwargs)
try:
out, err = p.communicate(input_str, timeout=timeout)
except TimeoutExpired:
out = ''
err = get_exception()
p.kill()
stat = p.returncode
return stat, out, err
def get_exception():
with StringIO() as io:
traceback.print_exc(file=io)
io.seek(0)
content = io.read()
return content

63
app/util/system_api.py Executable file
View File

@@ -0,0 +1,63 @@
from app.util.shell_execute import execute
from app.util.apple_script import AppleScript
import Quartz
from app.config import Config
import time
def open_url(url, new=False, wait=False, bundle: str = None, p_args=None):
args = ['/usr/bin/open']
if new:
args.append('-n')
if wait:
args.append('-W')
if bundle:
args.append('-b')
args.append(bundle)
args.append(url)
if p_args is not None:
args.append('--args')
for arg in p_args:
args.append(arg)
return execute(args)
def open_preference(name, **kwargs):
open_url('/System/Library/PreferencePanes/%s.prefPane' % name, bundle='com.apple.systempreferences', **kwargs)
# 获取设备信息
def ge_device_info():
if Config.cg_session_info is None:
Config.cg_session_info = getattr(Quartz, 'CGSessionCopyCurrentDictionary')
return Config.cg_session_info()
def sudo(command: str, timeout=None):
stat, out, err = execute('/usr/bin/sudo -S %s' % (command), Config.password, timeout, shell=True)
return stat, out, err
def lock_screen():
code = '''tell application id "com.apple.ScreenSaver.Engine" to launch'''
return AppleScript.exec(code)
def unlock():
unlock_screen()
time.sleep(0.5)
keystroke()
time.sleep(0.5)
success()
# 唤醒屏幕进入锁屏界面
def unlock_screen():
code = '''tell application "System Events" to keystroke "a" using command down'''
return AppleScript.exec(code)
# 输入密码
def keystroke():
code = '''tell application "System Events" to keystroke "%s" using {}''' % (Config.password)
return AppleScript.exec(code)
# 输完密码按下回车
def success():
code = '''tell application "System Events" to keystroke return using {}'''
return AppleScript.exec(code)