Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial native message iface I will develop a more complete native message interface, with json communication that will accept commands from the browser. For now though it is a simple stdin listener... * Add an easy tester The python tester allows to quickly test some changes. Extra work to be done. Pending. * Producer consumer queue, test program and json. Translation is broken The old translation method will not and I am not sure why. We need to create a new service anyways, but this is a problem for the Nick of tomorrow. * One producer thread consumes stdin and enqueues a bunch of translation requests. Lock on stdout writing via callback Early versions. Several issues. Number one is termination. Is there a way of knowing when all service work is done so that we can safely die, before we have any queued translations pending? * More progress Removed service shared pointer and put it inside the thread. Clean shutdown. Removed syncrhonisation with C style iostream. Modified the json * Firefox always calls translateLocally with two arguments: path-to-manifest.json extension-id No way to change that. So easy hack for now: if you see the extension-id as an argument, switch to nativeMessaging. * Add the length header to the output And flush, otherwise the message won't make it directly to Firefox * Add toggle for HTML I need HTML in the extension because there is no non-HTML mode anymore * Add support for langid tags and some code cleanup Wrapped one string in tr, removed unneeded headers and forward defines and used constexpr if template instead of overloaded functions * Implement initial version of model swapping and pivoting What isn't implemented is downloading a model that is not already downloaded. Pretty much eventLoop is used wrongly * On the way to the api proposed by @JelmervD Lots of refactoring, but now we have more reliable parsing of the incoming messages. Outgoing API is not implemented. I have made some modifications of what I expect and I will post my proposed edits tomorrow morning. We are also facing an issue with working in a separate thread. Any sort of QT objects's connections must be called in the same thread as the one in which they were constructed, as opposed to in a child thread. This means that we need to rethink the design so that FetchRemoteModels and DownloadModels are both callled from the main thread. * Move everything to the main thread. Listing models works. Fetching models is implemneted but some extra details needed to make it useful * `return` at the wrong level? * Fix response message structure * Somewhat more proper functionality * No termination condition, but everything is working Finalise is never called, because it will not complete any slots that are in progress. The way to do this is to probably have a second thread that keeps track on the termination condition and calls finalise() there... * First fully functional prototype. Not very well tested * Do not set `success:true` on download progress messages This makes handling TranslateLocally's responses much easier since we can keep the 1 request 1 response (with success = true or false) model in the extension. `update:true` messages can later be handled by something similar to progress reporting QFuture-like promises in the extension. * Send single object in `data` As opposed to an array of objects * Fix bug where remote model was selected when local model was available * Add a todo note * Move model matching code to ModelManager Temporarily removed the map that speeds up finding models but needs to be kept in sync with the model list. Will bring it back at some point but keep it hidden inside ModelManager's internals. I've tasted std::variant and it is now my favourite food. * (hopefully) fix compilation issue for macOS 10.15 * Revert "(hopefully) fix compilation issue for macOS 10.15" This reverts commit 9512113. It is essentially a "compiler isn't told properly that we're using C++17" issue. See https://stackoverflow.com/a/43631668 * Rewrite native_client.py example to use asyncio Necessary preparations for load testing later on, where I want to test concurrent requests like there would be from a browser extension trying to keep up with tabs loading & translating. * Simplify DownloadModel message handling * Update for changes to master * Upload timing test code as well * Catch nullptr returned from downloadFile The whole `operations_--` counter thing is very easy to mess up :( * Make progress messages more useful for a client Passing bytes instead of 0..1 so a client can show download speed and size if they want to. * Implement & test single shot connection type for signal handling * Implement model-specific translations It falls back too often to `QString id` when it already has access to a `Model`, but it has fewer separate code pathss. * Implement isSameModel through Model::id() * When includeRemote is false, don't include remote models. * Defensive work-around in test for broken model_info.json in eng-fin model. * Fill in srcTags and trgTag based on shortName if they're missing from model_info.json * Graceful shutdown of native client * Debug stuff It's a debug program. No use not having the debug print statements in there… * Make connectSingleShot also accept lambdas * Move respond logic to write* methods Also always pass along the request because it makes debugging a lot easier since you can see which request you're responding to. Moved a lot of the logic to single shot connections since ModelManager does not guarantee that every request that accepts `extradata` will also produce a signal. This also helps group all the logic to handling one request type in one place, which is nice. * Possibly fix undeclared `Args` in gcc * Attempt to fix compilation issue where QStringList (which extends QList<QString>) does not seem to have a constructor that accepts being and end iterators. * Base connectSingleShot template on the signal it connects to instead of the slot Maybe this works? Problem was in the Qt5 bit, not the Qt6 bit. * Fix macOS compilation issue by replacing `char[]` with `std::vector<char>` * Add async shutdown test In which I write requests, close stdin, and then wait to see if all responses do end up on stdout. * Simplify iothread & operation count locking a bit Basically I wanted a semaphore that blocked till it was 0. But until then this will do. * Add code to register native messaging client with Firefox on launch Maybe we should first ask though * Revert to using atomic In my limited testing, it seems to work okay even when the condition_variable does not share the same mutex as the atomic. * Fix concurrent downloads * Add comments to native messaging launch detection * Print errors to stderr * Change modelID -> id in download update message to match format in ListModels and DownloadModel success messages * Document each of the requests * Remove `die_` * Replace `shared_ptr<vector<char>>` with QByteArray * Fix windows registry path … I think * Switch stdin & stdout to binary mode on Windows * Include the right headers on Windows * Use the other slash Cause Qt [is funny like that](https://github.com/qt/qtbase/blob/a0a2bf2d95d4fcd468b6ce3c2e728d95425dd760/src/corelib/io/qsettings_win.cpp#L103-L115) * Fix call to `std::isspace` Documentation is explicit about only calling it with unsigned char, and Windows' C++ runtime is checking for that. * Move extension ids to a single place * Update README with info about native messaging * Remove superfluous `)` * Mention limitations up front So nobody gets hurt Co-authored-by: Jelmer van der Linde <[email protected]>
- Loading branch information