1 module libwasm.bindings.Notification; 2 3 import libwasm.types; 4 5 import memutils.ct: tuple; 6 import libwasm.bindings.EventHandler; 7 import libwasm.bindings.EventTarget; 8 9 @safe: 10 nothrow: 11 12 struct GetNotificationOptions { 13 nothrow: 14 JsHandle handle; 15 alias handle this; 16 this(Handle h) { 17 this.handle = JsHandle(h); 18 } 19 static auto create() { 20 return GetNotificationOptions(libwasm_add__object()); 21 } 22 void tag()(string tag) { 23 Object_Call_string__void(this.handle, "tag", tag); 24 } 25 string tag()() { 26 return Object_Getter__string(this.handle, "tag"); 27 } 28 } 29 struct Notification { 30 nothrow: 31 libwasm.bindings.EventTarget.EventTarget _parent; 32 alias _parent this; 33 this(Handle h) { 34 _parent = .EventTarget(h); 35 } 36 void permission()(NotificationPermission permission) { 37 Object_Call_int__void(this._parent, "permission", permission); 38 } 39 NotificationPermission permission()() { 40 return Object_Getter__int(this._parent, "permission"); 41 } 42 auto requestPermission()(NotificationPermissionCallback permissionCallback) { 43 return JsPromise!(NotificationPermission)(Notification_requestPermission(this._parent, permissionCallback)); 44 } 45 auto requestPermission()() { 46 return JsPromise!(NotificationPermission)(Object_Getter__Handle(this._parent, "requestPermission")); 47 } 48 auto get()(scope ref GetNotificationOptions filter) { 49 return JsPromise!(Sequence!(Notification))(Object_Call_Handle__Handle(this._parent, "get", filter.handle)); 50 } 51 auto get()() { 52 return JsPromise!(Sequence!(Notification))(Object_Getter__Handle(this._parent, "get")); 53 } 54 void onclick(T0)(scope auto ref Optional!(T0) onclick) if (isTOrPointer!(T0, EventHandlerNonNull)) { 55 Object_Call_EventHandler__void(this._parent, "onclick", !onclick.empty, onclick.front); 56 } 57 EventHandler onclick()() { 58 return Object_Getter__EventHandler(this._parent, "onclick"); 59 } 60 void onshow(T0)(scope auto ref Optional!(T0) onshow) if (isTOrPointer!(T0, EventHandlerNonNull)) { 61 Object_Call_EventHandler__void(this._parent, "onshow", !onshow.empty, onshow.front); 62 } 63 EventHandler onshow()() { 64 return Object_Getter__EventHandler(this._parent, "onshow"); 65 } 66 void onerror(T0)(scope auto ref Optional!(T0) onerror) if (isTOrPointer!(T0, EventHandlerNonNull)) { 67 Object_Call_EventHandler__void(this._parent, "onerror", !onerror.empty, onerror.front); 68 } 69 EventHandler onerror()() { 70 return Object_Getter__EventHandler(this._parent, "onerror"); 71 } 72 void onclose(T0)(scope auto ref Optional!(T0) onclose) if (isTOrPointer!(T0, EventHandlerNonNull)) { 73 Object_Call_EventHandler__void(this._parent, "onclose", !onclose.empty, onclose.front); 74 } 75 EventHandler onclose()() { 76 return Object_Getter__EventHandler(this._parent, "onclose"); 77 } 78 string title()() { 79 return Object_Getter__string(this._parent, "title"); 80 } 81 NotificationDirection dir()() { 82 return Object_Getter__int(this._parent, "dir"); 83 } 84 Optional!(string) lang()() { 85 return Object_Getter__OptionalString(this._parent, "lang"); 86 } 87 Optional!(string) body_()() { 88 return Object_Getter__OptionalString(this._parent, "body"); 89 } 90 Optional!(string) tag()() { 91 return Object_Getter__OptionalString(this._parent, "tag"); 92 } 93 Optional!(string) icon()() { 94 return Object_Getter__OptionalString(this._parent, "icon"); 95 } 96 bool requireInteraction()() { 97 return Object_Getter__bool(this._parent, "requireInteraction"); 98 } 99 auto data()() { 100 return Any(Object_Getter__Handle(this._parent, "data")); 101 } 102 void close()() { 103 Object_Call__void(this._parent, "close"); 104 } 105 } 106 struct NotificationBehavior { 107 nothrow: 108 JsHandle handle; 109 alias handle this; 110 this(Handle h) { 111 this.handle = JsHandle(h); 112 } 113 static auto create() { 114 return NotificationBehavior(libwasm_add__object()); 115 } 116 void noscreen()(bool noscreen) { 117 Object_Call_bool__void(this.handle, "noscreen", noscreen); 118 } 119 bool noscreen()() { 120 return Object_Getter__bool(this.handle, "noscreen"); 121 } 122 void noclear()(bool noclear) { 123 Object_Call_bool__void(this.handle, "noclear", noclear); 124 } 125 bool noclear()() { 126 return Object_Getter__bool(this.handle, "noclear"); 127 } 128 void showOnlyOnce()(bool showOnlyOnce) { 129 Object_Call_bool__void(this.handle, "showOnlyOnce", showOnlyOnce); 130 } 131 bool showOnlyOnce()() { 132 return Object_Getter__bool(this.handle, "showOnlyOnce"); 133 } 134 void soundFile()(string soundFile) { 135 Object_Call_string__void(this.handle, "soundFile", soundFile); 136 } 137 string soundFile()() { 138 return Object_Getter__string(this.handle, "soundFile"); 139 } 140 void vibrationPattern()(scope ref Sequence!(uint) vibrationPattern) { 141 Object_Call_Handle__void(this.handle, "vibrationPattern", vibrationPattern.handle); 142 } 143 auto vibrationPattern()() { 144 return Sequence!(uint)(Object_Getter__Handle(this.handle, "vibrationPattern")); 145 } 146 } 147 enum NotificationDirection { 148 auto_, 149 ltr, 150 rtl 151 } 152 struct NotificationOptions { 153 nothrow: 154 JsHandle handle; 155 alias handle this; 156 this(Handle h) { 157 this.handle = JsHandle(h); 158 } 159 static auto create() { 160 return NotificationOptions(libwasm_add__object()); 161 } 162 void dir()(NotificationDirection dir) { 163 Object_Call_int__void(this.handle, "dir", dir); 164 } 165 NotificationDirection dir()() { 166 return Object_Getter__int(this.handle, "dir"); 167 } 168 void lang()(string lang) { 169 Object_Call_string__void(this.handle, "lang", lang); 170 } 171 string lang()() { 172 return Object_Getter__string(this.handle, "lang"); 173 } 174 void body_()(string body_) { 175 Object_Call_string__void(this.handle, "body", body_); 176 } 177 string body_()() { 178 return Object_Getter__string(this.handle, "body"); 179 } 180 void tag()(string tag) { 181 Object_Call_string__void(this.handle, "tag", tag); 182 } 183 string tag()() { 184 return Object_Getter__string(this.handle, "tag"); 185 } 186 void icon()(string icon) { 187 Object_Call_string__void(this.handle, "icon", icon); 188 } 189 string icon()() { 190 return Object_Getter__string(this.handle, "icon"); 191 } 192 void requireInteraction()(bool requireInteraction) { 193 Object_Call_bool__void(this.handle, "requireInteraction", requireInteraction); 194 } 195 bool requireInteraction()() { 196 return Object_Getter__bool(this.handle, "requireInteraction"); 197 } 198 void data(T0)(scope auto ref T0 data) { 199 import std.traits : isNumeric, isFloatingPoint, isSomeString; 200 if (isSomeString!T0) { 201 Object_Call_string__void(this.handle, "data", cast(string) data); 202 return; 203 } else if (isNumeric!T0 && !isFloatingPoint!T0) { 204 Object_Call_long__void(this.handle, "data", cast(long) data); 205 return; 206 } else if (isFloatingPoint!T0) { 207 Object_Call_double__void(this.handle, "data", cast(double) data); 208 return; 209 } 210 // Any 211 Handle _handle_data = getOrCreateHandle(data); 212 Object_Call_Handle__void(this.handle, "data", _handle_data); 213 dropHandle!(T0)(_handle_data); 214 } 215 auto data()() { 216 return Any(Object_Getter__Handle(this.handle, "data")); 217 } 218 void mozbehavior()(scope ref NotificationBehavior mozbehavior) { 219 Object_Call_Handle__void(this.handle, "mozbehavior", mozbehavior.handle); 220 } 221 auto mozbehavior()() { 222 return NotificationBehavior(Object_Getter__Handle(this.handle, "mozbehavior")); 223 } 224 } 225 enum NotificationPermission { 226 default_, 227 denied, 228 granted 229 } 230 alias NotificationPermissionCallback = void delegate(NotificationPermission); 231 232 233 extern (C) Handle Notification_requestPermission(Handle, NotificationPermissionCallback);