Skip to content

Commit

Permalink
take the first avilable device
Browse files Browse the repository at this point in the history
  • Loading branch information
Filip Andrzej Kaminski authored and Filip Andrzej Kaminski committed Apr 8, 2024
1 parent 272bbb7 commit ca4862c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 21 deletions.
18 changes: 11 additions & 7 deletions packages/vscode-extension/src/webview/utilities/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import iphoneSE from "../../assets/iphone_SE/skin.webp";
import iphoneSEmask from "../../assets/iphone_SE/mask.png";
import { Platform } from "../../common/DeviceManager";

export type SupportedDeviceName = keyof typeof SupportedDevices;
export type SupportedDeviceName = typeof SupportedDevices[number]["name"];

// iOS devices names should match supportedDeviceTypes inside the runtime
export const SupportedDevices = {
"iPhone 15 Pro": {
export const SupportedDevices = [
{
name: "iPhone 15 Pro",
platform: Platform.IOS,
screenWidth: 1179,
screenHeight: 2556,
Expand All @@ -23,7 +24,8 @@ export const SupportedDevices = {
frameImage: iphone15pro,
maskImage: iphone15promask,
},
"iPhone SE (3rd generation)": {
{
name: "iPhone SE (3rd generation)",
platform: Platform.IOS,
screenWidth: 750,
screenHeight: 1334,
Expand All @@ -34,7 +36,8 @@ export const SupportedDevices = {
frameImage: iphoneSE,
maskImage: iphoneSEmask,
},
"Google Pixel 7": {
{
name: "Google Pixel 7",
platform: Platform.Android,
screenWidth: 1080,
screenHeight: 2400,
Expand All @@ -45,7 +48,8 @@ export const SupportedDevices = {
frameImage: pixel7,
maskImage: pixel7mask,
},
"Google Pixel 6a": {
{
name: "Google Pixel 6a",
platform: Platform.Android,
screenWidth: 1080,
screenHeight: 2400,
Expand All @@ -56,7 +60,7 @@ export const SupportedDevices = {
frameImage: pixel6a,
maskImage: pixel6amask,
},
};
] as const;

export type DeviceProperties = {
name: string;
Expand Down
22 changes: 11 additions & 11 deletions packages/vscode-extension/src/webview/views/CreateDeviceView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ import { SupportedDeviceName, SupportedDevices } from "../utilities/consts";
import { Platform } from "../../common/DeviceManager";

function isSupportedIOSDevice(device: SupportedDeviceName): boolean {
return SupportedDevices[device].platform === Platform.IOS;
return (
SupportedDevices.find((sd) => {
return sd.name === device;
})?.platform === Platform.IOS
);
}

const SUPPORTED_DEVICES = [
{
items: Object.entries(SupportedDevices)
.filter((item) => {
return item[1].platform === Platform.IOS;
})
.map((item) => ({ value: item[0], label: item[0] })),
items: SupportedDevices.filter((item) => {
return item.platform === Platform.IOS;
}).map((item) => ({ value: item.name, label: item.name })),
label: "iOS",
},
{
items: Object.entries(SupportedDevices)
.filter((item) => {
return item[1].platform === Platform.Android;
})
.map((item) => ({ value: item[0], label: item[0] })),
items: SupportedDevices.filter((item) => {
return item.platform === Platform.Android;
}).map((item) => ({ value: item.name, label: item.name })),
label: "Android",
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import CreateDeviceView from "./CreateDeviceView";
import { useDevices } from "../providers/DevicesProvider";
import { VSCodeProgressRing } from "@vscode/webview-ui-toolkit/react";
import { useState } from "react";
import { SupportedDevices } from "../utilities/consts";
import { Platform } from "../../common/DeviceManager";

function DevicesNotFoundView() {
const { openModal, closeModal } = useModal();
Expand Down Expand Up @@ -33,7 +35,12 @@ function DevicesNotFoundView() {
newestAPIImage = image;
}
}
await deviceManager.createAndroidDevice("Google Pixel 7", newestAPIImage);
await deviceManager.createAndroidDevice(
SupportedDevices.find((sd) => {
return sd.platform === Platform.Android;
})!.name,
newestAPIImage
);
} finally {
setAndroidCreating(false);
}
Expand All @@ -46,7 +53,13 @@ function DevicesNotFoundView() {
for (const runtime of iOSRuntimes) {
if (
(newestRuntime === undefined || runtime.version > newestRuntime.version) &&
runtime.supportedDeviceTypes.find((dt) => dt.name === "iPhone 15 Pro")
runtime.supportedDeviceTypes.find(
(dt) =>
dt.name ===
SupportedDevices.find((sd) => {
return sd.platform === Platform.IOS;
})?.name
)
) {
newestRuntime = runtime;
}
Expand All @@ -56,7 +69,11 @@ function DevicesNotFoundView() {
return;
}
const iOSDeviceType = newestRuntime.supportedDeviceTypes.find(
(dt) => dt.name === "iPhone 15 Pro"
(dt) =>
dt.name ===
SupportedDevices.find((sd) => {
return sd.platform === Platform.IOS;
})?.name
);
await deviceManager.createIOSDevice(iOSDeviceType!, newestRuntime);
} finally {
Expand Down

0 comments on commit ca4862c

Please sign in to comment.