11/*
2- * Copyright (c) 2018-2024 Moddable Tech, Inc.
2+ * Copyright (c) 2018-2025 Moddable Tech, Inc.
33 *
44 * This file is part of the Moddable SDK Tools.
55 *
2020
2121import { } from "_262" ;
2222import { } from "harness" ;
23+ import Modules from "modules" ;
2324import ChecksumOut from "commodetto/checksumOut" ;
2425import Timer from "timer" ;
2526import config from "mc/config" ;
2627import { URL , URLSearchParams } from "url" ;
2728globalThis . URL = URL ;
2829globalThis . URLSearchParams = URLSearchParams ;
29- /* comment out the import of WiFi or Net if your platform doesn't support it */
30- import WiFi from "wifi" ;
31- import Net from "net" ;
32- /* end network */
3330
3431globalThis . $DO = function ( f ) {
3532 return function ( ...args ) {
@@ -134,8 +131,10 @@ Object.defineProperty(globalThis, "screen", {
134131 value
135132 } ) ;
136133
137- screen = new Screen ( { width : config . mc_width ?? width ?? 240 , height : config . mc_height ?? height ?? 320 } ) ;
138- screen . configure ( { show : ( ( undefined === config . mc_width ) && ( undefined === config . mc_height ) ) || ( ( width === config . mc_width ) && ( height === config . mc_height ) ) } ) ;
134+ const mc_width = ( undefined === config . mc_width ) ? undefined : Number ( config . mc_width ) ;
135+ const mc_height = ( undefined === config . mc_height ) ? undefined : Number ( config . mc_height ) ;
136+ screen = new Screen ( { width : mc_width ?? width ?? 240 , height : mc_height ?? height ?? 320 } ) ;
137+ screen . configure ( { show : ( ( undefined === mc_width ) && ( undefined === mc_height ) ) || ( ( width === mc_width ) && ( height === mc_height ) ) } ) ;
139138
140139 return screen ;
141140 } ,
@@ -147,15 +146,16 @@ Object.defineProperty(globalThis, "screen", {
147146 value
148147 } ) ;
149148
150- screen = new Screen ( { width : config . mc_width ?? value . width , height : config . mc_height ?? value . height } ) ;
149+ const mc_width = ( undefined === config . mc_width ) ? undefined : Number ( config . mc_width ) ;
150+ const mc_height = ( undefined === config . mc_height ) ? undefined : Number ( config . mc_height ) ;
151+ screen = new Screen ( { width : mc_width ?? value . width , height : mc_height ?? value . height } ) ;
151152 }
152153} ) ;
153154
154- /* *** WiFi */
155155globalThis . $NETWORK = {
156- get connected ( ) {
157- if ( WiFi === undefined )
158- return false ;
156+ get connected ( ) {
157+ const WiFi = Modules . importNow ( "wifi" ) ;
158+ const Net = Modules . importNow ( "net" ) ;
159159
160160 if ( WiFi . Mode . station !== WiFi . mode )
161161 WiFi . mode = WiFi . Mode . station ;
@@ -186,6 +186,7 @@ globalThis.$NETWORK = {
186186 } ,
187187 async resolve ( domain ) {
188188 return new Promise ( ( resolve , reject ) => {
189+ const Net = Modules . importNow ( "net" ) ;
189190 Net . resolve ( domain , ( name , address ) => {
190191 if ( address )
191192 resolve ( address ) ;
@@ -196,7 +197,7 @@ globalThis.$NETWORK = {
196197 } ,
197198 invalidDomain : "fail.moddable.com" ,
198199} ;
199- /* *** WiFi */
200+ Object . freeze ( globalThis . $NETWORK ) ;
200201
201202class HostObject extends Native ( "xs_hostobject_destructor" ) {
202203 constructor ( ) { super ( ) ; native ( "xs_hostobject" ) . call ( this ) ; }
@@ -240,7 +241,7 @@ globalThis.$TESTMC = {
240241 Behavior : TestBehavior
241242} ;
242243
243- Object . freeze ( [ globalThis . $TESTMC , globalThis . $NETWORK ] , true ) ;
244+ Object . freeze ( globalThis . $TESTMC , true ) ;
244245
245246export default function ( ) {
246247 const former = globalThis . assert ;
0 commit comments