Skip to content

Commit

Permalink
add safarie6 detection fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pmp-p committed Dec 2, 2023
1 parent 79f74b6 commit aff1028
Show file tree
Hide file tree
Showing 10 changed files with 290 additions and 186 deletions.
28 changes: 14 additions & 14 deletions pygbag/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,31 @@ def __repr__(self):

__str__ = __repr__

class window_navigator:
userAgent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36"

# fake host document.window
import platform as fakehost


def truc(*argv, **kw):
print("truc", argv, kw)

def prompt():
# FIXME for js style console should be
# CSI(f"{TTY.LINES+TTY.CONSOLE};1H{prompt}")
print('\r>>> ',end='')

fakehost.is_browser = False
fakehost.async_input = async_input
fakehost.window = NoOp("platform.window")
fakehost.window.console = NoOp("platform.window.console")
fakehost.window.console.log = print
fakehost.window.get_terminal_console = truc
fakehost.window.RAW_MODE = 0
fakehost.window.navigator = window_navigator
fakehost.readline = lambda :""
fakehost.prompt = prompt

def set_raw_mode(mode):
import platform as fakehost
Expand Down Expand Up @@ -222,20 +236,6 @@ def eval(self, source):
self.buffer.insert(0, "#")
print(f"178: {count} lines queued for async eval")

async def input_console(self, prompt=">>> "):
if len(self.buffer):
return self.buffer.pop(0)

# if program wants I/O do not empty buffers
if self.shell.is_interactive:
if async_input:
maybe = await async_input()
else:
maybe = ""

if len(maybe):
return maybe
return None

async def async_get_pkg(cls, want, ex, resume):
print(
Expand Down
31 changes: 16 additions & 15 deletions pygbag/aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@
from pathlib import Path

try:
import aioconsole, aiohttp
#import aioconsole, aiohttp
import aiohttp
except Exception as e:
print(e,f"""
pygbag simulator rely on both aioconsole and aiohttp
pygbag simulator rely on : aiohttp asyncio_socks_server token_util
please use :
{sys.executable} -m pip install aioconsole aiohttp asyncio_socks_server token_util
{sys.executable} -m pip install aiohttp asyncio_socks_server token_util
""")
raise SystemExit



import aio.pep0723

if aio.pep0723.Config.dev_mode:
Expand All @@ -35,20 +35,21 @@


import pygbag.__main__

async def custom_async_input():
import platform
if platform.window.RAW_MODE:
# TODO: FIXME: implement embed.os_read and debug focus handler
#return await asyncio.sleep(0)
...
return await aioconsole.ainput("››› ")
#
# async def custom_async_input():
# import platform
# if platform.window.RAW_MODE:
## TODO: FIXME: implement embed.os_read and debug focus handler
# #return await asyncio.sleep(0)
# ...
# return await aioconsole.ainput("››› ")

aio.loop.create_task(
pygbag.__main__.import_site(
sourcefile=sys.argv[0],
simulator=True,
async_input=custom_async_input,
# async_input=custom_async_input,
async_input=None,
async_pkg=aio.pep0723.check_list(filename=sys.argv[0]),
)
)
Expand All @@ -61,7 +62,7 @@ async def custom_async_input():
aio.started = True

while not aio.exit:
next = time.time() + 0.016
next = time.time() + 0.0155
try:
aio.loop._run_once()
except KeyboardInterrupt:
Expand All @@ -72,7 +73,7 @@ async def custom_async_input():
past = int(-dt * 1000)
# do not spam for <4 ms late (50Hz vs 60Hz)
if past > 4:
print(f"aio: violation frame is {past} ms late")
print(f"\raio: violation frame is {past} ms late")
# too late do not sleep at all
else:
time.sleep(dt)
Expand Down
4 changes: 2 additions & 2 deletions pygbag/support/cross/__EMSCRIPTEN__.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def fix_preload_table_apk():
aio.defer(execfile, [f"{ROOTDIR}/{loadermain}"], {})
else:
pdb(f"no {loadermain} found for {sys.argv[0]} in {ROOTDIR}")
aio.defer(embed.prompt, (), {}, delay=2000)
#aio.defer(embed.prompt, (), {}, delay=2000)

# C should unlock aio loop when preload count reach 0.

Expand All @@ -350,7 +350,7 @@ def fix_preload_table_apk():
global fix_preload_table_apk, ROOTDIR
pdb("no assets preloaded")
os.chdir(ROOTDIR)
aio.defer(embed.prompt, (), {})
#aio.defer(embed.prompt, (), {})

# unlock embed looper because no preloading
embed.run()
Expand Down
41 changes: 25 additions & 16 deletions pygbag/support/cross/aio/pep0723.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ class Config:

mapping = {
"pygame": "pygame.base",
"pygame-ce": "pygame.base",
"python-i18n" : "i18n",
"pygame_ce": "pygame.base",
"python_i18n" : "i18n",
"pillow" : "PIL",
}

Expand Down Expand Up @@ -246,6 +246,19 @@ async def install_pkg(sysconf, wheel_url, wheel_pkg):
target.write(pkg.read())
install(target_filename, sysconf)

def do_patches():
global PATCHLIST
# apply any patches
while len(PATCHLIST):
dep = PATCHLIST.pop(0)
print(f"254: patching {dep}")
try:
import platform
platform.patches.pop(dep)()
except Exception as e:
sys.print_exception(e)


# FIXME: HISTORY and invalidate caches
async def pip_install(pkg, sysconf={}):
global sconf
Expand All @@ -264,7 +277,11 @@ async def pip_install(pkg, sysconf={}):
pkg = Config.mapping[pkg.lower()]
if pkg in HISTORY:
return
print("228: package renamed to", pkg)
print("279: package renamed to", pkg)

if pkg in platform.patches:
if not pkg in PATCHLIST:
PATCHLIST.append(pkg)

for repo in Config.pkg_repolist:
if pkg in repo:
Expand All @@ -280,13 +297,13 @@ async def pip_install(pkg, sysconf={}):
if line.find("-py3-none-any.whl") > 0:
wheel_url = line.split('"', 2)[1]
else:
print("270: ERROR: cannot find package :", pkg)
print("283: ERROR: cannot find package :", pkg)
except FileNotFoundError:
print("200: ERROR: cannot find package :", pkg)
print("285: ERROR: cannot find package :", pkg)
return

except:
print("204: ERROR: cannot find package :", pkg)
print("289: ERROR: cannot find package :", pkg)
return

if wheel_url:
Expand All @@ -296,7 +313,7 @@ async def pip_install(pkg, sysconf={}):
if pkg not in HISTORY:
HISTORY.append(pkg)
except:
print("212: INVALID", pkg, "from", wheel_url)
print("299: INVALID", pkg, "from", wheel_url)

PYGAME=0
async def parse_code(code, env):
Expand Down Expand Up @@ -418,15 +435,7 @@ async def check_list(code=None, filename=None):
platform.explore(sconf["platlib"])
await asyncio.sleep(0)

# apply any patches
while len(PATCHLIST):
dep = PATCHLIST.pop(0)
print(f"314: patching {dep}")
try:
import platform
platform.patches.pop(dep)()
except Exception as e:
sys.print_exception(e)
do_patches()

print("-" * 40)
print()
Expand Down
Loading

0 comments on commit aff1028

Please sign in to comment.