Re-implemented wrapper in C**, added proper cmake recipe.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
65c0bfc7ea
commit
de5d65d32a
|
@ -65,10 +65,7 @@ if (WITH_MAN)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (WITH_MOZILLA)
|
if (WITH_MOZILLA)
|
||||||
install(FILES
|
add_subdirectory(browser-plugins/webextension/native-wrapper)
|
||||||
browser-plugins/webextension/native-wrapper/remwharead.json
|
|
||||||
browser-plugins/webextension/native-wrapper/remwharead_wrapper.sh
|
|
||||||
DESTINATION "${CMAKE_INSTALL_LIBDIR}/mozilla/native-messaging-hosts")
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(WITH_TESTS)
|
if(WITH_TESTS)
|
||||||
|
|
|
@ -18,7 +18,7 @@ function get_tags() // get tags from text input.
|
||||||
}
|
}
|
||||||
|
|
||||||
function onResponse(response) {
|
function onResponse(response) {
|
||||||
console.log("Received " + response);
|
console.log("Received: " + response);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onError(error) {
|
function onError(error) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"name": "remwharead",
|
"name": "remwharead",
|
||||||
"version": "0.1.1",
|
"version": "0.1.2",
|
||||||
|
|
||||||
"description": "Integrates remwharead into your Browser.",
|
"description": "Integrates remwharead into your Browser.",
|
||||||
"homepage_url": "https://schlomp.space/tastytea/remwharead",
|
"homepage_url": "https://schlomp.space/tastytea/remwharead",
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
set(MOZILLA_NMH_DIR "${CMAKE_INSTALL_LIBDIR}/mozilla/native-messaging-hosts")
|
||||||
|
|
||||||
|
add_executable(${PROJECT_NAME}_wrapper ${PROJECT_NAME}_wrapper.cpp)
|
||||||
|
|
||||||
|
install(TARGETS ${PROJECT_NAME}_wrapper DESTINATION ${MOZILLA_NMH_DIR})
|
||||||
|
install(FILES remwharead.json remwharead_wrapper.sh
|
||||||
|
DESTINATION ${MOZILLA_NMH_DIR})
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "remwharead",
|
"name": "remwharead",
|
||||||
"description": "Saves URIs of things you want to remember in a database.",
|
"description": "Saves URIs of things you want to remember in a database.",
|
||||||
"path": "/usr/lib/mozilla/native-messaging-hosts/remwharead_wrapper.sh",
|
"path": "/usr/lib/mozilla/native-messaging-hosts/remwharead_wrapper",
|
||||||
"type": "stdio",
|
"type": "stdio",
|
||||||
"allowed_extensions": [ "remwharead@tastytea.de" ]
|
"allowed_extensions": [ "remwharead@tastytea.de" ]
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,91 @@
|
||||||
|
/* This file is part of remwharead.
|
||||||
|
* Copyright © 2019 tastytea <tastytea@tastytea.de>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
|
||||||
|
using std::string;
|
||||||
|
using std::cin;
|
||||||
|
using std::cout;
|
||||||
|
using std::uint32_t;
|
||||||
|
using std::system;
|
||||||
|
|
||||||
|
const string read_input()
|
||||||
|
{
|
||||||
|
string input;
|
||||||
|
char c;
|
||||||
|
|
||||||
|
bool start = false;
|
||||||
|
while (cin.read(&c, 1).good())
|
||||||
|
{
|
||||||
|
if (!start)
|
||||||
|
{
|
||||||
|
if (c == '"')
|
||||||
|
{
|
||||||
|
start = true;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (c != '"')
|
||||||
|
{
|
||||||
|
input += c;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
|
void send_message(const string &message)
|
||||||
|
{
|
||||||
|
uint32_t length = message.length() + 2;
|
||||||
|
cout.write(reinterpret_cast<const char*>(&length), sizeof(length));
|
||||||
|
cout << '"' << message << '"';
|
||||||
|
}
|
||||||
|
|
||||||
|
int launch(const string &args)
|
||||||
|
{
|
||||||
|
const string cmd = "remwharead " + args + " 2>/dev/null";
|
||||||
|
int ret = system(cmd.c_str());
|
||||||
|
if (WIFEXITED(ret))
|
||||||
|
{
|
||||||
|
ret = WEXITSTATUS(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
const string args = read_input();
|
||||||
|
int ret = launch(args);
|
||||||
|
|
||||||
|
if (ret == 0)
|
||||||
|
{
|
||||||
|
send_message("Command successful.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
send_message("Command failed with status: " + std::to_string(ret) + '.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
Loading…
Reference in New Issue