Consume all pending events at once
This commit is contained in:
13
api.cpp
13
api.cpp
@@ -75,13 +75,20 @@ class Context {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasPendingEvent() {
|
bool consumeEvents() {
|
||||||
return gpp_rethrow([=]() {
|
return gpp_rethrow([=]() {
|
||||||
|
bool had_events = false;
|
||||||
|
for (;;) {
|
||||||
CameraEventType event_type = GP_EVENT_UNKNOWN;
|
CameraEventType event_type = GP_EVENT_UNKNOWN;
|
||||||
gpp_unique_ptr<void, free> event_data(GPP_CALL(
|
gpp_unique_ptr<void, free> event_data(GPP_CALL(
|
||||||
void *, gp_camera_wait_for_event(camera.get(), 0, &event_type, _,
|
void *, gp_camera_wait_for_event(camera.get(), 0, &event_type, _,
|
||||||
context.get())));
|
context.get())));
|
||||||
return event_type != GP_EVENT_TIMEOUT;
|
if (event_type == GP_EVENT_TIMEOUT) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
had_events = true;
|
||||||
|
}
|
||||||
|
return had_events;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -312,6 +319,6 @@ EMSCRIPTEN_BINDINGS(gphoto2_js_api) {
|
|||||||
.function("setConfigValue", &Context::setConfigValue)
|
.function("setConfigValue", &Context::setConfigValue)
|
||||||
.function("capturePreviewAsBlob", &Context::capturePreviewAsBlob)
|
.function("capturePreviewAsBlob", &Context::capturePreviewAsBlob)
|
||||||
.function("captureImageAsFile", &Context::captureImageAsFile)
|
.function("captureImageAsFile", &Context::captureImageAsFile)
|
||||||
.function("hasPendingEvent", &Context::hasPendingEvent)
|
.function("consumeEvents", &Context::consumeEvents)
|
||||||
.function("supportedOps", &Context::supportedOps);
|
.function("supportedOps", &Context::supportedOps);
|
||||||
}
|
}
|
||||||
|
|||||||
2
libapi.mjs.d.ts
vendored
2
libapi.mjs.d.ts
vendored
@@ -30,7 +30,7 @@ declare class Context {
|
|||||||
): Promise<undefined>;
|
): Promise<undefined>;
|
||||||
capturePreviewAsBlob(): Promise<Blob>;
|
capturePreviewAsBlob(): Promise<Blob>;
|
||||||
captureImageAsFile(): Promise<File>;
|
captureImageAsFile(): Promise<File>;
|
||||||
hasPendingEvent(): Promise<boolean>;
|
consumeEvents(): Promise<boolean>;
|
||||||
supportedOps(): SupportedOps;
|
supportedOps(): SupportedOps;
|
||||||
|
|
||||||
delete(): void;
|
delete(): void;
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ class App extends Component {
|
|||||||
context.configToJS()
|
context.configToJS()
|
||||||
);
|
);
|
||||||
if (!isDebug) {
|
if (!isDebug) {
|
||||||
|
delete config.children.actions;
|
||||||
delete config.children.other;
|
delete config.children.other;
|
||||||
}
|
}
|
||||||
this.setState({
|
this.setState({
|
||||||
@@ -83,10 +84,10 @@ class App extends Component {
|
|||||||
await new Promise(resolve =>
|
await new Promise(resolve =>
|
||||||
requestIdleCallback(resolve, { timeout: 500 })
|
requestIdleCallback(resolve, { timeout: 500 })
|
||||||
);
|
);
|
||||||
let hasPendingEvent = await this.connection.schedule(context =>
|
let hadEvents = await this.connection.schedule(context =>
|
||||||
context.hasPendingEvent()
|
context.consumeEvents()
|
||||||
);
|
);
|
||||||
if (hasPendingEvent) {
|
if (hadEvents) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user