mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-12-17 00:38:59 +00:00
@@ -1,8 +1,7 @@
|
||||
const std = @import("std");
|
||||
|
||||
const server = @import("../server.zig");
|
||||
const Ctx = server.CmdContext;
|
||||
const SendFn = server.SendFn;
|
||||
const Ctx = server.Cmd;
|
||||
const result = @import("cdp.zig").result;
|
||||
const getParams = @import("cdp.zig").getParams;
|
||||
|
||||
@@ -19,7 +18,7 @@ pub fn browser(
|
||||
ctx: *Ctx,
|
||||
) ![]const u8 {
|
||||
const method = std.meta.stringToEnum(BrowserMethods, action) orelse
|
||||
return error.UnknownBrowserMethod;
|
||||
return error.UnknownMethod;
|
||||
return switch (method) {
|
||||
.getVersion => browserGetVersion(alloc, id, scanner, ctx),
|
||||
.setDownloadBehavior => browserSetDownloadBehavior(alloc, id, scanner, ctx),
|
||||
|
||||
@@ -1,11 +1,26 @@
|
||||
const std = @import("std");
|
||||
|
||||
const server = @import("../server.zig");
|
||||
const Ctx = server.CmdContext;
|
||||
const SendFn = server.SendFn;
|
||||
const Ctx = server.Cmd;
|
||||
const browser = @import("browser.zig").browser;
|
||||
const target = @import("target.zig").target;
|
||||
|
||||
pub const Error = error{
|
||||
UnknonwDomain,
|
||||
UnknownMethod,
|
||||
};
|
||||
|
||||
pub fn isCdpError(err: anyerror) ?Error {
|
||||
// see https://github.com/ziglang/zig/issues/2473
|
||||
const errors = @typeInfo(Error).ErrorSet.?;
|
||||
inline for (errors) |e| {
|
||||
if (std.mem.eql(u8, e.name, @errorName(err))) {
|
||||
return @errorCast(err);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
const Domains = enum {
|
||||
Browser,
|
||||
Target,
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
const std = @import("std");
|
||||
|
||||
const server = @import("../server.zig");
|
||||
const Ctx = server.CmdContext;
|
||||
const SendFn = server.SendFn;
|
||||
const Ctx = server.Cmd;
|
||||
const result = @import("cdp.zig").result;
|
||||
const getParams = @import("cdp.zig").getParams;
|
||||
const stringify = @import("cdp.zig").stringify;
|
||||
|
||||
const TargetMethods = enum {
|
||||
setAutoAttach,
|
||||
// attachedToTarget,
|
||||
// getTargetInfo,
|
||||
};
|
||||
|
||||
@@ -21,10 +19,10 @@ pub fn target(
|
||||
ctx: *Ctx,
|
||||
) ![]const u8 {
|
||||
const method = std.meta.stringToEnum(TargetMethods, action) orelse
|
||||
return error.UnknownTargetMethod;
|
||||
return error.UnknownMethod;
|
||||
return switch (method) {
|
||||
.setAutoAttach => tagetSetAutoAttach(alloc, id, scanner, ctx),
|
||||
// .getTargetInfo => tagetGetTargetInfo(alloc, id, scanner),
|
||||
// .getTargetInfo => tagetGetTargetInfo(alloc, id, scanner, ctx),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -63,7 +61,7 @@ fn tagetSetAutoAttach(
|
||||
} = .{},
|
||||
};
|
||||
const attached = try stringify(alloc, AttachToTarget{});
|
||||
try server.sendLater(ctx, attached, 0);
|
||||
try server.sendSync(ctx, attached);
|
||||
|
||||
return result(alloc, id, null, null);
|
||||
}
|
||||
@@ -93,28 +91,3 @@ fn tagetGetTargetInfo(
|
||||
_ = targetInfo;
|
||||
return result(alloc, id, null, null);
|
||||
}
|
||||
|
||||
// fn tagetGetTargetInfo(
|
||||
// alloc: std.mem.Allocator,
|
||||
// id: u64,
|
||||
// scanner: *std.json.Scanner,
|
||||
// ) ![]const u8 {
|
||||
// _ = scanner;
|
||||
|
||||
// const TargetInfo = struct {
|
||||
// targetId: []const u8,
|
||||
// type: []const u8,
|
||||
// title: []const u8,
|
||||
// url: []const u8,
|
||||
// attached: bool,
|
||||
// canAccessOpener: bool,
|
||||
|
||||
// browserContextId: ?[]const u8 = null,
|
||||
// };
|
||||
// const targetInfo = TargetInfo{
|
||||
// .targetId = TargetID,
|
||||
// .type = "page",
|
||||
// };
|
||||
// _ = targetInfo;
|
||||
// return result(alloc, id, null, null);
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user