1 module formoshlep.platform; 2 3 import dlangui; 4 import dlangui.platforms.common.platform; 5 6 class FormoshlepPlatform : Platform 7 { 8 import formoshlep.window; 9 import vibe.http.server; 10 11 private FormoshlepWindow window; 12 private HTTPServerSettings _httpServerSettings; 13 14 void httpServerSettings(HTTPServerSettings s) 15 { 16 _httpServerSettings = s; 17 } 18 19 void handleRequest(HTTPServerRequest req, HTTPServerResponse res) 20 { 21 import std.string : startsWith, endsWith; 22 23 string pics_path = "/res/@embedded@/"; 24 25 if (req.path.startsWith(pics_path)) 26 { 27 // TODO: check URL for aviability for current user 28 29 if(req.path.endsWith(".png")) 30 { 31 auto embedded = embeddedResourceList.find(req.path[pics_path.length .. $]); 32 33 if(embedded is null) 34 { 35 res.writeBody("Unknown resource"); 36 res.statusCode = 500; 37 } 38 else 39 res.writeBody(embedded.data, "image/png"); 40 } 41 else 42 { 43 res.writeBody("Unknown format, error 500"); 44 } 45 } 46 else if (req.path != "/") 47 { 48 res.writeBody("Unknown path"); 49 res.statusCode = 500; 50 } 51 else 52 { 53 assert(window !is null); 54 55 import formoshlep.widget; 56 57 window.mainWidget.readWidgetsState(req); 58 window.mainWidget.processEvents(req); 59 window.genHttpServerResponse(res); 60 } 61 } 62 63 override: 64 65 Window createWindow(dstring windowCaption, Window parent, uint flags, uint width, uint height) 66 { 67 assert(window is null); 68 69 window = new FormoshlepWindow(windowCaption); 70 71 return window; 72 } 73 74 void closeWindow(Window w) 75 { 76 assert(false, "Isn't implemented"); 77 } 78 79 /** 80 * Starts application message loop. 81 * 82 * When returned from this method, application is shutting down. 83 */ 84 int enterMessageLoop() 85 { 86 import vibe.core.core: runApplication; 87 88 assert(_httpServerSettings !is null); 89 90 listenHTTP(_httpServerSettings, &handleRequest); 91 runApplication(); 92 93 return 0; 94 } 95 96 bool hasClipboardText(bool mouseBuffer) 97 { 98 assert(false, "Isn't implemented"); 99 } 100 101 dstring getClipboardText(bool mouseBuffer) 102 { 103 assert(false, "Isn't implemented"); 104 } 105 106 void setClipboardText(dstring text, bool mouseBuffer) 107 { 108 assert(false, "Isn't implemented"); 109 } 110 111 void requestLayout() 112 { 113 //~ if(window !is null) 114 //~ window.requestLayout(); 115 } 116 }