Skip to content

Commit

Permalink
Merge pull request #17 from r52/widget-platform
Browse files Browse the repository at this point in the history
Platform restrictions in widget definitions
  • Loading branch information
r52 committed Mar 28, 2023
2 parents 53612e1 + ed5f596 commit 50b2e7a
Show file tree
Hide file tree
Showing 31 changed files with 162 additions and 77 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ jobs:
version: "6.4.3"
arch: ${{ matrix.arch }}
modules: qtwebengine qtpositioning qtwebchannel qtnetworkauth qtserialport
cache: "true"

- name: Set up Ninja
if: runner.os == 'Linux'
Expand All @@ -75,6 +76,7 @@ jobs:
- name: Cache vcpkg
uses: lukka/run-vcpkg@v10
with:
prependedCacheKey: ${{ matrix.builder }}
vcpkgJsonGlob: "vcpkg.json"

- name: Configure Project
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,6 @@ docs/xml/

# quasar specific
version.h

# clang
.cache/
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ Quasar is licensed under GPL-3.0. All sample widgets are licensed under the MIT

## System Requirements

An OS and computer capable of running Chrome. Only 64-bit OSes are supported. On Windows, only Windows 10 and above are supported. On Linux, only X11 desktop environments with system tray support are supported.
An OS and computer capable of running Chrome, preferably with Hardware Acceleration capabilities. Only 64-bit OSes are supported. On Windows, only Windows 10 and above are supported. On Linux, only X11 desktop environments with system tray support are supported.

While Quasar is reasonably fast and lightweight, do not expect Quasar to be power efficient, especially when running heavier widgets like the [WebGL visualizer](widgets/visualizer_webgl).

#### Note Regarding Wayland

Expand Down Expand Up @@ -87,7 +89,7 @@ cd quasar

#### Windows

The following example configures the project to build using the `clang-cl` toolkit with Visual Studio Communitry 2022 (plus the Clang MSVC toolkit) installed:
The following example configures the project to build using the `clang-cl` toolkit with Visual Studio Community 2022 (plus the Clang MSVC toolkit) installed:

```pwsh
cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE "-DCMAKE_C_COMPILER:FILEPATH=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\Llvm\x64\bin\clang-cl.exe" "-DCMAKE_CXX_COMPILER:FILEPATH=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\Llvm\x64\bin\clang-cl.exe" -S./ -B./build -G "Visual Studio 17 2022" -T ClangCL,host=x64 -A x64
Expand Down
8 changes: 6 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ Quasar is licensed under GPL-3.0. All sample widgets are licensed under the MIT
System Requirements
-------------------

An OS and computer capable of running Chrome. Only 64-bit OSes are supported. On Windows, only Windows 10 and above are supported. On Linux, only X11 desktop environments with system tray support are supported.
An OS and computer capable of running Chrome, preferably with Hardware Acceleration capabilities. Only 64-bit OSes are supported. On Windows, only Windows 10 and above are supported. On Linux, only X11 desktop environments with system tray support are supported.

While Quasar is reasonably fast and lightweight, do not expect Quasar to be power efficient, especially when running heavier widgets like the `WebGL visualizer <https://github.com/r52/quasar/tree/master/widgets/visualizer_webgl>`_.

Note Regarding Wayland
^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -114,7 +116,7 @@ Configuring the Project
Windows
^^^^^^^^^^^^^

The following example configures the project to build using the ``clang-cl`` toolkit with Visual Studio Communitry 2022 (plus the Clang MSVC toolkit) installed:
The following example configures the project to build using the ``clang-cl`` toolkit with Visual Studio Community 2022 (plus the Clang MSVC toolkit) installed:

.. code-block:: bash
Expand All @@ -132,6 +134,8 @@ The following example configures the project to build using ``g++-12``, assuming
export CXX=g++-12
cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE --install-prefix $HOME/.local/ -S./ -B./build -G "Unix Makefiles"
``-G Ninja`` can also be used provided that Ninja is installed.


Building the Project
~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion extensions/win_audio_viz/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ target_link_libraries(win_audio_viz PRIVATE quasar extension-api)
target_link_libraries(win_audio_viz PRIVATE fmt::fmt)

add_custom_command(TARGET win_audio_viz POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:win_audio_viz> $<TARGET_FILE_DIR:quasar>/extensions/
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:win_audio_viz> $<TARGET_FILE_DIR:quasar>/extensions/$<TARGET_FILE_NAME:win_audio_viz>
)

install(TARGETS win_audio_viz DESTINATION quasar/extensions)
2 changes: 1 addition & 1 deletion extensions/win_simple_perf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ target_link_libraries(win_simple_perf PRIVATE fmt::fmt)
target_link_libraries(win_simple_perf PRIVATE quasar extension-api)

add_custom_command(TARGET win_simple_perf POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:win_simple_perf> $<TARGET_FILE_DIR:quasar>/extensions/
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:win_simple_perf> $<TARGET_FILE_DIR:quasar>/extensions/$<TARGET_FILE_NAME:win_simple_perf>
)

install(TARGETS win_simple_perf DESTINATION quasar/extensions)
2 changes: 0 additions & 2 deletions quasar/extension/extension_support_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
#include <variant>
#include <vector>

#include "common/settings.h"

#include <jsoncons/json.hpp>

using SelectionOptionsVector = std::vector<std::pair<std::string, std::string>>;
Expand Down
1 change: 0 additions & 1 deletion quasar/internal/applauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "api/extension_support.hpp"
#include "common/settings.h"
#include "extension/extension.h"

#include <QDesktopServices>
#include <QFileInfo>
Expand Down
6 changes: 3 additions & 3 deletions quasar/quasar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Quasar::Quasar(QWidget* parent) : QMainWindow(parent), updateManager(new QNetwor

// Initialize late components
server = std::make_shared<Server>(config);
manager = std::make_shared<WidgetManager>(server);
manager = std::make_shared<WidgetManager>(server, config);

// Setup system tray
createTrayMenu();
Expand Down Expand Up @@ -116,7 +116,7 @@ Quasar::Quasar(QWidget* parent) : QMainWindow(parent), updateManager(new QNetwor
createDirectories();

// Load widgets
manager->LoadStartupWidgets(config);
manager->LoadStartupWidgets();

if (Settings::internal.update_check.GetValue())
{
Expand Down Expand Up @@ -312,7 +312,7 @@ void Quasar::openWidget()
QFileInfo info(fname);
Settings::internal.lastpath.SetValue(info.canonicalPath().toStdString());

manager->LoadWidget(fname.toStdString(), config, true);
manager->LoadWidget(fname.toStdString(), true);
}
}

Expand Down
26 changes: 17 additions & 9 deletions quasar/widgets/widgetdefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,28 @@

#include <optional>
#include <string>
#include <variant>
#include <vector>


struct ExtensionRequirement
{
std::string name;
std::string platform;
};

struct WidgetDefinition
{
// Widget definition schema
std::string name;
std::size_t width;
std::size_t height;
std::string startFile;
bool transparentBg;
std::optional<bool> clickable;
std::optional<bool> dataserver;
std::optional<bool> remoteAccess;
std::optional<std::vector<std::string>> required;
std::string name;
std::size_t width;
std::size_t height;
std::string startFile;
bool transparentBg;
std::optional<bool> clickable;
std::optional<bool> dataserver;
std::optional<bool> remoteAccess;
std::optional<std::vector<std::variant<std::string, ExtensionRequirement>>> required;

// Internal
std::string fullpath;
Expand Down
53 changes: 45 additions & 8 deletions quasar/widgets/widgetmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "quasarwidget.h"

#include "common/config.h"
#include "common/settings.h"
#include "common/util.h"
#include "server/server.h"
Expand All @@ -19,8 +20,17 @@
#include <jsoncons/json.hpp>
#include <spdlog/spdlog.h>

JSONCONS_N_MEMBER_TRAITS(ExtensionRequirement, 2, name, platform);
JSONCONS_N_MEMBER_TRAITS(WidgetDefinition, 5, name, width, height, startFile, transparentBg, clickable, dataserver, remoteAccess, required);

#if defined(Q_OS_WIN)
constexpr auto _ostype = "windows";
#elif defined(Q_OS_LINUX)
constexpr auto _ostype = "linux";
#else
constexpr auto _ostype = "unknown";
#endif

namespace
{
enum NetscapeCookieFormat
Expand All @@ -36,7 +46,7 @@ namespace
};
} // namespace

WidgetManager::WidgetManager(std::shared_ptr<Server> serv) : server{serv}
WidgetManager::WidgetManager(std::shared_ptr<Server> serv, std::shared_ptr<Config> cfg) : server{serv}, config{cfg}
{
auto cookiesfile = Settings::internal.cookies.GetValue();

Expand Down Expand Up @@ -96,7 +106,7 @@ WidgetManager::~WidgetManager()
widgetMap.clear();
}

bool WidgetManager::LoadWidget(const std::string& filename, std::shared_ptr<Config> config, bool userAction)
bool WidgetManager::LoadWidget(const std::string& filename, bool userAction)
{
if (filename.empty())
{
Expand Down Expand Up @@ -139,10 +149,36 @@ bool WidgetManager::LoadWidget(const std::string& filename, std::shared_ptr<Conf

for (auto p : def.required.value())
{
if (!serv->FindExtension(p))
std::string extname;

if (std::holds_alternative<std::string>(p))
{
extname = std::get<std::string>(p);
}
else if (std::holds_alternative<ExtensionRequirement>(p))
{
auto req = std::get<ExtensionRequirement>(p);

if (req.platform != "windows" && req.platform != "linux")
{
SPDLOG_WARN("Unrecognized platform requirement: {}", req.platform);
return false;
}

if (req.platform == _ostype)
{
extname = req.name;
}
else
{
continue;
}
}

if (!serv->FindExtension(extname))
{
pass = false;
failext = p;
failext = extname;
break;
}
}
Expand Down Expand Up @@ -181,7 +217,7 @@ bool WidgetManager::LoadWidget(const std::string& filename, std::shared_ptr<Conf

SPDLOG_INFO("Loading widget \"{}\" ({})", widgetName, def.fullpath);

auto widget = std::make_unique<QuasarWidget>(widgetName, def, server.lock(), shared_from_this(), config);
auto widget = std::make_unique<QuasarWidget>(widgetName, def, server.lock(), shared_from_this(), config.lock());

widget->show();

Expand Down Expand Up @@ -220,7 +256,7 @@ void WidgetManager::CloseWidget(QuasarWidget* widget)
{
assert((it->second.get()) == widget);
// Release unique_ptr ownership to allow Qt gc to kick in
it->second.release();
(void) it->second.release();
widgetMap.erase(it);
}

Expand All @@ -244,13 +280,13 @@ void WidgetManager::CloseWidget(QuasarWidget* widget)
}
}

void WidgetManager::LoadStartupWidgets(std::shared_ptr<Config> config)
void WidgetManager::LoadStartupWidgets()
{
auto loaded = getLoadedWidgetsList();

for (auto&& file : loaded)
{
LoadWidget(file, config, false);
LoadWidget(file, false);
}
}

Expand Down Expand Up @@ -301,4 +337,5 @@ void WidgetManager::saveLoadedWidgetsList(const std::vector<std::string>& list)
auto amend = fmt::format("{}", fmt::join(list, ","));

Settings::internal.loaded_widgets.SetValue(amend);
config.lock()->Save();
}
10 changes: 6 additions & 4 deletions quasar/widgets/widgetmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ class WidgetManager : public std::enable_shared_from_this<WidgetManager>
WidgetManager(const WidgetManager&) = delete;
WidgetManager& operator= (const WidgetManager&) = delete;

WidgetManager(std::shared_ptr<Server> serv);
WidgetManager(std::shared_ptr<Server> serv, std::shared_ptr<Config> cfg);
~WidgetManager();

bool LoadWidget(const std::string& filename, std::shared_ptr<Config> config, bool userAction);
bool LoadWidget(const std::string& filename, bool userAction);
void CloseWidget(QuasarWidget* widget);

void LoadStartupWidgets(std::shared_ptr<Config> config);
void LoadStartupWidgets();

std::vector<QuasarWidget*> GetWidgets();

Expand All @@ -39,8 +39,10 @@ class WidgetManager : public std::enable_shared_from_this<WidgetManager>
void saveLoadedWidgetsList(const std::vector<std::string>& list);

WidgetMapType widgetMap;
std::weak_ptr<Server> server;
WidgetChangedCallback widgetChangedCb;

std::weak_ptr<Server> server{};
std::weak_ptr<Config> config{};

mutable std::shared_mutex mutex;
};
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# win_visualizer_css
# visualizer_css

A simple CSS/JS animation based audio spectrum visualizer widget for Quasar, adapted from codepen by Akihiro Ikeda (http://codepen.io/AI428/pen/dXqvjN).

Configure widget styles using [js/options.js](js/options.js).
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
let websocket = null;
const source = "win_audio_viz/" + src;
let rate = 90; // milliseconds
const source = `${extension}/${src}`;
let rate = 10; // milliseconds

// acceptable sources
const sources = {
band: {
size: "win_audio_viz/Bands",
size: `${extension}/Bands`,
calc: function (e) {
return e.val;
},
},
fft: {
size: "win_audio_viz/FFTSize",
size: `${extension}/FFTSize`,
calc: function (e) {
return e.val / 2 + 1;
},
Expand All @@ -32,8 +32,8 @@ function subscribe() {
function initialize(dat) {
const element = `<div><i></i></div>`;

if ("win_audio_viz/settings" in dat) {
let settings = dat["win_audio_viz/settings"];
if (`${extension}/settings` in dat) {
let settings = dat[`${extension}/settings`];

settings.forEach(function (e) {
if (e.name === sources[src].size) {
Expand All @@ -51,12 +51,12 @@ function initialize(dat) {
});
}

if ("rates" in dat["win_audio_viz/metadata"]) {
let rates = dat["win_audio_viz/metadata"]["rates"];
if ("rates" in dat[`${extension}/metadata`]) {
let rates = dat[`${extension}/metadata`]["rates"];

rates.forEach(function (e) {
if (e.name === source) {
rate = Math.round(e.rate * 0.9);
rate = Math.round(e.rate * 0.0006);
}
});
}
Expand Down Expand Up @@ -88,7 +88,7 @@ function parseMsg(msg) {
return;
}

if ("win_audio_viz/settings" in data) {
if (`${extension}/settings` in data) {
initialize(data);
return;
}
Expand Down
6 changes: 6 additions & 0 deletions widgets/visualizer_css/js/options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Viz extension
// "win_audio_viz" on windows, "pulse_viz" on linux
const extension = "win_audio_viz";

// "band" or "fft"
const src = "band";

0 comments on commit 50b2e7a

Please sign in to comment.