-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[desktop]: Show error message on perform an action for a disconnected…
… device
- Loading branch information
Showing
7 changed files
with
46 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { inject, Injectable } from '@angular/core' | ||
import { DeviceListMenuComponent } from '../components/device-list-menu/device-list-menu.component' | ||
import { Device } from '../types/device.types' | ||
import { AngularService } from './angular.service' | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class DeviceService { | ||
private readonly angularService = inject(AngularService) | ||
|
||
async executeAction<T extends Device>(deviceMenu: DeviceListMenuComponent, devices: T[], action: (device: T) => void | Promise<void>, showConfirmation: boolean = true) { | ||
if (showConfirmation && (await this.angularService.confirm('Are you sure that you want to proceed?'))) { | ||
return false | ||
} | ||
|
||
if (!devices.length) { | ||
this.angularService.message('No equipment available to perform this action!', 'warn') | ||
return false | ||
} else { | ||
const device = devices.length === 1 ? devices[0] : await deviceMenu.show(devices, undefined, devices[0].type) | ||
|
||
if (device && device !== 'NONE') { | ||
if (device.connected) { | ||
await action(device) | ||
return true | ||
} else { | ||
this.angularService.message('Your equipment must be connected to perform this action', 'error') | ||
} | ||
} | ||
} | ||
|
||
return false | ||
} | ||
} |