Skip to content

Commit

Permalink
keep device used as raw type to support older scans
Browse files Browse the repository at this point in the history
  • Loading branch information
future-pirate-king committed Jan 29, 2025
1 parent 5b30ad7 commit 33b6acb
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 8 deletions.
9 changes: 8 additions & 1 deletion app/components/vnc-viewer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,14 @@ export default class VncViewerComponent extends Component<VncViewerSignature> {
}

get isTablet() {
return this.deviceUsed?.isTablet;
const isScanInProgress =
this.args.dynamicScan?.get('isBooting') ||
this.args.dynamicScan?.get('isInstalling') ||
this.args.dynamicScan?.get('isLaunching') ||
this.args.dynamicScan?.get('isHooking') ||
this.args.dynamicScan?.get('isReadyOrRunning');

return isScanInProgress && this.deviceUsed?.is_tablet;
}

get isIOSDevice() {
Expand Down
25 changes: 25 additions & 0 deletions app/models/device.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
import Model, { attr } from '@ember-data/model';

export type RawDeviceType = {
state: string;
device_identifier: string;
custom_identifier: string | null;
address: string;
is_connected: boolean;
is_active: boolean;
is_tablet: boolean;
is_reserved: boolean;
platform: number;
platform_version: string;
cpu_architecture: string;
model: string;
has_sim: boolean;
sim_network: string;
sim_phone_number: string;
has_pin_lock: boolean;
has_vpn: boolean;
vpn_package_name: string;
has_persistent_apps: boolean;
persistent_apps: unknown[];
has_vnc: boolean;
extra_capabilities: string;
};

export default class DeviceModel extends Model {
@attr('string')
declare state: string;
Expand Down
6 changes: 3 additions & 3 deletions app/models/dynamicscan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type IntlService from 'ember-intl/services/intl';
import ENUMS from 'irene/enums';
import type UserModel from './user';
import type FileModel from './file';
import type DeviceModel from './device';
import type { RawDeviceType } from './device';

export enum DsComputedStatus {
NOT_STARTED,
Expand Down Expand Up @@ -63,8 +63,8 @@ export default class DynamicscanModel extends Model {
@attr('date', { allowNull: true })
declare autoShutdownOn: Date | null;

@belongsTo('device', { async: false, inverse: null })
declare deviceUsed: DeviceModel | null;
@attr()
declare deviceUsed: RawDeviceType | null;

@attr()
declare devicePreference: unknown;
Expand Down
21 changes: 17 additions & 4 deletions tests/integration/components/vnc-viewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ module('Integration | Component | vnc-viewer', function (hooks) {
isTablet: true,
deviceClass: 'ipad black',
},
{
platform: ENUMS.PLATFORM.IOS,
isTablet: true,
deviceClass: 'iphone5s black', // since device might not be allocated so show default
status: ENUMS.DYNAMIC_SCAN_STATUS.IN_QUEUE,
},
{
platform: ENUMS.PLATFORM.ANDROID,
isTablet: false,
Expand All @@ -110,15 +116,15 @@ module('Integration | Component | vnc-viewer', function (hooks) {
deviceClass: 'iphone5s black',
},
],
async function (assert, { platform, isTablet, deviceClass }) {
async function (assert, { platform, isTablet, deviceClass, status }) {
const deviceUsed = this.server.create('device', {
is_tablet: isTablet,
platform,
});

const dynamicscan = this.server.create('dynamicscan', {
file: this.file.id,
status: ENUMS.DYNAMIC_SCAN_STATUS.READY_FOR_INTERACTION,
status: status || ENUMS.DYNAMIC_SCAN_STATUS.READY_FOR_INTERACTION,
ended_on: null,
device_used: deviceUsed.toJSON(),
});
Expand All @@ -138,12 +144,19 @@ module('Integration | Component | vnc-viewer', function (hooks) {
<VncViewer @file={{this.file}} @profileId={{this.activeProfileId}} @dynamicScan={{this.dynamicscan}} />
`);

const isScanInProgress =
this.dynamicscan.isBooting ||
this.dynamicscan.isInstalling ||
this.dynamicscan.isLaunching ||
this.dynamicscan.isHooking ||
this.dynamicscan.isReadyOrRunning;

deviceClass.split(' ').forEach((val) => {
assert.dom('[data-test-vncViewer-device]').hasClass(val);
});

['TopBar', 'Sleep', 'Volume'].forEach((it) => {
if (isTablet) {
if (isScanInProgress && isTablet) {
assert.dom(`[data-test-vncViewer-device${it}]`).exists();
} else {
assert.dom(`[data-test-vncViewer-device${it}]`).doesNotExist();
Expand All @@ -157,7 +170,7 @@ module('Integration | Component | vnc-viewer', function (hooks) {
assert.dom('[data-test-vncViewer-deviceHome]').exists();

['Speaker', 'BottomBar'].forEach((it) => {
if (isTablet) {
if (isScanInProgress && isTablet) {
assert.dom(`[data-test-vncViewer-device${it}]`).exists();
} else {
assert.dom(`[data-test-vncViewer-device${it}]`).doesNotExist();
Expand Down

0 comments on commit 33b6acb

Please sign in to comment.