waver : adding snap

This commit is contained in:
Georgi Gerganov
2021-01-05 21:14:37 +02:00
parent d29bf6d0e8
commit 14f4dbc226
3 changed files with 127 additions and 12 deletions

View File

@@ -13,3 +13,5 @@ target_link_libraries(waver PRIVATE
imgui-sdl2
${CMAKE_THREAD_LIBS_INIT}
)
install(TARGETS waver RUNTIME DESTINATION bin)

View File

@@ -7,12 +7,48 @@
#include <SDL.h>
#include <SDL_opengl.h>
#include <dlfcn.h>
#include <unistd.h>
#include <fstream>
#include <vector>
#include <iterator>
namespace {
void dummy() {}
}
std::string getBinaryPath() {
std::string result;
void* p = reinterpret_cast<void*>(dummy);
Dl_info info;
dladdr(p, &info);
if (*info.dli_fname == '/') {
result = info.dli_fname;
} else {
char buff[2048];
auto len = readlink("/proc/self/exe", buff, sizeof(buff) - 1);
if (len > 0) {
buff[len] = 0;
result = buff;
}
}
auto slash = result.rfind('/');
if (slash != std::string::npos) {
result.erase(slash + 1);
}
return result;
}
std::vector<char> readFile(const char* filename) {
std::ifstream file(filename, std::ios::binary);
if (!file.is_open() || !file.good()) return {};
file.unsetf(std::ios::skipws);
std::streampos fileSize;
@@ -42,13 +78,17 @@ bool ImGui_BeginFrame(SDL_Window * window) {
if (event.type == SDL_DROPFILE) {
printf("Dropped file: '%s'\n", event.drop.file);
auto data = readFile(event.drop.file);
if (data.empty()) {
fprintf(stderr, "Unable to access file. Probably missing permissions\n");
continue;
}
std::string uri = event.drop.file;
std::string filename = event.drop.file;
if (uri.find("/") || uri.find("\\")) {
filename = uri.substr(uri.find_last_of("/\\") + 1);
}
addFile(uri.c_str(), filename.c_str(), std::move(data), true);
break;
}
}
@@ -149,7 +189,7 @@ int main(int argc, char** argv) {
return -1;
}
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0) {
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
fprintf(stderr, "Error: %s\n", SDL_GetError());
return -1;
}
@@ -175,18 +215,21 @@ int main(int argc, char** argv) {
SDL_GL_SetSwapInterval(1); // Enable vsync
ImGui_Init(window, gl_context);
ImGui::GetIO().IniFilename = nullptr;
ImGui::GetIO().Fonts->AddFontFromFileTTF((getBinaryPath() + "../../examples/assets/fonts/DroidSans.ttf").c_str(), 14.0f);
{
ImWchar ranges[] = { 0xf000, 0xf3ff, 0 };
ImFontConfig config;
config.MergeMode = true;
config.GlyphOffset = { 0.0f, 0.0f };
ImGui::GetIO().Fonts->AddFontFromFileTTF((getBinaryPath() + "../../examples/assets/fonts/fontawesome-webfont.ttf").c_str(), 14.0f, &config, ranges);
}
ImGui_SetStyle();
ImGui::GetIO().Fonts->AddFontFromFileTTF("../examples/assets/fonts/DroidSans.ttf", 14.0f);
static ImWchar ranges[] = { 0xf000, 0xf3ff, 0 };
ImFontConfig config;
config.MergeMode = true;
config.GlyphOffset = { 0.0f, 0.0f };
ImGui::GetIO().Fonts->AddFontFromFileTTF("../examples/assets/fonts/fontawesome-webfont.ttf", 14.0f, &config, ranges);
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
ImGui_NewFrame(window);

70
snap/snapcraft.yaml Normal file
View File

@@ -0,0 +1,70 @@
name: waver
version: '1.3.1'
summary: Data over sound
description: |
Waver allows you to send and receive text messages from nearby devices through sound waves.
This application can be useful for communicating with multiple nearby devices at once.
Both audible and ultrasound communication protocols are available.
The app does not connect to the internet and all information is transmitted only through sound.
In order to receive incoming messages you only need to allow access to your device's microphone so that it can record nearby sounds.
How to use:
- Before starting - make sure the speaker of your device is enabled and disconnect/unplug any headphones. The app uses your device's speaker to emit sounds when sending a text message
- To send a message - tap on "Messages", enter some text at the bottom of the screen and click "Send"
- Any nearby device that is also running this application can capture the emitted sound and display the received message
- In the settings menu, you can adjust the volume and the transmission protocol that will be used when sending messages. Make sure to adjust the volume level high enough, so the sounds can be picked up by other devices
- Tap on "Spectrum" to see a real-time frequency spectrum of the currently captured audio by your device's microphone
File sharing in a local network:
As of v1.3.0 Waver supports file sharing. It works like this:
- Add files that you would like to transmit by drag and dropping them in Waver
- In the "Files" menu, click on "Broadcast". This plays an audio message that contains a file broadcast offer
- Nearby devices in the same local network can receive this offer and initiate a TCP/IP connection to your device
- The files are transmitted over TCP/IP. The sound message is used only to initiate the network connections between the devices
- Waver allows sharing multiple files to multiple devices at once
base: core18
grade: stable
confinement: strict
parts:
alsa-mixin:
plugin: dump
source: https://github.com/diddlesnaps/snapcraft-alsa.git
source-subdir: snapcraft-assets
build-packages:
- libasound2-dev
stage-packages:
- libasound2
- libasound2-plugins
- yad
waver:
source: .
source-type: local
plugin: cmake
plugin: dump
build-packages:
- g++
- make
- libsdl2-dev
stage-packages:
- libsdl2-2.0-0
- libgl1
- libglx0
- libglu1-mesa
- libgl1-mesa-dri
after: [alsa-mixin]
apps:
waver:
command-chain: ["snap/command-chain/alsa-launch"]
command: bin/waver
plugs: [unity7, opengl, alsa, audio-playback, audio-record, network, network-bind]
environment:
ALWAYS_USE_PULSEAUDIO: '1'