From 7d2b1f111850e96270266dbee779cea7578ed547 Mon Sep 17 00:00:00 2001 From: Rafostar <40623528+Rafostar@users.noreply.github.com> Date: Thu, 3 Sep 2020 10:43:07 +0200 Subject: [PATCH] Add custom debug script with Gst version check --- clapper_src/app.js | 7 +++++-- clapper_src/debug.js | 33 +++++++++++++++++++++++++++++++++ clapper_src/interface.js | 7 ++++++- 3 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 clapper_src/debug.js diff --git a/clapper_src/app.js b/clapper_src/app.js index 2fc04714..8c472130 100644 --- a/clapper_src/app.js +++ b/clapper_src/app.js @@ -1,10 +1,13 @@ const { Gdk, GLib, GObject, Gtk } = imports.gi; +const Debug = imports.clapper_src.debug; const { Interface } = imports.clapper_src.interface; const { Player } = imports.clapper_src.player; const { Window } = imports.clapper_src.window; const APP_NAME = 'Clapper'; +let { debug } = Debug; + var App = GObject.registerClass({ Signals: { 'ready': { @@ -306,11 +309,11 @@ var App = GObject.registerClass({ _onPlayerWarning(self, error) { - log(error.message); + debug(error.message, 'LEVEL_WARNING'); } _onPlayerError(self, error) { - logError(error); + debug(error); } }); diff --git a/clapper_src/debug.js b/clapper_src/debug.js new file mode 100644 index 00000000..f9537f13 --- /dev/null +++ b/clapper_src/debug.js @@ -0,0 +1,33 @@ +const { GLib, Gst } = imports.gi; + +const GST_VERSION = Gst.version(); +const REQ_GST_VER_MINOR = 16; + +function debug(msg, levelName) +{ + levelName = levelName || 'LEVEL_DEBUG'; + + if(msg instanceof Error) { + levelName = 'LEVEL_CRITICAL'; + msg = msg.message; + } + GLib.log_structured( + 'Clapper', GLib.LogLevelFlags[levelName], { + MESSAGE: msg, + SYSLOG_IDENTIFIER: 'clapper' + }); +} + +function gstVersionCheck() +{ + if(GST_VERSION[1] >= REQ_GST_VER_MINOR) + return; + + debug( + 'clapper interface was designed to' + + ` work with GStreamer 1.${REQ_GST_VER_MINOR} or later.` + + ` Your version is ${GST_VERSION[0]}.${GST_VERSION[1]}.` + + ' Please update GStreamer or expect some things to be broken.', + 'LEVEL_WARNING' + ); +} diff --git a/clapper_src/interface.js b/clapper_src/interface.js index 84190840..3ed94bec 100644 --- a/clapper_src/interface.js +++ b/clapper_src/interface.js @@ -1,11 +1,16 @@ -const { GObject, Gtk, GstPlayer } = imports.gi; +const { GObject, Gtk, Gst, GstPlayer } = imports.gi; const { Controls } = imports.clapper_src.controls; +const Debug = imports.clapper_src.debug; + +let { debug } = Debug; var Interface = GObject.registerClass( class ClapperInterface extends Gtk.Grid { _init(opts) { + Debug.gstVersionCheck(); + super._init(); let defaults = {