All of the files

This commit is contained in:
Kaley, Fischer 2024-01-11 17:04:31 +01:00
parent 1e21be4204
commit 6775114ea6
5 changed files with 175 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
build/

15
CMakeLists.txt Normal file
View file

@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.19)
project(RapidMenu)
set(CMAKE_CXX_STANDARD 23)
# Add the path to the source files
file(GLOB_RECURSE SOURCE_FILES "src/*.cpp")
# Add the executable target
add_executable(RapidMenu ${SOURCE_FILES})
# Find and link against the tomlplusplus library
find_package(tomlplusplus REQUIRED)
target_link_libraries(RapidMenu PRIVATE tomlplusplus::tomlplusplus)

25
Makefile Normal file
View file

@ -0,0 +1,25 @@
NAME = RapidMenu
PREFIX = /usr
all:
$(MAKE) clear
$(MAKE) release
release:
cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Debug -DLEGACY_RENDERER:BOOL=true -S . -B ./build -G Ninja
cmake --build ./build
chmod -R 777 ./build
clear:
rm -rf build
install.core:
@if [ ! -f ./build/RapidMenu ]; then echo -en "You need to run $(MAKE) all first.\n" && exit 1; fi
@echo -en "!NOTE: Please note make install does not compile RapidMenu and only installs the already built files."
mkdir -p ${PREFIX}/bin
cp -f ./build/RapidMenu ${PREFIX}/bin
chmod 755 ${PREFIX}/bin/RapidMenu
install: install.core
uninstall:

24
assets/dashboard.conf Normal file
View file

@ -0,0 +1,24 @@
[runner]
rname = "Dashboard:"
rcommand = "rofi -dmenu -p"
rtheme = "-show-icons -theme ~/.config/rofi/themes/rounded-purple-dark.rasi"
[Disk]
names = "Disk"
description = "You chose Disk."
command = "RapidMenu -c yourdiskconf.conf"
[Games]
names = "Games"
description = "You chose Games."
command = "RapidMenu -c yougameconf.conf"
[PipeWire]
names = "PipeWire"
description = "You chose PipeWire"
command = "systemctl --user restart pipestart"
[Browser]
names = "Browser"
description = "You chose floorp."
command = "floorp"

110
src/main.cpp Normal file
View file

@ -0,0 +1,110 @@
#include <iostream>
#include <fstream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <stdexcept>
#include <cpptoml.h>
using namespace std;
using namespace cpptoml;
struct Action {
string names;
string description;
string command;
Action(const string& nms = "", const string& desc = "", const string& cmd = "")
: names(nms), description(desc), command(cmd) {}
};
void from_toml(const table& t, Action& a) {
try {
a.names = *t.get_as<string>("names");
a.description = *t.get_as<string>("description");
a.command = *t.get_as<string>("command");
} catch (const parse_exception& e) {
throw std::invalid_argument("Error getting value from config:");
}
}
int main(int argc, char* argv[]) {
if (argc < 3 || argv[2][0] == '-') {
cerr << "Usage: -c <config_file>" << endl;
return 1;
}
const string configFile2 = argv[2];
try {
auto config = parse_file(configFile2);
// Create the Rofi command
setenv("LC_CTYPE", "", 1); // Unset LC_CTYPE
string namesList;
for (const auto& tableItem : *config) {
try {
// Use the `from_toml` function to convert TOML to Action
Action a;
from_toml(*tableItem.second->as_table(), a);
namesList += a.names + "\n";
} catch (const std::invalid_argument& e) {
cerr << "Error getting value from config: " << e.what() << endl;
return 1;
}
}
string rname = config->get_table("runner")->get_as<string>("rname").value_or("");
string rtheme = config->get_table("runner")->get_as<string>("rtheme").value_or("");
string rcommand = config->get_table("runner")->get_as<string>("rcommand").value_or("");
//string rofiCommand = "printf '" + namesList + "' | rofi -dmenu -p 'Dashboard: ' -show-icons -theme ~/.config/rofi/themes/rounded-purple-dark.rasi";
string rofiCommand = "printf '" + namesList + "' | " + rcommand + " '" + rname + " ' " + rtheme;
// Open a pipe to the Rofi process
FILE *rofiProcess = popen(rofiCommand.c_str(), "r");
char buffer[256];
string userChoice;
// Read user input from Rofi using getline
while (fgets(buffer, sizeof(buffer), rofiProcess)) {
userChoice += buffer;
}
// Remove newline characters from userChoice
userChoice.erase(remove_if(userChoice.begin(), userChoice.end(), [](char c) { return c == '\n'; }), userChoice.end());
for (const auto& tableItem : *config) {
try {
const auto& table = tableItem.second->as_table();
if (table->get_as<string>("names").value_or("") == userChoice) {
// Use the `from_toml` function to convert TOML to Action
Action a;
from_toml(*table, a);
int bashResult = system(a.command.c_str());
cout << a.description << endl;
// Check the return value if needed
if (bashResult != 0) {
cerr << "Error executing command: " << a.command << endl;
}
return 0;
}
} catch (const std::invalid_argument& e) {
cerr << "Error getting value from config: " << e.what() << endl;
return 1;
}
}
cout << "Invalid choice. Please enter a valid option." << endl;
} catch (const parse_exception& e) {
cerr << "Incorrect config file: " << endl;
return 1;
}
return 0;
}