Current section

Files

Jump to
chrobot src protocol@emulation.erl
Raw

src/protocol@emulation.erl

-module(protocol@emulation).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([encode__screen_orientation_type/1, decode__screen_orientation_type/1, encode__screen_orientation/1, decode__screen_orientation/1, encode__display_feature_orientation/1, decode__display_feature_orientation/1, encode__display_feature/1, decode__display_feature/1, encode__device_posture_type/1, decode__device_posture_type/1, encode__device_posture/1, decode__device_posture/1, encode__media_feature/1, decode__media_feature/1, clear_device_metrics_override/1, clear_geolocation_override/1, set_cpu_throttling_rate/2, set_default_background_color_override/2, set_device_metrics_override/6, set_emulated_media/3, encode__set_emulated_vision_deficiency_type/1, set_emulated_vision_deficiency/2, decode__set_emulated_vision_deficiency_type/1, set_geolocation_override/4, set_idle_override/3, clear_idle_override/1, set_script_execution_disabled/2, set_touch_emulation_enabled/3, set_timezone_override/2, set_user_agent_override/4]).
-export_type([screen_orientation/0, screen_orientation_type/0, display_feature/0, display_feature_orientation/0, device_posture/0, device_posture_type/0, media_feature/0, set_emulated_vision_deficiency_type/0]).
-type screen_orientation() :: {screen_orientation,
screen_orientation_type(),
integer()}.
-type screen_orientation_type() :: screen_orientation_type_portrait_primary |
screen_orientation_type_portrait_secondary |
screen_orientation_type_landscape_primary |
screen_orientation_type_landscape_secondary.
-type display_feature() :: {display_feature,
display_feature_orientation(),
integer(),
integer()}.
-type display_feature_orientation() :: display_feature_orientation_vertical |
display_feature_orientation_horizontal.
-type device_posture() :: {device_posture, device_posture_type()}.
-type device_posture_type() :: device_posture_type_continuous |
device_posture_type_folded.
-type media_feature() :: {media_feature, binary(), binary()}.
-type set_emulated_vision_deficiency_type() :: set_emulated_vision_deficiency_type_none |
set_emulated_vision_deficiency_type_blurred_vision |
set_emulated_vision_deficiency_type_reduced_contrast |
set_emulated_vision_deficiency_type_achromatopsia |
set_emulated_vision_deficiency_type_deuteranopia |
set_emulated_vision_deficiency_type_protanopia |
set_emulated_vision_deficiency_type_tritanopia.
-spec encode__screen_orientation_type(screen_orientation_type()) -> gleam@json:json().
encode__screen_orientation_type(Value__) ->
_pipe = case Value__ of
screen_orientation_type_portrait_primary ->
<<"portraitPrimary"/utf8>>;
screen_orientation_type_portrait_secondary ->
<<"portraitSecondary"/utf8>>;
screen_orientation_type_landscape_primary ->
<<"landscapePrimary"/utf8>>;
screen_orientation_type_landscape_secondary ->
<<"landscapeSecondary"/utf8>>
end,
gleam@json:string(_pipe).
-spec decode__screen_orientation_type(gleam@dynamic:dynamic_()) -> {ok,
screen_orientation_type()} |
{error, list(gleam@dynamic:decode_error())}.
decode__screen_orientation_type(Value__) ->
case gleam@dynamic:string(Value__) of
{ok, <<"portraitPrimary"/utf8>>} ->
{ok, screen_orientation_type_portrait_primary};
{ok, <<"portraitSecondary"/utf8>>} ->
{ok, screen_orientation_type_portrait_secondary};
{ok, <<"landscapePrimary"/utf8>>} ->
{ok, screen_orientation_type_landscape_primary};
{ok, <<"landscapeSecondary"/utf8>>} ->
{ok, screen_orientation_type_landscape_secondary};
{error, Error} ->
{error, Error};
{ok, Other} ->
{error,
[{decode_error,
<<"valid enum property"/utf8>>,
Other,
[<<"enum decoder"/utf8>>]}]}
end.
-spec encode__screen_orientation(screen_orientation()) -> gleam@json:json().
encode__screen_orientation(Value__) ->
gleam@json:object(
[{<<"type"/utf8>>,
encode__screen_orientation_type(erlang:element(2, Value__))},
{<<"angle"/utf8>>, gleam@json:int(erlang:element(3, Value__))}]
).
-spec decode__screen_orientation(gleam@dynamic:dynamic_()) -> {ok,
screen_orientation()} |
{error, list(gleam@dynamic:decode_error())}.
decode__screen_orientation(Value__) ->
gleam@result:'try'(
(gleam@dynamic:field(
<<"type"/utf8>>,
fun decode__screen_orientation_type/1
))(Value__),
fun(Type_) ->
gleam@result:'try'(
(gleam@dynamic:field(<<"angle"/utf8>>, fun gleam@dynamic:int/1))(
Value__
),
fun(Angle) -> {ok, {screen_orientation, Type_, Angle}} end
)
end
).
-spec encode__display_feature_orientation(display_feature_orientation()) -> gleam@json:json().
encode__display_feature_orientation(Value__) ->
_pipe = case Value__ of
display_feature_orientation_vertical ->
<<"vertical"/utf8>>;
display_feature_orientation_horizontal ->
<<"horizontal"/utf8>>
end,
gleam@json:string(_pipe).
-spec decode__display_feature_orientation(gleam@dynamic:dynamic_()) -> {ok,
display_feature_orientation()} |
{error, list(gleam@dynamic:decode_error())}.
decode__display_feature_orientation(Value__) ->
case gleam@dynamic:string(Value__) of
{ok, <<"vertical"/utf8>>} ->
{ok, display_feature_orientation_vertical};
{ok, <<"horizontal"/utf8>>} ->
{ok, display_feature_orientation_horizontal};
{error, Error} ->
{error, Error};
{ok, Other} ->
{error,
[{decode_error,
<<"valid enum property"/utf8>>,
Other,
[<<"enum decoder"/utf8>>]}]}
end.
-spec encode__display_feature(display_feature()) -> gleam@json:json().
encode__display_feature(Value__) ->
gleam@json:object(
[{<<"orientation"/utf8>>,
encode__display_feature_orientation(erlang:element(2, Value__))},
{<<"offset"/utf8>>, gleam@json:int(erlang:element(3, Value__))},
{<<"maskLength"/utf8>>, gleam@json:int(erlang:element(4, Value__))}]
).
-spec decode__display_feature(gleam@dynamic:dynamic_()) -> {ok,
display_feature()} |
{error, list(gleam@dynamic:decode_error())}.
decode__display_feature(Value__) ->
gleam@result:'try'(
(gleam@dynamic:field(
<<"orientation"/utf8>>,
fun decode__display_feature_orientation/1
))(Value__),
fun(Orientation) ->
gleam@result:'try'(
(gleam@dynamic:field(<<"offset"/utf8>>, fun gleam@dynamic:int/1))(
Value__
),
fun(Offset) ->
gleam@result:'try'(
(gleam@dynamic:field(
<<"maskLength"/utf8>>,
fun gleam@dynamic:int/1
))(Value__),
fun(Mask_length) ->
{ok,
{display_feature,
Orientation,
Offset,
Mask_length}}
end
)
end
)
end
).
-spec encode__device_posture_type(device_posture_type()) -> gleam@json:json().
encode__device_posture_type(Value__) ->
_pipe = case Value__ of
device_posture_type_continuous ->
<<"continuous"/utf8>>;
device_posture_type_folded ->
<<"folded"/utf8>>
end,
gleam@json:string(_pipe).
-spec decode__device_posture_type(gleam@dynamic:dynamic_()) -> {ok,
device_posture_type()} |
{error, list(gleam@dynamic:decode_error())}.
decode__device_posture_type(Value__) ->
case gleam@dynamic:string(Value__) of
{ok, <<"continuous"/utf8>>} ->
{ok, device_posture_type_continuous};
{ok, <<"folded"/utf8>>} ->
{ok, device_posture_type_folded};
{error, Error} ->
{error, Error};
{ok, Other} ->
{error,
[{decode_error,
<<"valid enum property"/utf8>>,
Other,
[<<"enum decoder"/utf8>>]}]}
end.
-spec encode__device_posture(device_posture()) -> gleam@json:json().
encode__device_posture(Value__) ->
gleam@json:object(
[{<<"type"/utf8>>,
encode__device_posture_type(erlang:element(2, Value__))}]
).
-spec decode__device_posture(gleam@dynamic:dynamic_()) -> {ok, device_posture()} |
{error, list(gleam@dynamic:decode_error())}.
decode__device_posture(Value__) ->
gleam@result:'try'(
(gleam@dynamic:field(<<"type"/utf8>>, fun decode__device_posture_type/1))(
Value__
),
fun(Type_) -> {ok, {device_posture, Type_}} end
).
-spec encode__media_feature(media_feature()) -> gleam@json:json().
encode__media_feature(Value__) ->
gleam@json:object(
[{<<"name"/utf8>>, gleam@json:string(erlang:element(2, Value__))},
{<<"value"/utf8>>, gleam@json:string(erlang:element(3, Value__))}]
).
-spec decode__media_feature(gleam@dynamic:dynamic_()) -> {ok, media_feature()} |
{error, list(gleam@dynamic:decode_error())}.
decode__media_feature(Value__) ->
gleam@result:'try'(
(gleam@dynamic:field(<<"name"/utf8>>, fun gleam@dynamic:string/1))(
Value__
),
fun(Name) ->
gleam@result:'try'(
(gleam@dynamic:field(
<<"value"/utf8>>,
fun gleam@dynamic:string/1
))(Value__),
fun(Value) -> {ok, {media_feature, Name, Value}} end
)
end
).
-spec clear_device_metrics_override(
fun((binary(), gleam@option:option(any())) -> AEKZ)
) -> AEKZ.
clear_device_metrics_override(Callback__) ->
Callback__(<<"Emulation.clearDeviceMetricsOverride"/utf8>>, none).
-spec clear_geolocation_override(
fun((binary(), gleam@option:option(any())) -> AELD)
) -> AELD.
clear_geolocation_override(Callback__) ->
Callback__(<<"Emulation.clearGeolocationOverride"/utf8>>, none).
-spec set_cpu_throttling_rate(
fun((binary(), gleam@option:option(gleam@json:json())) -> AELH),
float()
) -> AELH.
set_cpu_throttling_rate(Callback__, Rate) ->
Callback__(
<<"Emulation.setCPUThrottlingRate"/utf8>>,
{some, gleam@json:object([{<<"rate"/utf8>>, gleam@json:float(Rate)}])}
).
-spec set_default_background_color_override(
fun((binary(), gleam@option:option(gleam@json:json())) -> AELM),
gleam@option:option(protocol@dom:rgba())
) -> AELM.
set_default_background_color_override(Callback__, Color) ->
Callback__(
<<"Emulation.setDefaultBackgroundColorOverride"/utf8>>,
{some,
gleam@json:object(
begin
_pipe = [],
chrobot@internal@utils:add_optional(
_pipe,
Color,
fun(Inner_value__) ->
{<<"color"/utf8>>,
protocol@dom:encode__rgba(Inner_value__)}
end
)
end
)}
).
-spec set_device_metrics_override(
fun((binary(), gleam@option:option(gleam@json:json())) -> AELT),
integer(),
integer(),
float(),
boolean(),
gleam@option:option(screen_orientation())
) -> AELT.
set_device_metrics_override(
Callback__,
Width,
Height,
Device_scale_factor,
Mobile,
Screen_orientation
) ->
Callback__(
<<"Emulation.setDeviceMetricsOverride"/utf8>>,
{some,
gleam@json:object(
begin
_pipe = [{<<"width"/utf8>>, gleam@json:int(Width)},
{<<"height"/utf8>>, gleam@json:int(Height)},
{<<"deviceScaleFactor"/utf8>>,
gleam@json:float(Device_scale_factor)},
{<<"mobile"/utf8>>, gleam@json:bool(Mobile)}],
chrobot@internal@utils:add_optional(
_pipe,
Screen_orientation,
fun(Inner_value__) ->
{<<"screenOrientation"/utf8>>,
encode__screen_orientation(Inner_value__)}
end
)
end
)}
).
-spec set_emulated_media(
fun((binary(), gleam@option:option(gleam@json:json())) -> AEMA),
gleam@option:option(binary()),
gleam@option:option(list(media_feature()))
) -> AEMA.
set_emulated_media(Callback__, Media, Features) ->
Callback__(
<<"Emulation.setEmulatedMedia"/utf8>>,
{some,
gleam@json:object(
begin
_pipe = [],
_pipe@1 = chrobot@internal@utils:add_optional(
_pipe,
Media,
fun(Inner_value__) ->
{<<"media"/utf8>>, gleam@json:string(Inner_value__)}
end
),
chrobot@internal@utils:add_optional(
_pipe@1,
Features,
fun(Inner_value__@1) ->
{<<"features"/utf8>>,
gleam@json:array(
Inner_value__@1,
fun encode__media_feature/1
)}
end
)
end
)}
).
-spec encode__set_emulated_vision_deficiency_type(
set_emulated_vision_deficiency_type()
) -> gleam@json:json().
encode__set_emulated_vision_deficiency_type(Value__) ->
_pipe = case Value__ of
set_emulated_vision_deficiency_type_none ->
<<"none"/utf8>>;
set_emulated_vision_deficiency_type_blurred_vision ->
<<"blurredVision"/utf8>>;
set_emulated_vision_deficiency_type_reduced_contrast ->
<<"reducedContrast"/utf8>>;
set_emulated_vision_deficiency_type_achromatopsia ->
<<"achromatopsia"/utf8>>;
set_emulated_vision_deficiency_type_deuteranopia ->
<<"deuteranopia"/utf8>>;
set_emulated_vision_deficiency_type_protanopia ->
<<"protanopia"/utf8>>;
set_emulated_vision_deficiency_type_tritanopia ->
<<"tritanopia"/utf8>>
end,
gleam@json:string(_pipe).
-spec set_emulated_vision_deficiency(
fun((binary(), gleam@option:option(gleam@json:json())) -> AEML),
set_emulated_vision_deficiency_type()
) -> AEML.
set_emulated_vision_deficiency(Callback__, Type_) ->
Callback__(
<<"Emulation.setEmulatedVisionDeficiency"/utf8>>,
{some,
gleam@json:object(
[{<<"type"/utf8>>,
encode__set_emulated_vision_deficiency_type(Type_)}]
)}
).
-spec decode__set_emulated_vision_deficiency_type(gleam@dynamic:dynamic_()) -> {ok,
set_emulated_vision_deficiency_type()} |
{error, list(gleam@dynamic:decode_error())}.
decode__set_emulated_vision_deficiency_type(Value__) ->
case gleam@dynamic:string(Value__) of
{ok, <<"none"/utf8>>} ->
{ok, set_emulated_vision_deficiency_type_none};
{ok, <<"blurredVision"/utf8>>} ->
{ok, set_emulated_vision_deficiency_type_blurred_vision};
{ok, <<"reducedContrast"/utf8>>} ->
{ok, set_emulated_vision_deficiency_type_reduced_contrast};
{ok, <<"achromatopsia"/utf8>>} ->
{ok, set_emulated_vision_deficiency_type_achromatopsia};
{ok, <<"deuteranopia"/utf8>>} ->
{ok, set_emulated_vision_deficiency_type_deuteranopia};
{ok, <<"protanopia"/utf8>>} ->
{ok, set_emulated_vision_deficiency_type_protanopia};
{ok, <<"tritanopia"/utf8>>} ->
{ok, set_emulated_vision_deficiency_type_tritanopia};
{error, Error} ->
{error, Error};
{ok, Other} ->
{error,
[{decode_error,
<<"valid enum property"/utf8>>,
Other,
[<<"enum decoder"/utf8>>]}]}
end.
-spec set_geolocation_override(
fun((binary(), gleam@option:option(gleam@json:json())) -> AEOD),
gleam@option:option(float()),
gleam@option:option(float()),
gleam@option:option(float())
) -> AEOD.
set_geolocation_override(Callback__, Latitude, Longitude, Accuracy) ->
Callback__(
<<"Emulation.setGeolocationOverride"/utf8>>,
{some,
gleam@json:object(
begin
_pipe = [],
_pipe@1 = chrobot@internal@utils:add_optional(
_pipe,
Latitude,
fun(Inner_value__) ->
{<<"latitude"/utf8>>,
gleam@json:float(Inner_value__)}
end
),
_pipe@2 = chrobot@internal@utils:add_optional(
_pipe@1,
Longitude,
fun(Inner_value__@1) ->
{<<"longitude"/utf8>>,
gleam@json:float(Inner_value__@1)}
end
),
chrobot@internal@utils:add_optional(
_pipe@2,
Accuracy,
fun(Inner_value__@2) ->
{<<"accuracy"/utf8>>,
gleam@json:float(Inner_value__@2)}
end
)
end
)}
).
-spec set_idle_override(
fun((binary(), gleam@option:option(gleam@json:json())) -> AEOO),
boolean(),
boolean()
) -> AEOO.
set_idle_override(Callback__, Is_user_active, Is_screen_unlocked) ->
Callback__(
<<"Emulation.setIdleOverride"/utf8>>,
{some,
gleam@json:object(
[{<<"isUserActive"/utf8>>, gleam@json:bool(Is_user_active)},
{<<"isScreenUnlocked"/utf8>>,
gleam@json:bool(Is_screen_unlocked)}]
)}
).
-spec clear_idle_override(fun((binary(), gleam@option:option(any())) -> AEOT)) -> AEOT.
clear_idle_override(Callback__) ->
Callback__(<<"Emulation.clearIdleOverride"/utf8>>, none).
-spec set_script_execution_disabled(
fun((binary(), gleam@option:option(gleam@json:json())) -> AEOX),
boolean()
) -> AEOX.
set_script_execution_disabled(Callback__, Value) ->
Callback__(
<<"Emulation.setScriptExecutionDisabled"/utf8>>,
{some, gleam@json:object([{<<"value"/utf8>>, gleam@json:bool(Value)}])}
).
-spec set_touch_emulation_enabled(
fun((binary(), gleam@option:option(gleam@json:json())) -> AEPC),
boolean(),
gleam@option:option(integer())
) -> AEPC.
set_touch_emulation_enabled(Callback__, Enabled, Max_touch_points) ->
Callback__(
<<"Emulation.setTouchEmulationEnabled"/utf8>>,
{some,
gleam@json:object(
begin
_pipe = [{<<"enabled"/utf8>>, gleam@json:bool(Enabled)}],
chrobot@internal@utils:add_optional(
_pipe,
Max_touch_points,
fun(Inner_value__) ->
{<<"maxTouchPoints"/utf8>>,
gleam@json:int(Inner_value__)}
end
)
end
)}
).
-spec set_timezone_override(
fun((binary(), gleam@option:option(gleam@json:json())) -> AEPJ),
binary()
) -> AEPJ.
set_timezone_override(Callback__, Timezone_id) ->
Callback__(
<<"Emulation.setTimezoneOverride"/utf8>>,
{some,
gleam@json:object(
[{<<"timezoneId"/utf8>>, gleam@json:string(Timezone_id)}]
)}
).
-spec set_user_agent_override(
fun((binary(), gleam@option:option(gleam@json:json())) -> AEPO),
binary(),
gleam@option:option(binary()),
gleam@option:option(binary())
) -> AEPO.
set_user_agent_override(Callback__, User_agent, Accept_language, Platform) ->
Callback__(
<<"Emulation.setUserAgentOverride"/utf8>>,
{some,
gleam@json:object(
begin
_pipe = [{<<"userAgent"/utf8>>,
gleam@json:string(User_agent)}],
_pipe@1 = chrobot@internal@utils:add_optional(
_pipe,
Accept_language,
fun(Inner_value__) ->
{<<"acceptLanguage"/utf8>>,
gleam@json:string(Inner_value__)}
end
),
chrobot@internal@utils:add_optional(
_pipe@1,
Platform,
fun(Inner_value__@1) ->
{<<"platform"/utf8>>,
gleam@json:string(Inner_value__@1)}
end
)
end
)}
).