Skip to content

Commit 8268ea3

Browse files
committed
chore(effects): async Take Screenshot backend calls
1 parent 3b315b6 commit 8268ea3

2 files changed

Lines changed: 36 additions & 18 deletions

File tree

‎src/backend/app-management/electron/window-management.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,11 +741,11 @@ function updateSplashScreenStatus(newStatus) {
741741

742742
SettingsManager.on("settings:setting-updated:OverlayInstances", createAppMenu);
743743

744-
frontendCommunicator.on("getAllDisplays", () => {
744+
frontendCommunicator.onAsync("getAllDisplays", async () => {
745745
return screenHelpers.getAllDisplays();
746746
});
747747

748-
frontendCommunicator.on("getPrimaryDisplay", () => {
748+
frontendCommunicator.onAsync("getPrimaryDisplay", async () => {
749749
return screenHelpers.getPrimaryDisplay();
750750
});
751751

‎src/backend/effects/builtin/take-screenshot.ts‎

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import type { EffectType, DiscordCustomEmbed } from "../../../types";
1+
import type {
2+
EffectType,
3+
DiscordCustomEmbed,
4+
BackendCommunicator
5+
} from "../../../types";
26

37
import { takeScreenshot } from "../../app-management/electron/screen-helpers";
48
import {
@@ -49,7 +53,9 @@ const effect: EffectType<{
4953
},
5054
optionsTemplate: `
5155
<eos-container header="Display">
52-
<dropdown-select options="displayOptions" selected="effect.displayId"></dropdown-select>
56+
<firebot-dropdown
57+
options="displayOptions"
58+
ng-model="effect.displayId" />
5359
</eos-container>
5460
5561
<screenshot-effect-options effect="effect"></screenshot-effect-options>
@@ -60,20 +66,32 @@ const effect: EffectType<{
6066
</div>
6167
</eos-container>
6268
`,
63-
optionsController: ($scope, backendCommunicator) => {
64-
const displays = backendCommunicator.fireEventSync("getAllDisplays") as Electron.Display[];
65-
const primaryDisplay = backendCommunicator.fireEventSync("getPrimaryDisplay") as Electron.Display;
66-
67-
$scope.displayOptions = displays.reduce((acc, display, i) => {
68-
const isPrimary = display.id === primaryDisplay.id;
69-
acc[display.id] = `Display ${i + 1}${isPrimary ? ` (Primary)` : ''}`;
70-
return acc;
71-
}, {});
72-
73-
if ($scope.effect.displayId == null ||
74-
$scope.displayOptions[$scope.effect.displayId] == null) {
75-
$scope.effect.displayId = displays[0].id;
76-
}
69+
optionsController: ($scope, backendCommunicator: BackendCommunicator) => {
70+
$scope.displayOptions = [];
71+
72+
$scope.refreshDisplays = async () => {
73+
const displays: Electron.Display[] = await backendCommunicator.fireEventAsync("getAllDisplays");
74+
const primaryDisplay: Electron.Display = await backendCommunicator.fireEventAsync("getPrimaryDisplay");
75+
76+
let i = 1;
77+
$scope.displayOptions = displays.map((d) => {
78+
const isPrimary = d.id === primaryDisplay.id;
79+
return {
80+
name: isPrimary
81+
? `Display ${i++} (${d.label}) (Primary)`
82+
: `Display ${i++} (${d.label})`,
83+
value: d.id
84+
};
85+
});
86+
87+
if ($scope.effect.displayId == null
88+
|| !$scope.displayOptions.some(d => d.value === $scope.effect.displayId)
89+
) {
90+
$scope.effect.displayId = displays[0].id;
91+
}
92+
};
93+
94+
$scope.refreshDisplays();
7795
},
7896
optionsValidator: (effect) => {
7997
const errors: string[] = [];

0 commit comments

Comments
 (0)