Skip to content

Commit

Permalink
Start updating applications to use Oxide::Tarnish
Browse files Browse the repository at this point in the history
  • Loading branch information
Eeems committed Jul 4, 2023
1 parent f84b224 commit c1048c7
Show file tree
Hide file tree
Showing 14 changed files with 205 additions and 152 deletions.
12 changes: 5 additions & 7 deletions applications/gio/launch.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <liboxide.h>
#include <liboxide/applications.h>
#include <liboxide/tarnish.h>

#include <QProcess>
#include <QUrl>
Expand Down Expand Up @@ -65,25 +66,22 @@ class LaunchCommand : ICommand{
}
return EXIT_FAILURE;
}
auto bus = QDBusConnection::systemBus();
General api(OXIDE_SERVICE, OXIDE_SERVICE_PATH, bus);
QDBusObjectPath qpath = api.requestAPI("apps");
if(qpath.path() == "/"){
auto apps = Oxide::Tarnish::appsAPI();
if(apps == nullptr){
GIO_ERROR(url, path, "Error registering transient application", "Unable to get apps API");
return EXIT_FAILURE;
}
Apps apps(OXIDE_SERVICE, qpath.path(), bus);
auto properties = registrationToMap(reg, name);
if(properties.isEmpty()){
GIO_ERROR(url, path, "Error registering transient application", "Unable to convert application registration to QVariantMap");
return EXIT_FAILURE;
}
qpath = apps.registerApplication(properties);
QDBusObjectPath qpath = apps->registerApplication(properties);
if(qpath.path() == "/"){
GIO_ERROR(url, path, "Error registering transient application", "Failed to register" << name.toStdString().c_str());
return EXIT_FAILURE;
}
Application app(OXIDE_SERVICE, qpath.path(), bus);
Application app(OXIDE_SERVICE, qpath.path(), Oxide::Tarnish::getAPI()->connection());
app.launch().waitForFinished();
return EXIT_SUCCESS;
}
Expand Down
73 changes: 11 additions & 62 deletions applications/launcher/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <liboxide.h>
#include <liboxide/eventfilter.h>
#include <liboxide/sysobject.h>
#include <liboxide/tarnish.h>

#include "appitem.h"
#include "wifinetworklist.h"
Expand Down Expand Up @@ -72,31 +73,12 @@ class Controller : public QObject
{
networks = new WifiNetworkList();
notifications = new NotificationList();

auto bus = QDBusConnection::systemBus();
qDebug() << "Waiting for tarnish to start up";
while(!bus.interface()->registeredServiceNames().value().contains(OXIDE_SERVICE)){
struct timespec args{
.tv_sec = 1,
.tv_nsec = 0,
}, res;
nanosleep(&args, &res);
}
qDebug() << "Requesting APIs";
General api(OXIDE_SERVICE, OXIDE_SERVICE_PATH, bus);
connect(&api, &General::aboutToQuit, qApp, &QGuiApplication::quit);
auto reply = api.requestAPI("power");
reply.waitForFinished();
if(reply.isError()){
qDebug() << reply.error();
qFatal("Could not request power API");
}
auto path = ((QDBusObjectPath)reply).path();
if(path == "/"){
qDebug() << "API not available";
connect(Oxide::Tarnish::getAPI(), &General::aboutToQuit, qApp, &QGuiApplication::quit);
powerApi = Oxide::Tarnish::powerAPI();
if(powerApi == nullptr){
qFatal("Power API was not available");
}
powerApi = new Power(OXIDE_SERVICE, path, bus);
// Connect to signals
connect(powerApi, &Power::batteryLevelChanged, this, &Controller::batteryLevelChanged);
connect(powerApi, &Power::batteryStateChanged, this, &Controller::batteryStateChanged);
Expand All @@ -106,18 +88,9 @@ class Controller : public QObject
connect(powerApi, &Power::batteryAlert, this, &Controller::batteryAlert);
connect(powerApi, &Power::batteryWarning, this, &Controller::batteryWarning);
connect(powerApi, &Power::chargerWarning, this, &Controller::chargerWarning);
reply = api.requestAPI("wifi");
reply.waitForFinished();
if(reply.isError()){
qDebug() << reply.error();
qFatal("Could not request wifi API");
}
path = ((QDBusObjectPath)reply).path();
if(path == "/"){
qDebug() << "API not available";
if(wifiApi == nullptr){
qFatal("Wifi API was not available");
}
wifiApi = new Wifi(OXIDE_SERVICE, path, bus);
connect(wifiApi, &Wifi::disconnected, this, &Controller::disconnected);
connect(wifiApi, &Wifi::networkConnected, this, &Controller::networkConnected);
connect(wifiApi, &Wifi::stateChanged, this, &Controller::wifiStateChanged);
Expand All @@ -144,18 +117,10 @@ class Controller : public QObject
networkConnected(network);
}
});
reply = api.requestAPI("system");
reply.waitForFinished();
if(reply.isError()){
qDebug() << reply.error();
systemApi = Oxide::Tarnish::systemAPI();
if(systemApi == nullptr){
qFatal("Could not request system API");
}
path = ((QDBusObjectPath)reply).path();
if(path == "/"){
qDebug() << "API not available";
qFatal("System API was not available");
}
systemApi = new System(OXIDE_SERVICE, path, bus);
connect(systemApi, &System::powerOffInhibitedChanged, this, &Controller::powerOffInhibitedChanged);
connect(systemApi, &System::powerOffInhibitedChanged, [=](bool value){
qDebug() << "Power Off Inhibited:" << value;
Expand All @@ -176,32 +141,16 @@ class Controller : public QObject
}
emit powerOffInhibitedChanged(powerOffInhibited());
emit sleepInhibitedChanged(sleepInhibited());
reply = api.requestAPI("apps");
reply.waitForFinished();
if(reply.isError()){
qDebug() << reply.error();
qFatal("Could not request apps API");
}
path = ((QDBusObjectPath)reply).path();
if(path == "/"){
qDebug() << "API not available";
appsApi = Oxide::Tarnish::appsAPI();
if(appsApi == nullptr){
qFatal("Apps API was not available");
}
appsApi = new Apps(OXIDE_SERVICE, path, bus);
connect(appsApi, &Apps::applicationUnregistered, this, &Controller::unregisterApplication);
connect(appsApi, &Apps::applicationRegistered, this, &Controller::registerApplication);
reply = api.requestAPI("notification");
reply.waitForFinished();
if(reply.isError()){
qDebug() << reply.error();
qFatal("Could not request notification API");
}
path = ((QDBusObjectPath)reply).path();
if(path == "/"){
qDebug() << "API not available";
notificationApi = Oxide::Tarnish::notificationAPI();
if(notificationApi == nullptr){
qFatal("Notification API was not available");
}
notificationApi = new Notifications(OXIDE_SERVICE, path, bus);
connect(notificationApi, &Notifications::notificationAdded, this, &Controller::notificationAdded);
connect(notificationApi, &Notifications::notificationRemoved, this, &Controller::notificationRemoved);
connect(notificationApi, &Notifications::notificationChanged, this, &Controller::notificationChanged);
Expand Down
1 change: 1 addition & 0 deletions applications/launcher/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ int main(int argc, char* argv[]){
app.setApplicationName("oxide");
app.setApplicationDisplayName("Launcher");
app.installEventFilter(filter);
Tarnish::registerChild();
QQmlApplicationEngine engine;
QQmlContext* context = engine.rootContext();
Controller* controller = new Controller();
Expand Down
26 changes: 8 additions & 18 deletions applications/lockscreen/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,21 @@ class Controller : public QObject {
Controller(QObject* parent)
: QObject(parent), confirmPin() {
clockTimer = new QTimer(root);
Oxide::Tarnish::connect();
auto bus = Oxide::Tarnish::getApi()->connection();
qDebug() << "Requesting system API...";
QDBusObjectPath path = Oxide::Tarnish::requestAPI("system");
if(path.path() == "/"){
systemApi = Oxide::Tarnish::systemAPI();
if(systemApi == nullptr){
qDebug() << "Unable to get system API";
throw "";
}
systemApi = new System(OXIDE_SERVICE, path.path(), bus, this);

connect(systemApi, &System::sleepInhibitedChanged, this, &Controller::sleepInhibitedChanged);
connect(systemApi, &System::powerOffInhibitedChanged, this, &Controller::powerOffInhibitedChanged);
connect(systemApi, &System::deviceSuspending, this, &Controller::deviceSuspending);

qDebug() << "Requesting power API...";
path = Oxide::Tarnish::requestAPI("power");
if(path.path() == "/"){
powerApi = Oxide::Tarnish::powerAPI();
if(powerApi == nullptr){
qDebug() << "Unable to get power API";
throw "";
}
powerApi = new Power(OXIDE_SERVICE, path.path(), bus, this);

connect(powerApi, &Power::batteryLevelChanged, this, &Controller::batteryLevelChanged);
connect(powerApi, &Power::batteryStateChanged, this, &Controller::batteryStateChanged);
connect(powerApi, &Power::chargerStateChanged, this, &Controller::chargerStateChanged);
Expand All @@ -58,25 +51,22 @@ class Controller : public QObject {
connect(powerApi, &Power::chargerWarning, this, &Controller::chargerWarning);

qDebug() << "Requesting wifi API...";
path = Oxide::Tarnish::requestAPI("wifi");
if(path.path() == "/"){
wifiApi = Oxide::Tarnish::wifiAPI();
if(wifiApi == nullptr){
qDebug() << "Unable to get wifi API";
throw "";
}
wifiApi = new Wifi(OXIDE_SERVICE, path.path(), bus, this);

connect(wifiApi, &Wifi::disconnected, this, &Controller::disconnected);
connect(wifiApi, &Wifi::networkConnected, this, &Controller::networkConnected);
connect(wifiApi, &Wifi::stateChanged, this, &Controller::wifiStateChanged);
connect(wifiApi, &Wifi::rssiChanged, this, &Controller::wifiRssiChanged);

qDebug() << "Requesting apps API...";
path = Oxide::Tarnish::requestAPI("apps");
if(path.path() == "/"){
appsApi = Oxide::Tarnish::appsAPI();
if(appsApi == nullptr){
qDebug() << "Unable to get apps API";
throw "";
}
appsApi = new Apps(OXIDE_SERVICE, path.path(), bus, this);

QSettings settings;
if(QFile::exists(settings.fileName())){
Expand Down
2 changes: 1 addition & 1 deletion applications/lockscreen/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ using namespace Oxide::Sentry;

int main(int argc, char *argv[]){
deviceSettings.setupQtEnvironment();
Tarnish::connect();
QGuiApplication app(argc, argv);
sentry_init("decay", argv);
auto filter = new EventFilter(&app);
Expand All @@ -25,6 +24,7 @@ int main(int argc, char *argv[]){
app.setOrganizationDomain(OXIDE_SERVICE);
app.setApplicationName("decay");
app.setApplicationVersion(APP_VERSION);
Tarnish::registerChild();
Controller controller(&app);
QQmlApplicationEngine engine;
QQmlContext* context = engine.rootContext();
Expand Down
2 changes: 2 additions & 0 deletions applications/process-manager/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <ostream>
#include <fcntl.h>
#include <liboxide.h>
#include <liboxide/tarnish.h>
#include <liboxide/eventfilter.h>

#include "controller.h"
Expand All @@ -25,6 +26,7 @@ int main(int argc, char *argv[]){
app.setApplicationName("tarnish");
app.setApplicationDisplayName("Process Monitor");
app.setApplicationVersion(APP_VERSION);
Tarnish::registerChild();
EventFilter filter;
app.installEventFilter(&filter);
QQmlApplicationEngine engine;
Expand Down
30 changes: 13 additions & 17 deletions applications/screenshot-tool/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,43 +48,39 @@ int main(int argc, char *argv[]){
app.setOrganizationDomain(OXIDE_SERVICE);
app.setApplicationName("fret");
app.setApplicationVersion(APP_VERSION);
Oxide::Tarnish::connect();
auto bus = Oxide::Tarnish::getApi()->connection();
qDebug() << "Requesting system API...";
QDBusObjectPath path = Oxide::Tarnish::requestAPI("system");
if(path.path() == "/"){
Oxide::Tarnish::registerChild();
auto system = Oxide::Tarnish::systemAPI();
if(system == nullptr){
qDebug() << "Unable to get system API";
return EXIT_FAILURE;
}
System system(OXIDE_SERVICE, path.path(), bus, &app);
qDebug() << "Requesting screen API...";
path = Oxide::Tarnish::requestAPI("screen");
if(path.path() == "/"){
auto screen = Oxide::Tarnish::screenAPI();
if(screen == nullptr){
qDebug() << "Unable to get screen API";
return EXIT_FAILURE;
}
Screen screen(OXIDE_SERVICE, path.path(), bus, &app);
qDebug() << "Requesting notification API...";
path = Oxide::Tarnish::requestAPI("notification");
if(path.path() == "/"){
auto notifications = Oxide::Tarnish::notificationAPI();
if(notifications == nullptr){
qDebug() << "Unable to get notification API";
return EXIT_FAILURE;
}
Notifications notifications(OXIDE_SERVICE, path.path(), bus, &app);
qDebug() << "Connecting signal listener...";
QObject::connect(&system, &System::rightAction, [&screen, &notifications, bus, &app]{
auto bus = notifications->connection();
QObject::connect(system, &System::rightAction, [screen, notifications, bus, &app]{
qDebug() << "Taking screenshot";
auto reply = screen.screenshot();
auto reply = screen->screenshot();
reply.waitForFinished();
if(reply.isError()){
qDebug() << "Failed to take screenshot";
addNotification(&notifications, "Screenshot failed: " + reply.error().message());
addNotification(notifications, "Screenshot failed: " + reply.error().message());
return;
}
auto qPath = reply.value().path();
if(qPath == "/"){
qDebug() << "Failed to take screenshot";
addNotification(&notifications, "Screenshot failed: Unknown reason");
addNotification(notifications, "Screenshot failed: Unknown reason");
return;
}
Screenshot screenshot(OXIDE_SERVICE, qPath, bus, &app);
Expand All @@ -93,7 +89,7 @@ int main(int argc, char *argv[]){
qDebug() << "Screenshot file exists.";
QProcess::execute("/bin/bash", QStringList() << "/tmp/.screenshot" << screenshot.path());
}
addNotification(&notifications, "Screenshot taken", screenshot.path());
addNotification(notifications, "Screenshot taken", screenshot.path());
qDebug() << "Screenshot done.";
});
qDebug() << "Waiting for signals...";
Expand Down
24 changes: 5 additions & 19 deletions applications/screenshot-viewer/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <QImage>
#include <QQuickItem>
#include <liboxide.h>
#include <liboxide/tarnish.h>

#include "epframebuffer.h"

Expand All @@ -29,30 +30,16 @@ class Controller : public QObject {
Controller(QObject* parent)
: QObject(parent), settings(this), applications() {
screenshots = new ScreenshotList();
auto bus = QDBusConnection::systemBus();
qDebug() << "Waiting for tarnish to start up...";
while(!bus.interface()->registeredServiceNames().value().contains(OXIDE_SERVICE)){
struct timespec args{
.tv_sec = 1,
.tv_nsec = 0,
}, res;
nanosleep(&args, &res);
screenApi = Oxide::Tarnish::screenAPI();
if(screenApi == nullptr){
qFatal("Screen API is not available");
}
api = new General(OXIDE_SERVICE, OXIDE_SERVICE_PATH, bus, this);

qDebug() << "Requesting screen API...";
QDBusObjectPath path = api->requestAPI("screen");
if(path.path() == "/"){
qDebug() << "Unable to get screen API";
throw "";
}
screenApi = new Screen(OXIDE_SERVICE, path.path(), bus, this);
connect(screenApi, &Screen::screenshotAdded, this, &Controller::screenshotAdded);
connect(screenApi, &Screen::screenshotModified, this, &Controller::screenshotModified);
connect(screenApi, &Screen::screenshotRemoved, this, &Controller::screenshotRemoved);

for(auto path : screenApi->screenshots()){
screenshots->append(new Screenshot(OXIDE_SERVICE, path.path(), bus, this));
screenshots->append(new Screenshot(OXIDE_SERVICE, path.path(), screenApi->connection(), this));
}

settings.sync();
Expand Down Expand Up @@ -120,7 +107,6 @@ private slots:
private:
QSettings settings;
ScreenshotList* screenshots;
General* api;
Screen* screenApi;
QObject* root = nullptr;
QObject* stateControllerUI = nullptr;
Expand Down
2 changes: 2 additions & 0 deletions applications/screenshot-viewer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <cstdlib>
#include <signal.h>
#include <liboxide.h>
#include <liboxide/tarnish.h>

#include "controller.h"

Expand All @@ -29,6 +30,7 @@ int main(int argc, char *argv[]){
app.setApplicationName("anxiety");
app.setApplicationDisplayName("Screenshots");
app.setApplicationVersion(APP_VERSION);
Tarnish::registerChild();
Controller controller(&app);
QQmlApplicationEngine engine;
QQmlContext* context = engine.rootContext();
Expand Down
Loading

0 comments on commit c1048c7

Please sign in to comment.