Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add camera summary section #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ class Context {
});
}

val summary() {
return gpp_rethrow([=]() {
val result = val::object();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I'd probably avoid the object and just return the string, converted to val, directly.

auto summary = GPP_CALL(
CameraText, gp_camera_get_summary(camera.get(), _, context.get()));
result.set("text", static_cast<const char *>(summary.text));
return result;
});
}

val supportedOps() {
return gpp_rethrow([=]() {
auto ops =
Expand Down Expand Up @@ -350,5 +360,6 @@ EMSCRIPTEN_BINDINGS(gphoto2_js_api) {
.function("capturePreviewAsBlob", &Context::capturePreviewAsBlob)
.function("captureImageAsFile", &Context::captureImageAsFile)
.function("consumeEvents", &Context::consumeEvents)
.function("summary", &Context::summary)
.function("supportedOps", &Context::supportedOps);
}
12 changes: 11 additions & 1 deletion ui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,17 @@ class App extends Component {
'⭐ Star on Github'
)
),
h(Widget, { config: state.config, setValue: this.setValue })
h(Widget, { config: state.config, setValue: this.setValue }),
h(
'fieldset',
null,
h('legend', null, 'Camera Summary'),
h(
'pre',
{ style: 'white-space: pre-wrap' },
this.connection.summary.text
)
)
)
)
);
Expand Down
5 changes: 5 additions & 0 deletions ui/libapi.mjs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export type Config = {
| { type: 'datetime'; value: number }
);

declare interface Summary {
text: string;
}

declare interface SupportedOps {
captureImage: boolean;
captureVideo: boolean;
Expand All @@ -49,6 +53,7 @@ declare class Context {
capturePreviewAsBlob(): Promise<Blob>;
captureImageAsFile(): Promise<File>;
consumeEvents(): Promise<boolean>;
summary(): Summary;
supportedOps(): SupportedOps;

delete(): void;
Expand Down
2 changes: 2 additions & 0 deletions ui/ops.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export async function connect() {
const Module = await ModulePromise;

let context = await new Module.Context();
let summary = await context.summary();
let supportedOps = await context.supportedOps();

/** @type {Promise<unknown>} */
Expand All @@ -51,6 +52,7 @@ export async function connect() {
}

return {
summary,
supportedOps,
schedule,
disconnect() {
Expand Down