@@ -65,6 +65,7 @@ export type MacProps = {
6565 machine : MachineDef ;
6666 ramSize ?: MachineDefRAMSize ;
6767 screenSize : ScreenSize ;
68+ screenScale ?: number ;
6869 ethernetProvider ?: EmulatorEthernetProvider ;
6970 customDate ?: Date ;
7071 debugFallback ?: boolean ;
@@ -87,6 +88,7 @@ export default function Mac({
8788 machine,
8889 ramSize,
8990 screenSize : screenSizeProp ,
91+ screenScale : screenScaleProp ,
9092 ethernetProvider,
9193 customDate,
9294 debugFallback,
@@ -98,7 +100,7 @@ export default function Mac({
98100} : MacProps ) {
99101 const screenRef = useRef < HTMLCanvasElement > ( null ) ;
100102 const [ emulatorLoaded , setEmulatorLoaded ] = useState ( false ) ;
101- const [ scale , setScale ] = useState < number | undefined > ( undefined ) ;
103+ const [ scale , setScale ] = useState < number | undefined > ( screenScaleProp ) ;
102104 const [ fullscreen , setFullscreen ] = useState ( false ) ;
103105 const [ emulatorLoadingProgress , setEmulatorLoadingProgress ] = useState ( [
104106 0 , 0 ,
@@ -134,11 +136,8 @@ export default function Mac({
134136
135137 const initialScreenSize = useMemo (
136138 ( ) =>
137- machine . fixedScreenSize ??
138- ( typeof screenSizeProp === "object"
139- ? screenSizeProp
140- : SCREEN_SIZES [ screenSizeProp ] ( machine ) ) ,
141- [ machine , screenSizeProp ]
139+ computeInitialScreenSize ( machine , screenSizeProp , screenScaleProp ) ,
140+ [ machine , screenSizeProp , screenScaleProp ]
142141 ) ;
143142 const { width : initialScreenWidth , height : initialScreenHeight } =
144143 initialScreenSize ;
@@ -204,8 +203,13 @@ export default function Mac({
204203 if ( hasSavedHD ) {
205204 emulatorDisks . push ( SAVED_HD ) ;
206205 }
207- const useSharedMemory =
208- typeof SharedArrayBuffer !== "undefined" && ! debugFallback ;
206+ const hasSharedArrayBuffer = typeof SharedArrayBuffer !== "undefined" ;
207+ if ( ! hasSharedArrayBuffer ) {
208+ console . warn (
209+ "SharedArrayBuffer is not available, fallback more will be used. Performance may be degraded."
210+ ) ;
211+ }
212+ const useSharedMemory = hasSharedArrayBuffer && ! debugFallback ;
209213 const emulator = new Emulator (
210214 {
211215 machine,
@@ -377,6 +381,10 @@ export default function Mac({
377381 handleMacLibraryProgress ,
378382 ] ) ;
379383
384+ useEffect ( ( ) => {
385+ document . body . classList . toggle ( "embed" , screenSizeProp === "embed" ) ;
386+ } , [ screenSizeProp ] ) ;
387+
380388 const handleFullScreenClick = ( ) => {
381389 // Make the entire page go fullscreen (instead of just the screen
382390 // canvas) because iOS Safari does not maintain the aspect ratio of the
@@ -688,7 +696,8 @@ export default function Mac({
688696 fullscreen ||
689697 // These screen sizes always want fullscreen-like bezels
690698 screenSizeProp === "fullscreen" ||
691- screenSizeProp === "window"
699+ screenSizeProp === "window" ||
700+ screenSizeProp === "embed"
692701 }
693702 led = {
694703 ( ! emulatorLoaded && ! debugPaused ) ||
@@ -781,14 +790,15 @@ export default function Mac({
781790 />
782791 ) }
783792 </ ScreenFrame >
784- { ! fullscreen && disks [ 0 ] ?. infiniteHdSubset !== "mfs " && (
793+ { ! fullscreen && screenSizeProp !== "embed " && (
785794 < DrawersContainer >
786- { emulatorSupportsCDROMs ( machine . emulatorType ) && (
787- < MacCDROMs
788- onRun = { loadCDROM }
789- platform = { machine . platform }
790- />
791- ) }
795+ { emulatorSupportsCDROMs ( machine . emulatorType ) &&
796+ disks [ 0 ] ?. infiniteHdSubset !== "mfs" && (
797+ < MacCDROMs
798+ onRun = { loadCDROM }
799+ platform = { machine . platform }
800+ />
801+ ) }
792802 { includeLibrary &&
793803 emulatorSupportsDownloadsFolder (
794804 machine . emulatorType
@@ -905,35 +915,54 @@ function uploadFiles(
905915const SMALL_BEZEL_THRESHOLD = 80 ;
906916const MEDIUM_BEZEL_THRESHOLD = 168 ;
907917
908- const SCREEN_SIZES : {
909- [ id : string ] : ( machine : MachineDef ) => { width : number ; height : number } ;
910- } = {
911- "auto" : machine => {
912- const availableWidth = window . innerWidth - MEDIUM_BEZEL_THRESHOLD ;
913- const availableHeight = window . innerHeight - MEDIUM_BEZEL_THRESHOLD ;
914- const {
915- supportedScreenSizes = [
916- { width : 1600 , height : 1200 } ,
917- { width : 1280 , height : 1024 } ,
918- { width : 1152 , height : 870 } ,
919- { width : 1024 , height : 768 } ,
920- { width : 800 , height : 600 } ,
921- { width : 640 , height : 480 } ,
922- ] ,
923- } = machine ;
924- for ( const { width, height} of supportedScreenSizes ) {
925- if ( width <= availableWidth && height <= availableHeight ) {
926- return { width, height} ;
918+ function computeInitialScreenSize (
919+ machine : MachineDef ,
920+ screenSizeProp ?: ScreenSize ,
921+ screenScaleProp ?: number
922+ ) : { width : number ; height : number } {
923+ if ( machine . fixedScreenSize ) {
924+ return machine . fixedScreenSize ;
925+ }
926+ if ( typeof screenSizeProp === "object" ) {
927+ return screenSizeProp ;
928+ }
929+ let { innerWidth : windowWidth , innerHeight : windowHeight } = window ;
930+ let { width : screenWidth , height : screenHeight } = window . screen ;
931+ if ( screenScaleProp ) {
932+ windowWidth = Math . floor ( windowWidth / screenScaleProp ) ;
933+ windowHeight = Math . floor ( windowHeight / screenScaleProp ) ;
934+ screenWidth = Math . floor ( screenWidth / screenScaleProp ) ;
935+ screenHeight = Math . floor ( screenHeight / screenScaleProp ) ;
936+ }
937+ switch ( screenSizeProp ) {
938+ case undefined :
939+ case "auto" : {
940+ const availableWidth = windowWidth - MEDIUM_BEZEL_THRESHOLD ;
941+ const availableHeight = windowHeight - MEDIUM_BEZEL_THRESHOLD ;
942+ const {
943+ supportedScreenSizes = [
944+ { width : 1600 , height : 1200 } ,
945+ { width : 1280 , height : 1024 } ,
946+ { width : 1152 , height : 870 } ,
947+ { width : 1024 , height : 768 } ,
948+ { width : 800 , height : 600 } ,
949+ { width : 640 , height : 480 } ,
950+ ] ,
951+ } = machine ;
952+ for ( const { width, height} of supportedScreenSizes ) {
953+ if ( width <= availableWidth && height <= availableHeight ) {
954+ return { width, height} ;
955+ }
927956 }
957+ return { width : 640 , height : 480 } ;
928958 }
929- return { width : 640 , height : 480 } ;
930- } ,
931- "window" : ( ) => ( { width : window . innerWidth , height : window . innerHeight } ) ,
932- "fullscreen" : ( ) => ( {
933- width : window . screen . width ,
934- height : window . screen . availHeight ,
935- } ) ,
936- } ;
959+ case "window" :
960+ case "embed" :
961+ return { width : windowWidth , height : windowHeight } ;
962+ case "fullscreen" :
963+ return { width : screenWidth , height : screenHeight } ;
964+ }
965+ }
937966
938967// Assume that mobile devices that can't do hover events also need an explicit
939968// control for bringing up the on-screen keyboard.
0 commit comments