Use "const" where possible

Increase readability by using "const" for identifiers that will not be reassigned
This commit is contained in:
Rafostar
2021-01-05 20:13:53 +01:00
parent f6601766f1
commit 3452990c28
21 changed files with 320 additions and 321 deletions

View File

@@ -4,7 +4,7 @@ const { HeaderBar } = imports.clapper_src.headerbar;
const { Widget } = imports.clapper_src.widget;
const Debug = imports.clapper_src.debug;
let { debug } = Debug;
const { debug } = Debug;
var App = GObject.registerClass(
class ClapperApp extends AppBase
@@ -27,13 +27,13 @@ class ClapperApp extends AppBase
this.active_window.isClapperApp = true;
this.active_window.add_css_class('nobackground');
let clapperWidget = new Widget();
const clapperWidget = new Widget();
this.active_window.set_child(clapperWidget);
let headerBar = new HeaderBar(this.active_window);
const headerBar = new HeaderBar(this.active_window);
this.active_window.set_titlebar(headerBar);
let size = clapperWidget.windowSize;
const size = clapperWidget.windowSize;
this.active_window.set_default_size(size[0], size[1]);
debug(`restored window size: ${size[0]}x${size[1]}`);
}
@@ -62,7 +62,7 @@ class ClapperApp extends AppBase
if(!this.playlist.length)
return;
let { player } = window.get_child();
const { player } = window.get_child();
player.set_playlist(this.playlist);
}
});

View File

@@ -3,8 +3,8 @@ const Debug = imports.clapper_src.debug;
const Menu = imports.clapper_src.menu;
const Misc = imports.clapper_src.misc;
let { debug } = Debug;
let { settings } = Misc;
const { debug } = Debug;
const { settings } = Misc;
var AppBase = GObject.registerClass(
class ClapperAppBase extends Gtk.Application
@@ -22,7 +22,7 @@ class ClapperAppBase extends Gtk.Application
{
super.vfunc_startup();
let window = new Gtk.ApplicationWindow({
const window = new Gtk.ApplicationWindow({
application: this,
title: Misc.appName,
});
@@ -37,7 +37,7 @@ class ClapperAppBase extends Gtk.Application
window.add_css_class('brightscale');
for(let action in Menu.actions) {
let simpleAction = new Gio.SimpleAction({
const simpleAction = new Gio.SimpleAction({
name: action
});
simpleAction.connect(
@@ -66,7 +66,7 @@ class ClapperAppBase extends Gtk.Application
_onFirstActivate()
{
let gtkSettings = Gtk.Settings.get_default();
const gtkSettings = Gtk.Settings.get_default();
settings.bind(
'dark-theme', gtkSettings,
'gtk-application-prefer-dark-theme',

View File

@@ -10,10 +10,10 @@ class ClapperAppRemote extends AppBase
{
super.vfunc_startup();
let clapperWidget = new WidgetRemote();
const clapperWidget = new WidgetRemote();
this.active_window.set_child(clapperWidget);
let headerBar = new HeaderBarBase(this.active_window);
const headerBar = new HeaderBarBase(this.active_window);
this.active_window.set_titlebar(headerBar);
this.active_window.maximize();

View File

@@ -7,7 +7,7 @@ class ClapperCustomButton extends Gtk.Button
{
opts = opts || {};
let defaults = {
const defaults = {
margin_top: 4,
margin_bottom: 4,
margin_start: 2,
@@ -70,7 +70,7 @@ class ClapperCustomButton extends Gtk.Button
if(!this.isFullscreen)
return;
let { player } = this.get_ancestor(Gtk.Grid);
const { player } = this.get_ancestor(Gtk.Grid);
player._setHideControlsTimeout();
}
});
@@ -174,11 +174,11 @@ class ClapperPopoverButton extends IconButton
this.popover.set_offset(0, -this.margin_top);
let cssClass = 'osd';
const cssClass = 'osd';
if(isFullscreen === this.popover.has_css_class(cssClass))
return;
let action = (isFullscreen) ? 'add' : 'remove';
const action = (isFullscreen) ? 'add' : 'remove';
this.popover[action + '_css_class'](cssClass);
}
@@ -192,7 +192,7 @@ class ClapperPopoverButton extends IconButton
_onClosed()
{
let { player } = this.get_ancestor(Gtk.Grid);
const { player } = this.get_ancestor(Gtk.Grid);
player.widget.grab_focus();
this.unset_state_flags(Gtk.StateFlags.CHECKED);

View File

@@ -7,8 +7,8 @@ const Revealers = imports.clapper_src.revealers;
const CONTROLS_MARGIN = 2;
const CONTROLS_SPACING = 0;
let { debug } = Debug;
let { settings } = Misc;
const { debug } = Debug;
const { settings } = Misc;
var Controls = GObject.registerClass(
class ClapperControls extends Gtk.Box
@@ -37,7 +37,7 @@ class ClapperControls extends Gtk.Box
this._addTogglePlayButton();
let elapsedRevealer = new Revealers.ButtonsRevealer('SLIDE_RIGHT');
const elapsedRevealer = new Revealers.ButtonsRevealer('SLIDE_RIGHT');
this.elapsedButton = this.addLabelButton('00:00/00:00', elapsedRevealer);
elapsedRevealer.set_reveal_child(true);
this.revealersArr.push(elapsedRevealer);
@@ -45,14 +45,16 @@ class ClapperControls extends Gtk.Box
this._addPositionScale();
let revealTracksButton = new Buttons.IconToggleButton(
const revealTracksButton = new Buttons.IconToggleButton(
'go-previous-symbolic',
'go-next-symbolic'
);
revealTracksButton.floatUnaffected = false;
revealTracksButton.add_css_class('narrowbutton');
this.buttonsArr.push(revealTracksButton);
let tracksRevealer = new Revealers.ButtonsRevealer('SLIDE_LEFT', revealTracksButton);
const tracksRevealer = new Revealers.ButtonsRevealer(
'SLIDE_LEFT', revealTracksButton
);
this.visualizationsButton = this.addPopoverButton(
'display-projector-symbolic',
tracksRevealer
@@ -96,7 +98,7 @@ class ClapperControls extends Gtk.Box
this.unfloatButton.connect('clicked', this._onUnfloatClicked.bind(this));
this.unfloatButton.set_visible(false);
let keyController = new Gtk.EventControllerKey();
const keyController = new Gtk.EventControllerKey();
keyController.connect('key-pressed', this._onControlsKeyPressed.bind(this));
keyController.connect('key-released', this._onControlsKeyReleased.bind(this));
this.add_controller(keyController);
@@ -137,7 +139,7 @@ class ClapperControls extends Gtk.Box
{
value = value || 0;
let elapsed = Misc.getFormattedTime(value, this.showHours)
const elapsed = Misc.getFormattedTime(value, this.showHours)
+ '/' + this.durationFormatted;
this.elapsedButton.set_label(elapsed);
@@ -145,7 +147,7 @@ class ClapperControls extends Gtk.Box
addButton(buttonIcon, revealer)
{
let button = (buttonIcon instanceof Gtk.Button)
const button = (buttonIcon instanceof Gtk.Button)
? buttonIcon
: new Buttons.IconButton(buttonIcon);
@@ -162,14 +164,14 @@ class ClapperControls extends Gtk.Box
addLabelButton(text, revealer)
{
text = text || '';
let button = new Buttons.LabelButton(text);
const button = new Buttons.LabelButton(text);
return this.addButton(button, revealer);
}
addPopoverButton(iconName, revealer)
{
let button = new Buttons.PopoverButton(iconName);
const button = new Buttons.PopoverButton(iconName);
return this.addButton(button, revealer);
}
@@ -189,7 +191,7 @@ class ClapperControls extends Gtk.Box
continue;
}
let el = array[i];
const el = array[i];
let checkButton;
if(child) {
@@ -230,7 +232,7 @@ class ClapperControls extends Gtk.Box
_handleTrackChange(checkButton)
{
let clapperWidget = this.get_ancestor(Gtk.Grid);
const clapperWidget = this.get_ancestor(Gtk.Grid);
/* Reenabling audio is slow (as expected),
* so it is better to toggle mute instead */
@@ -255,7 +257,7 @@ class ClapperControls extends Gtk.Box
](false);
}
let setTrack = `set_${checkButton.type}_track`;
const setTrack = `set_${checkButton.type}_track`;
clapperWidget.player[setTrack](checkButton.activeId);
clapperWidget.player[`${setTrack}_enabled`](true);
@@ -266,8 +268,8 @@ class ClapperControls extends Gtk.Box
_handleVisualizationChange(checkButton)
{
let clapperWidget = this.get_ancestor(Gtk.Grid);
let isEnabled = clapperWidget.player.get_visualization_enabled();
const clapperWidget = this.get_ancestor(Gtk.Grid);
const isEnabled = clapperWidget.player.get_visualization_enabled();
if(!checkButton.activeId) {
if(isEnabled) {
@@ -277,7 +279,7 @@ class ClapperControls extends Gtk.Box
return;
}
let currVis = clapperWidget.player.get_current_visualization();
const currVis = clapperWidget.player.get_current_visualization();
if(currVis === checkButton.activeId)
return;
@@ -315,7 +317,7 @@ class ClapperControls extends Gtk.Box
can_focus: false,
visible: false,
});
let scrollController = new Gtk.EventControllerScroll();
const scrollController = new Gtk.EventControllerScroll();
scrollController.set_flags(Gtk.EventControllerScrollFlags.BOTH_AXES);
scrollController.connect('scroll', this._onPositionScaleScroll.bind(this));
this.positionScale.add_controller(scrollController);
@@ -336,7 +338,7 @@ class ClapperControls extends Gtk.Box
this.positionAdjustment.set_page_increment(0);
this.positionAdjustment.set_step_increment(8);
let box = new Gtk.Box({
const box = new Gtk.Box({
orientation: Gtk.Orientation.HORIZONTAL,
hexpand: true,
valign: Gtk.Align.CENTER,
@@ -366,7 +368,7 @@ class ClapperControls extends Gtk.Box
this.volumeAdjustment.set_page_increment(0.05);
for(let i of [0, 1, Misc.maxVolume]) {
let text = (!i) ? '0%' : (i % 1 === 0) ? `${i}00%` : `${i * 10}0%`;
const text = (!i) ? '0%' : (i % 1 === 0) ? `${i}00%` : `${i * 10}0%`;
this.volumeScale.add_mark(i, Gtk.PositionType.LEFT, text);
}
@@ -378,7 +380,7 @@ class ClapperControls extends Gtk.Box
_updateVolumeButtonIcon(volume)
{
let icon = (volume <= 0)
const icon = (volume <= 0)
? 'muted'
: (volume <= 0.3)
? 'low'
@@ -388,7 +390,7 @@ class ClapperControls extends Gtk.Box
? 'high'
: 'overamplified';
let iconName = `audio-volume-${icon}-symbolic`;
const iconName = `audio-volume-${icon}-symbolic`;
if(this.volumeButton.icon_name === iconName)
return;
@@ -401,8 +403,8 @@ class ClapperControls extends Gtk.Box
this.disconnect(this.realizeSignal);
this.realizeSignal = null;
let { player } = this.get_ancestor(Gtk.Grid);
let scrollController = new Gtk.EventControllerScroll();
const { player } = this.get_ancestor(Gtk.Grid);
const scrollController = new Gtk.EventControllerScroll();
scrollController.set_flags(
Gtk.EventControllerScrollFlags.VERTICAL
| Gtk.EventControllerScrollFlags.DISCRETE
@@ -410,7 +412,7 @@ class ClapperControls extends Gtk.Box
scrollController.connect('scroll', player._onScroll.bind(player));
this.volumeButton.add_controller(scrollController);
let initialVolume = (settings.get_string('volume-initial') === 'custom')
const initialVolume = (settings.get_string('volume-initial') === 'custom')
? settings.get_int('volume-value') / 100
: Misc.getCubicValue(settings.get_double('volume-last'));
@@ -420,7 +422,7 @@ class ClapperControls extends Gtk.Box
_onPlayerResize(widget, width, height)
{
let isMobile = (width < 560);
const isMobile = (width < 560);
if(this.isMobile === isMobile)
return;
@@ -433,13 +435,13 @@ class ClapperControls extends Gtk.Box
_onUnfullscreenClicked(button)
{
let root = button.get_root();
const root = button.get_root();
root.unfullscreen();
}
_onUnfloatClicked(button)
{
let clapperWidget = this.get_ancestor(Gtk.Grid);
const clapperWidget = this.get_ancestor(Gtk.Grid);
clapperWidget.setFloatingMode(false);
}
@@ -465,19 +467,19 @@ class ClapperControls extends Gtk.Box
_onTogglePlayClicked()
{
/* Parent of controls changes, so get ancestor instead */
let { player } = this.get_ancestor(Gtk.Grid);
const { player } = this.get_ancestor(Gtk.Grid);
player.toggle_play();
}
_onPositionScaleScroll(controller, dx, dy)
{
let { player } = this.get_ancestor(Gtk.Grid);
const { player } = this.get_ancestor(Gtk.Grid);
player._onScroll(controller, dx || dy, 0);
}
_onPositionScaleValueChanged(scale)
{
let positionSeconds = Math.round(scale.get_value());
const positionSeconds = Math.round(scale.get_value());
this.currentPosition = positionSeconds;
this.updateElapsedLabel(positionSeconds);
@@ -485,16 +487,16 @@ class ClapperControls extends Gtk.Box
_onVolumeScaleValueChanged(scale)
{
let volume = scale.get_value();
let linearVolume = Misc.getLinearValue(volume);
let { player } = this.get_ancestor(Gtk.Grid);
const volume = scale.get_value();
const linearVolume = Misc.getLinearValue(volume);
const { player } = this.get_ancestor(Gtk.Grid);
player.set_volume(linearVolume);
/* FIXME: All of below should be placed in 'volume-changed'
* event once we move to message bus API */
let cssClass = 'overamp';
let hasOveramp = (scale.has_css_class(cssClass));
const cssClass = 'overamp';
const hasOveramp = (scale.has_css_class(cssClass));
if(volume > 1) {
if(!hasOveramp)
@@ -510,22 +512,22 @@ class ClapperControls extends Gtk.Box
_onPositionScaleDragging(scale)
{
let isPositionDragging = scale.has_css_class('dragging');
const isPositionDragging = scale.has_css_class('dragging');
if((this.isPositionDragging = isPositionDragging))
return;
let clapperWidget = this.get_ancestor(Gtk.Grid);
const clapperWidget = this.get_ancestor(Gtk.Grid);
if(!clapperWidget) return;
let positionSeconds = Math.round(scale.get_value());
const positionSeconds = Math.round(scale.get_value());
clapperWidget.player.seek_seconds(positionSeconds);
}
/* Only happens when navigating through controls panel */
_onControlsKeyPressed(controller, keyval, keycode, state)
{
let { player } = this.get_ancestor(Gtk.Grid);
const { player } = this.get_ancestor(Gtk.Grid);
player._setHideControlsTimeout();
}
@@ -539,7 +541,7 @@ class ClapperControls extends Gtk.Box
case Gdk.KEY_Left:
break;
default:
let { player } = this.get_ancestor(Gtk.Grid);
const { player } = this.get_ancestor(Gtk.Grid);
player._onWidgetKeyReleased(controller, keyval, keycode, state);
break;
}

View File

@@ -1,14 +1,14 @@
const { Gio, GLib, GObject } = imports.gi;
const Debug = imports.clapper_src.debug;
let { debug } = Debug;
const { debug } = Debug;
var Daemon = GObject.registerClass(
class ClapperDaemon extends Gio.SubprocessLauncher
{
_init()
{
let port = ARGV[0] || 8080;
const port = ARGV[0] || 8080;
/* FIXME: show output when debugging is on */
const flags = Gio.SubprocessFlags.STDOUT_SILENCE

View File

@@ -4,7 +4,7 @@ const Misc = imports.clapper_src.misc;
const Prefs = imports.clapper_src.prefs;
const PrefsBase = imports.clapper_src.prefsBase;
let { debug } = Debug;
const { debug } = Debug;
var FileChooser = GObject.registerClass(
class ClapperFileChooser extends Gtk.FileChooserNative
@@ -17,7 +17,7 @@ class ClapperFileChooser extends Gtk.FileChooserNative
select_multiple: true,
});
let filter = new Gtk.FileFilter({
const filter = new Gtk.FileFilter({
name: 'Media Files',
});
filter.add_mime_type('video/*');
@@ -44,16 +44,16 @@ class ClapperFileChooser extends Gtk.FileChooserNative
this.responseSignal = null;
if(response === Gtk.ResponseType.ACCEPT) {
let index = 0;
let files = this.get_files();
const files = this.get_files();
const playlist = [];
let index = 0;
let file;
let subs;
let playlist = [];
while((file = files.get_item(index))) {
let filename = file.get_basename();
let [type, isUncertain] = Gio.content_type_guess(filename, null);
const filename = file.get_basename();
const [type, isUncertain] = Gio.content_type_guess(filename, null);
if(this.subsMimes.includes(type)) {
subs = file;
@@ -66,7 +66,7 @@ class ClapperFileChooser extends Gtk.FileChooserNative
index++;
}
let { player } = this.get_transient_for().get_child();
const { player } = this.get_transient_for().get_child();
if(playlist.length)
player.set_playlist(playlist);
@@ -94,14 +94,14 @@ class ClapperUriDialog extends Gtk.Dialog
default_width: 460,
});
let box = new Gtk.Box({
const box = new Gtk.Box({
orientation: Gtk.Orientation.HORIZONTAL,
valign: Gtk.Align.CENTER,
spacing: 6,
});
box.add_css_class('uridialogbox');
let linkEntry = new Gtk.Entry({
const linkEntry = new Gtk.Entry({
activates_default: true,
truncate_multiline: true,
width_request: 220,
@@ -112,7 +112,7 @@ class ClapperUriDialog extends Gtk.Dialog
linkEntry.connect('notify::text', this._onTextNotify.bind(this));
box.append(linkEntry);
let openButton = new Gtk.Button({
const openButton = new Gtk.Button({
label: "Open",
halign: Gtk.Align.END,
sensitive: false,
@@ -120,7 +120,7 @@ class ClapperUriDialog extends Gtk.Dialog
openButton.connect('clicked', this._onOpenButtonClicked.bind(this));
box.append(openButton);
let area = this.get_content_area();
const area = this.get_content_area();
area.append(box);
this.closeSignal = this.connect('close-request', this._onCloseRequest.bind(this));
@@ -131,7 +131,7 @@ class ClapperUriDialog extends Gtk.Dialog
openUri(uri)
{
let { player } = this.get_transient_for().get_child();
const { player } = this.get_transient_for().get_child();
player.set_playlist([uri]);
this.close();
@@ -139,17 +139,17 @@ class ClapperUriDialog extends Gtk.Dialog
_onTextNotify(entry)
{
let isUriValid = (entry.text.length)
const isUriValid = (entry.text.length)
? Gst.uri_is_valid(entry.text)
: false;
let button = entry.get_next_sibling();
const button = entry.get_next_sibling();
button.set_sensitive(isUriValid);
}
_onOpenButtonClicked(button)
{
let entry = button.get_prev_sibling();
const entry = button.get_prev_sibling();
this.openUri(entry.text);
}
@@ -176,7 +176,7 @@ class ClapperPrefsDialog extends Gtk.Dialog
default_height: 400,
});
let pages = [
const pages = [
{
title: 'Player',
pages: [
@@ -217,10 +217,10 @@ class ClapperPrefsDialog extends Gtk.Dialog
}
];
let prefsNotebook = new PrefsBase.Notebook(pages);
const prefsNotebook = new PrefsBase.Notebook(pages);
prefsNotebook.add_css_class('prefsnotebook');
let area = this.get_content_area();
const area = this.get_content_area();
area.append(prefsNotebook);
this.closeSignal = this.connect('close-request', this._onCloseRequest.bind(this));
@@ -236,8 +236,8 @@ class ClapperPrefsDialog extends Gtk.Dialog
dialog.disconnect(this.closeSignal);
this.closeSignal = null;
let area = dialog.get_content_area();
let notebook = area.get_first_child();
const area = dialog.get_content_area();
const notebook = area.get_first_child();
notebook._onClose();
}
});
@@ -247,15 +247,15 @@ class ClapperAboutDialog extends Gtk.AboutDialog
{
_init(window)
{
let gstVer = [
const gstVer = [
Gst.VERSION_MAJOR, Gst.VERSION_MINOR, Gst.VERSION_MICRO
].join('.');
let gtkVer = [
const gtkVer = [
Gtk.MAJOR_VERSION, Gtk.MINOR_VERSION, Gtk.MICRO_VERSION
].join('.');
let osInfo = [
const osInfo = [
'GTK version' + ': ' + gtkVer,
'GStreamer version' + ': ' + gstVer
].join('\n');

View File

@@ -8,7 +8,7 @@ class ClapperHeaderBar extends HeaderBarBase
{
super._init(window);
let clapperWidget = window.get_child();
const clapperWidget = window.get_child();
clapperWidget.controls.unfloatButton.bind_property('visible', this, 'visible',
GObject.BindingFlags.INVERT_BOOLEAN
);
@@ -16,13 +16,13 @@ class ClapperHeaderBar extends HeaderBarBase
_onFloatButtonClicked()
{
let clapperWidget = this.get_prev_sibling();
const clapperWidget = this.get_prev_sibling();
clapperWidget.setFloatingMode(true);
}
_onFullscreenButtonClicked()
{
let window = this.get_parent();
const window = this.get_parent();
window.fullscreen();
}
});

View File

@@ -10,11 +10,11 @@ class ClapperHeaderBarBase extends Gtk.HeaderBar
can_focus: false,
});
let clapperPath = Misc.getClapperPath();
let uiBuilder = Gtk.Builder.new_from_file(
const clapperPath = Misc.getClapperPath();
const uiBuilder = Gtk.Builder.new_from_file(
`${clapperPath}/ui/clapper.ui`
);
let models = {
const models = {
addMediaMenu: uiBuilder.get_object('addMediaMenu'),
settingsMenu: uiBuilder.get_object('settingsMenu'),
};
@@ -22,32 +22,32 @@ class ClapperHeaderBarBase extends Gtk.HeaderBar
this.add_css_class('noborder');
this.set_title_widget(this._createWidgetForWindow(window));
let addMediaButton = new Gtk.MenuButton({
const addMediaButton = new Gtk.MenuButton({
icon_name: 'list-add-symbolic',
});
let addMediaPopover = new HeaderBarPopover(models.addMediaMenu);
const addMediaPopover = new HeaderBarPopover(models.addMediaMenu);
addMediaButton.set_popover(addMediaPopover);
this.pack_start(addMediaButton);
let openMenuButton = new Gtk.MenuButton({
const openMenuButton = new Gtk.MenuButton({
icon_name: 'open-menu-symbolic',
});
let settingsPopover = new HeaderBarPopover(models.settingsMenu);
const settingsPopover = new HeaderBarPopover(models.settingsMenu);
openMenuButton.set_popover(settingsPopover);
this.pack_end(openMenuButton);
let buttonsBox = new Gtk.Box({
const buttonsBox = new Gtk.Box({
orientation: Gtk.Orientation.HORIZONTAL,
});
buttonsBox.add_css_class('linked');
let floatButton = new Gtk.Button({
const floatButton = new Gtk.Button({
icon_name: 'preferences-desktop-remote-desktop-symbolic',
});
floatButton.connect('clicked', this._onFloatButtonClicked.bind(this));
buttonsBox.append(floatButton);
let fullscreenButton = new Gtk.Button({
const fullscreenButton = new Gtk.Button({
icon_name: 'view-fullscreen-symbolic',
});
fullscreenButton.connect('clicked', this._onFullscreenButtonClicked.bind(this));
@@ -67,7 +67,7 @@ class ClapperHeaderBarBase extends Gtk.HeaderBar
_createWidgetForWindow(window)
{
let box = new Gtk.Box({
const box = new Gtk.Box({
orientation: Gtk.Orientation.VERTICAL,
valign: Gtk.Align.CENTER,
});
@@ -120,16 +120,15 @@ class ClapperHeaderBarPopover extends Gtk.PopoverMenu
_onClosed()
{
let root = this.get_root();
let clapperWidget = root.get_child();
const { child } = this.get_root();
if(
!clapperWidget
|| !clapperWidget.player
|| !clapperWidget.player.widget
!child
|| !child.player
|| !child.player.widget
)
return;
clapperWidget.player.widget.grab_focus();
child.player.widget.grab_focus();
}
});

View File

@@ -1,6 +1,8 @@
const { Gio, GstAudio, GstPlayer, Gdk, Gtk } = imports.gi;
const Debug = imports.clapper_src.debug;
const { debug } = Debug;
var appName = 'Clapper';
var appId = 'com.github.rafostar.Clapper';
@@ -14,7 +16,6 @@ var settings = new Gio.Settings({
var maxVolume = 1.5;
var isOldGtk = (Gtk.MINOR_VERSION === 99 && Gtk.MICRO_VERSION <= 4);
let { debug } = Debug;
let inhibitCookie;
function getClapperPath()
@@ -56,7 +57,7 @@ function inhibitForState(state, window)
if(inhibitCookie)
return;
let app = window.get_application();
const app = window.get_application();
inhibitCookie = app.inhibit(
window,
@@ -72,7 +73,7 @@ function inhibitForState(state, window)
if(!inhibitCookie)
return;
let app = window.get_application();
const app = window.get_application();
app.uninhibit(inhibitCookie);
inhibitCookie = null;
}
@@ -88,11 +89,11 @@ function getFormattedTime(time, showHours)
hours = ('0' + Math.floor(time / 3600)).slice(-2);
time -= hours * 3600;
}
let minutes = ('0' + Math.floor(time / 60)).slice(-2);
const minutes = ('0' + Math.floor(time / 60)).slice(-2);
time -= minutes * 60;
let seconds = ('0' + Math.floor(time)).slice(-2);
const seconds = ('0' + Math.floor(time)).slice(-2);
let parsed = (hours) ? `${hours}:` : '';
const parsed = (hours) ? `${hours}:` : '';
return parsed + `${minutes}:${seconds}`;
}

View File

@@ -4,8 +4,8 @@ const Debug = imports.clapper_src.debug;
const Misc = imports.clapper_src.misc;
const { PlayerBase } = imports.clapper_src.playerBase;
let { debug } = Debug;
let { settings } = Misc;
const { debug } = Debug;
const { settings } = Misc;
var Player = GObject.registerClass(
class ClapperPlayer extends PlayerBase
@@ -37,26 +37,26 @@ class ClapperPlayer extends PlayerBase
this._hideControlsTimeout = null;
this._updateTimeTimeout = null;
let clickGesture = new Gtk.GestureClick();
const clickGesture = new Gtk.GestureClick();
clickGesture.set_button(0);
clickGesture.connect('pressed', this._onWidgetPressed.bind(this));
this.widget.add_controller(clickGesture);
let dragGesture = new Gtk.GestureDrag();
const dragGesture = new Gtk.GestureDrag();
dragGesture.connect('drag-update', this._onWidgetDragUpdate.bind(this));
this.widget.add_controller(dragGesture);
let keyController = new Gtk.EventControllerKey();
const keyController = new Gtk.EventControllerKey();
keyController.connect('key-pressed', this._onWidgetKeyPressed.bind(this));
keyController.connect('key-released', this._onWidgetKeyReleased.bind(this));
this.widget.add_controller(keyController);
let scrollController = new Gtk.EventControllerScroll();
const scrollController = new Gtk.EventControllerScroll();
scrollController.set_flags(Gtk.EventControllerScrollFlags.BOTH_AXES);
scrollController.connect('scroll', this._onScroll.bind(this));
this.widget.add_controller(scrollController);
let motionController = new Gtk.EventControllerMotion();
const motionController = new Gtk.EventControllerMotion();
motionController.connect('enter', this._onWidgetEnter.bind(this));
motionController.connect('leave', this._onWidgetLeave.bind(this));
motionController.connect('motion', this._onWidgetMotion.bind(this));
@@ -104,30 +104,30 @@ class ClapperPlayer extends PlayerBase
return this.set_media(this._playlist[this._trackId]);
}
let fileUri = file.get_uri();
if(fileUri.endsWith('.claps'))
const uri = file.get_uri();
if(uri.endsWith('.claps'))
return this.load_playlist_file(file);
this.is_local_file = true;
this.set_uri(fileUri);
this.set_uri(uri);
}
load_playlist_file(file)
{
let stream = new Gio.DataInputStream({
const stream = new Gio.DataInputStream({
base_stream: file.read(null)
});
let listdir = file.get_parent();
let playlist = [];
let line;
const listdir = file.get_parent();
const playlist = [];
let line;
while((line = stream.read_line(null)[0])) {
line = (line instanceof Uint8Array)
? ByteArray.toString(line).trim()
: String(line).trim();
if(!Gst.uri_is_valid(line)) {
let lineFile = listdir.resolve_relative_path(line);
const lineFile = listdir.resolve_relative_path(line);
if(!lineFile)
continue;
@@ -158,7 +158,7 @@ class ClapperPlayer extends PlayerBase
set_subtitles(source)
{
let uri = (source.get_uri)
const uri = (source.get_uri)
? source.get_uri()
: source;
@@ -217,10 +217,11 @@ class ClapperPlayer extends PlayerBase
{
this.seek_done = false;
let { controls } = this.widget.get_ancestor(Gtk.Grid);
let max = controls.positionAdjustment.get_upper();
const { controls } = this.widget.get_ancestor(Gtk.Grid);
const max = controls.positionAdjustment.get_upper();
const seekingUnit = settings.get_string('seeking-unit');
let seekingValue = settings.get_int('seeking-value');
let seekingUnit = settings.get_string('seeking-unit');
switch(seekingUnit) {
case 'minute':
@@ -246,16 +247,16 @@ class ClapperPlayer extends PlayerBase
adjust_volume(isIncrease)
{
let { controls } = this.widget.get_ancestor(Gtk.Grid);
const { controls } = this.widget.get_ancestor(Gtk.Grid);
const value = (isIncrease) ? 0.05 : -0.05;
const volume = controls.volumeScale.get_value() + value;
let value = (isIncrease) ? 0.05 : -0.05;
let volume = controls.volumeScale.get_value() + value;
controls.volumeScale.set_value(volume);
}
toggle_play()
{
let action = (this.state === GstPlayer.PlayerState.PLAYING)
const action = (this.state === GstPlayer.PlayerState.PLAYING)
? 'pause'
: 'play';
@@ -284,7 +285,7 @@ class ClapperPlayer extends PlayerBase
this._hideCursorTimeout = null;
if(this.cursorInPlayer) {
let blankCursor = Gdk.Cursor.new_from_name('none', null);
const blankCursor = Gdk.Cursor.new_from_name('none', null);
this.widget.set_cursor(blankCursor);
}
@@ -299,7 +300,7 @@ class ClapperPlayer extends PlayerBase
this._hideControlsTimeout = null;
if(this.cursorInPlayer) {
let clapperWidget = this.widget.get_ancestor(Gtk.Grid);
const clapperWidget = this.widget.get_ancestor(Gtk.Grid);
if(clapperWidget.fullscreenMode || clapperWidget.floatingMode) {
this._clearTimeout('updateTime');
clapperWidget.revealControls(false);
@@ -313,8 +314,9 @@ class ClapperPlayer extends PlayerBase
_setUpdateTimeInterval()
{
this._clearTimeout('updateTime');
let clapperWidget = this.widget.get_ancestor(Gtk.Grid);
let nextUpdate = clapperWidget.updateTime();
const clapperWidget = this.widget.get_ancestor(Gtk.Grid);
const nextUpdate = clapperWidget.updateTime();
if(nextUpdate === null)
return;
@@ -346,9 +348,9 @@ class ClapperPlayer extends PlayerBase
window.disconnect(this.closeRequestSignal);
this.closeRequestSignal = null;
let clapperWidget = this.widget.get_ancestor(Gtk.Grid);
const clapperWidget = this.widget.get_ancestor(Gtk.Grid);
if(!clapperWidget.fullscreenMode) {
let size = (Misc.isOldGtk)
const size = (Misc.isOldGtk)
? window.get_size()
: window.get_default_size();
@@ -366,7 +368,7 @@ class ClapperPlayer extends PlayerBase
this.emitWs('state_changed', state);
if(state !== GstPlayer.PlayerState.BUFFERING) {
let root = player.widget.get_root();
const root = player.widget.get_root();
Misc.inhibitForState(state, root);
if(this.quitOnStop) {
@@ -377,7 +379,7 @@ class ClapperPlayer extends PlayerBase
}
}
let clapperWidget = player.widget.get_ancestor(Gtk.Grid);
const clapperWidget = player.widget.get_ancestor(Gtk.Grid);
if(!clapperWidget) return;
if(!this.seek_done && state !== GstPlayer.PlayerState.BUFFERING) {
@@ -413,8 +415,8 @@ class ClapperPlayer extends PlayerBase
this.doneStartup = true;
if(settings.get_boolean('fullscreen-auto')) {
let root = player.widget.get_root();
let clapperWidget = root.get_child();
const root = player.widget.get_root();
const clapperWidget = root.get_child();
if(!clapperWidget.fullscreenMode) {
this.playOnFullscreen = true;
root.fullscreen();
@@ -441,19 +443,21 @@ class ClapperPlayer extends PlayerBase
this.widget.disconnect(this._realizeSignal);
this._realizeSignal = null;
let root = this.widget.get_root();
const root = this.widget.get_root();
if(!root) return;
this.closeRequestSignal = root.connect('close-request', this._onCloseRequest.bind(this));
this.closeRequestSignal = root.connect(
'close-request', this._onCloseRequest.bind(this)
);
}
/* Widget only - does not happen when using controls navigation */
_onWidgetKeyPressed(controller, keyval, keycode, state)
{
this.keyPressCount++;
const clapperWidget = this.widget.get_ancestor(Gtk.Grid);
let bool = false;
let clapperWidget = this.widget.get_ancestor(Gtk.Grid);
this.keyPressCount++;
switch(keyval) {
case Gdk.KEY_Up:
@@ -479,10 +483,10 @@ class ClapperPlayer extends PlayerBase
/* Also happens after using controls navigation for selected keys */
_onWidgetKeyReleased(controller, keyval, keycode, state)
{
this.keyPressCount = 0;
const clapperWidget = this.widget.get_ancestor(Gtk.Grid);
let value, root;
let value;
let clapperWidget = this.widget.get_ancestor(Gtk.Grid);
this.keyPressCount = 0;
switch(keyval) {
case Gdk.KEY_space:
@@ -509,13 +513,13 @@ class ClapperPlayer extends PlayerBase
break;
case Gdk.KEY_Escape:
if(clapperWidget.fullscreenMode) {
let root = this.widget.get_root();
root = this.widget.get_root();
root.unfullscreen();
}
break;
case Gdk.KEY_q:
case Gdk.KEY_Q:
let root = this.widget.get_root();
root = this.widget.get_root();
root.emit('close-request');
break;
default:
@@ -525,14 +529,14 @@ class ClapperPlayer extends PlayerBase
_onWidgetPressed(gesture, nPress, x, y)
{
let button = gesture.get_current_button();
let isDouble = (nPress % 2 == 0);
const button = gesture.get_current_button();
const isDouble = (nPress % 2 == 0);
this.dragAllowed = !isDouble;
switch(button) {
case Gdk.BUTTON_PRIMARY:
if(isDouble) {
let clapperWidget = this.widget.get_ancestor(Gtk.Grid);
const clapperWidget = this.widget.get_ancestor(Gtk.Grid);
clapperWidget.toggleFullscreen();
}
break;
@@ -551,7 +555,7 @@ class ClapperPlayer extends PlayerBase
this._setHideCursorTimeout();
let clapperWidget = this.widget.get_ancestor(Gtk.Grid);
const clapperWidget = this.widget.get_ancestor(Gtk.Grid);
if(clapperWidget.fullscreenMode || clapperWidget.floatingMode)
this._setHideControlsTimeout();
}
@@ -577,11 +581,11 @@ class ClapperPlayer extends PlayerBase
Math.abs(this.posX - posX) >= 0.5
|| Math.abs(this.posY - posY) >= 0.5
) {
let defaultCursor = Gdk.Cursor.new_from_name('default', null);
const defaultCursor = Gdk.Cursor.new_from_name('default', null);
this.widget.set_cursor(defaultCursor);
this._setHideCursorTimeout();
let clapperWidget = this.widget.get_ancestor(Gtk.Grid);
const clapperWidget = this.widget.get_ancestor(Gtk.Grid);
if(clapperWidget.floatingMode && !clapperWidget.fullscreenMode) {
clapperWidget.revealerBottom.set_can_focus(false);
@@ -616,20 +620,20 @@ class ClapperPlayer extends PlayerBase
if(!this.dragAllowed)
return;
let clapperWidget = this.widget.get_ancestor(Gtk.Grid);
const clapperWidget = this.widget.get_ancestor(Gtk.Grid);
if(clapperWidget.fullscreenMode)
return;
let { gtk_double_click_distance } = this.widget.get_settings();
const { gtk_double_click_distance } = this.widget.get_settings();
if (
Math.abs(offsetX) > gtk_double_click_distance
|| Math.abs(offsetY) > gtk_double_click_distance
) {
let [isActive, startX, startY] = gesture.get_start_point();
const [isActive, startX, startY] = gesture.get_start_point();
if(!isActive) return;
let native = this.widget.get_native();
const native = this.widget.get_native();
if(!native) return;
let [isShared, winX, winY] = this.widget.translate_coordinates(
@@ -637,7 +641,7 @@ class ClapperPlayer extends PlayerBase
);
if(!isShared) return;
let [nativeX, nativeY] = native.get_surface_transform();
const [nativeX, nativeY] = native.get_surface_transform();
winX += nativeX;
winY += nativeY;
@@ -656,13 +660,13 @@ class ClapperPlayer extends PlayerBase
_onScroll(controller, dx, dy)
{
let isHorizontal = Math.abs(dx) >= Math.abs(dy);
let isIncrease = (isHorizontal) ? dx < 0 : dy < 0;
const isHorizontal = (Math.abs(dx) >= Math.abs(dy));
const isIncrease = (isHorizontal) ? dx < 0 : dy < 0;
if(isHorizontal) {
this.adjust_position(isIncrease);
let { controls } = this.widget.get_ancestor(Gtk.Grid);
let value = Math.round(controls.positionScale.get_value());
const { controls } = this.widget.get_ancestor(Gtk.Grid);
const value = Math.round(controls.positionScale.get_value());
this.seek_seconds(value);
}
else

View File

@@ -3,8 +3,8 @@ const Debug = imports.clapper_src.debug;
const Misc = imports.clapper_src.misc;
const { WebApp } = imports.clapper_src.webApp;
let { debug } = Debug;
let { settings } = Misc;
const { debug } = Debug;
const { settings } = Misc;
let WebServer;
@@ -16,27 +16,27 @@ class ClapperPlayerBase extends GstPlayer.Player
if(!Gst.is_initialized())
Gst.init(null);
let plugin = 'gtk4glsink';
let gtkglsink = Gst.ElementFactory.make(plugin, null);
const plugin = 'gtk4glsink';
const gtk4glsink = Gst.ElementFactory.make(plugin, null);
if(!gtkglsink) {
if(!gtk4glsink) {
return debug(new Error(
`Could not load "${plugin}".`
+ ' Do you have gstreamer-plugins-good-gtk4 installed?'
));
}
let glsinkbin = Gst.ElementFactory.make('glsinkbin', null);
glsinkbin.sink = gtkglsink;
const glsinkbin = Gst.ElementFactory.make('glsinkbin', null);
glsinkbin.sink = gtk4glsink;
let context = GLib.MainContext.ref_thread_default();
let acquired = context.acquire();
const context = GLib.MainContext.ref_thread_default();
const acquired = context.acquire();
debug(`default context acquired: ${acquired}`);
let dispatcher = new GstPlayer.PlayerGMainContextSignalDispatcher({
const dispatcher = new GstPlayer.PlayerGMainContextSignalDispatcher({
application_context: context,
});
let renderer = new GstPlayer.PlayerVideoOverlayVideoRenderer({
const renderer = new GstPlayer.PlayerVideoOverlayVideoRenderer({
video_sink: glsinkbin
});
@@ -68,7 +68,7 @@ class ClapperPlayerBase extends GstPlayer.Player
set_and_bind_settings()
{
let settingsToSet = [
const settingsToSet = [
'seeking-mode',
'audio-offset',
'subtitle-offset',
@@ -79,13 +79,13 @@ class ClapperPlayerBase extends GstPlayer.Player
for(let key of settingsToSet)
this._onSettingsKeyChanged(settings, key);
let flag = Gio.SettingsBindFlags.GET;
const flag = Gio.SettingsBindFlags.GET;
settings.bind('subtitle-font', this.pipeline, 'subtitle_font_desc', flag);
}
set_initial_config()
{
let gstPlayerConfig = {
const gstPlayerConfig = {
position_update_interval: 1000,
user_agent: 'clapper',
};
@@ -96,19 +96,19 @@ class ClapperPlayerBase extends GstPlayer.Player
this.set_mute(false);
/* FIXME: change into option in preferences */
let pipeline = this.get_pipeline();
const pipeline = this.get_pipeline();
pipeline.ring_buffer_max_size = 8 * 1024 * 1024;
}
set_config_option(option, value)
{
let setOption = GstPlayer.Player[`config_set_${option}`];
const setOption = GstPlayer.Player[`config_set_${option}`];
if(!setOption)
return debug(`unsupported option: ${option}`, 'LEVEL_WARNING');
let config = this.get_config();
const config = this.get_config();
setOption(config, value);
let success = this.set_config(config);
const success = this.set_config(config);
if(!success)
debug(`could not change option: ${option}`);
@@ -139,12 +139,12 @@ class ClapperPlayerBase extends GstPlayer.Player
set_plugin_rank(name, rank)
{
let gstRegistry = Gst.Registry.get();
let feature = gstRegistry.lookup_feature(name);
const gstRegistry = Gst.Registry.get();
const feature = gstRegistry.lookup_feature(name);
if(!feature)
return debug(`plugin unavailable: ${name}`);
let oldRank = feature.get_rank();
const oldRank = feature.get_rank();
if(rank === oldRank)
return;
@@ -179,7 +179,7 @@ class ClapperPlayerBase extends GstPlayer.Player
switch(key) {
case 'seeking-mode':
let isSeekMode = (typeof this.set_seek_mode !== 'undefined');
const isSeekMode = (typeof this.set_seek_mode !== 'undefined');
this.seekingMode = settings.get_string('seeking-mode');
switch(this.seekingMode) {
case 'fast':
@@ -212,9 +212,9 @@ class ClapperPlayerBase extends GstPlayer.Player
if(!root || !root.isClapperApp)
break;
let gpuClass = 'gpufriendly';
let renderShadows = settings.get_boolean(key);
let hasShadows = !root.has_css_class(gpuClass);
const gpuClass = 'gpufriendly';
const renderShadows = settings.get_boolean(key);
const hasShadows = !root.has_css_class(gpuClass);
if(renderShadows === hasShadows)
break;
@@ -238,8 +238,8 @@ class ClapperPlayerBase extends GstPlayer.Player
if(!root || !root.isClapperApp)
break;
let brightClass = 'brightscale';
let isBrighter = root.has_css_class(brightClass);
const brightClass = 'brightscale';
const isBrighter = root.has_css_class(brightClass);
if(key === 'dark-theme' && isBrighter && !settings.get_boolean(key)) {
root.remove_css_class(brightClass);
@@ -247,7 +247,7 @@ class ClapperPlayerBase extends GstPlayer.Player
break;
}
let setBrighter = settings.get_boolean('brighter-sliders');
const setBrighter = settings.get_boolean('brighter-sliders');
if(setBrighter === isBrighter)
break;

View File

@@ -2,7 +2,7 @@ const { GObject, Gst, Gtk, Pango } = imports.gi;
const Misc = imports.clapper_src.misc;
const PrefsBase = imports.clapper_src.prefsBase;
let { settings } = Misc;
const { settings } = Misc;
/* PlayFlags are not exported through GI */
Gst.PlayFlags = {
@@ -32,11 +32,11 @@ class ClapperGeneralPage extends PrefsBase.Grid
this.addCheckButton('Auto enter fullscreen', 'fullscreen-auto');
this.addTitle('Volume');
let comboBox = this.addComboBoxText('Initial value', [
const comboBox = this.addComboBoxText('Initial value', [
['restore', "Restore"],
['custom', "Custom"],
], 'volume-initial');
let spinButton = this.addSpinButton('Value (percentage)', 0, 200, 'volume-value');
const spinButton = this.addSpinButton('Value (percentage)', 0, 200, 'volume-value');
this._onVolumeInitialChanged(spinButton, comboBox);
comboBox.connect('changed', this._onVolumeInitialChanged.bind(this, spinButton));
@@ -46,7 +46,7 @@ class ClapperGeneralPage extends PrefsBase.Grid
_onVolumeInitialChanged(spinButton, comboBox)
{
let value = comboBox.get_active_id();
const value = comboBox.get_active_id();
spinButton.set_visible(value === 'custom');
}
});
@@ -116,12 +116,12 @@ class ClapperNetworkPage extends PrefsBase.Grid
this.addPlayFlagCheckButton('Progressive download buffering', Gst.PlayFlags.DOWNLOAD);
this.addTitle('Server');
let webServer = this.addCheckButton('Control player remotely', 'webserver-enabled');
let serverPort = this.addSpinButton('Listening port', 1024, 65535, 'webserver-port');
const webServer = this.addCheckButton('Control player remotely', 'webserver-enabled');
const serverPort = this.addSpinButton('Listening port', 1024, 65535, 'webserver-port');
webServer.bind_property('active', serverPort, 'visible', GObject.BindingFlags.SYNC_CREATE);
let webApp = this.addCheckButton('Start built-in web application', 'webapp-enabled');
const webApp = this.addCheckButton('Start built-in web application', 'webapp-enabled');
webServer.bind_property('active', webApp, 'visible', GObject.BindingFlags.SYNC_CREATE);
let webAppPort = this.addSpinButton('Web application port', 1024, 65535, 'webapp-port');
const webAppPort = this.addSpinButton('Web application port', 1024, 65535, 'webapp-port');
webServer.bind_property('active', webAppPort, 'visible', GObject.BindingFlags.SYNC_CREATE);
}
});
@@ -134,38 +134,38 @@ class ClapperGStreamerPage extends PrefsBase.Grid
super._init();
this.addTitle('Plugin Ranking');
let listStore = new Gtk.ListStore();
const listStore = new Gtk.ListStore();
listStore.set_column_types([
GObject.TYPE_BOOLEAN,
GObject.TYPE_STRING,
GObject.TYPE_STRING,
]);
let treeView = new Gtk.TreeView({
const treeView = new Gtk.TreeView({
hexpand: true,
vexpand: true,
enable_search: false,
model: listStore,
});
let treeSelection = treeView.get_selection();
const treeSelection = treeView.get_selection();
let apply = new Gtk.TreeViewColumn({
const apply = new Gtk.TreeViewColumn({
title: "Apply",
});
let name = new Gtk.TreeViewColumn({
const name = new Gtk.TreeViewColumn({
title: "Plugin",
expand: true,
});
let rank = new Gtk.TreeViewColumn({
const rank = new Gtk.TreeViewColumn({
title: "Rank",
min_width: 90,
});
let applyCell = new Gtk.CellRendererToggle();
let nameCell = new Gtk.CellRendererText({
const applyCell = new Gtk.CellRendererToggle();
const nameCell = new Gtk.CellRendererText({
editable: true,
placeholder_text: "Insert plugin name",
});
let rankCell = new Gtk.CellRendererText({
const rankCell = new Gtk.CellRendererText({
editable: true,
weight: Pango.Weight.BOLD,
placeholder_text: "Insert plugin rank",
@@ -183,27 +183,27 @@ class ClapperGStreamerPage extends PrefsBase.Grid
treeView.insert_column(name, 1);
treeView.insert_column(rank, 2);
let frame = new Gtk.Frame({
const frame = new Gtk.Frame({
child: treeView
});
this.addToGrid(frame);
let addButton = new Gtk.Button({
const addButton = new Gtk.Button({
icon_name: 'list-add-symbolic',
halign: Gtk.Align.END,
});
let removeButton = new Gtk.Button({
const removeButton = new Gtk.Button({
icon_name: 'list-remove-symbolic',
sensitive: false,
halign: Gtk.Align.END,
});
let label = new Gtk.Label({
const label = new Gtk.Label({
label: 'Changes require player restart',
halign: Gtk.Align.START,
hexpand: true,
ellipsize: Pango.EllipsizeMode.END,
});
let box = new Gtk.Box({
const box = new Gtk.Box({
orientation: Gtk.Orientation.HORIZONTAL,
spacing: 6,
hexpand: true,
@@ -229,7 +229,7 @@ class ClapperGStreamerPage extends PrefsBase.Grid
refreshListStore(listStore)
{
let data = JSON.parse(settings.get_string('plugin-ranking'));
const data = JSON.parse(settings.get_string('plugin-ranking'));
listStore.clear();
for(let plugin of data) {
@@ -246,14 +246,14 @@ class ClapperGStreamerPage extends PrefsBase.Grid
updatePlugin(index, prop, value)
{
let data = JSON.parse(settings.get_string('plugin-ranking'));
const data = JSON.parse(settings.get_string('plugin-ranking'));
data[index][prop] = value;
settings.set_string('plugin-ranking', JSON.stringify(data));
}
_onTreeSelectionChanged(removeButton, treeSelection)
{
let [isSelected, model, iter] = treeSelection.get_selected();
const [isSelected, model, iter] = treeSelection.get_selected();
this.activeIndex = -1;
if(isSelected) {
@@ -265,7 +265,7 @@ class ClapperGStreamerPage extends PrefsBase.Grid
_onAddButtonClicked(listStore, button)
{
let data = JSON.parse(settings.get_string('plugin-ranking'));
const data = JSON.parse(settings.get_string('plugin-ranking'));
data.push({
apply: false,
name: '',
@@ -279,14 +279,14 @@ class ClapperGStreamerPage extends PrefsBase.Grid
if(this.activeIndex < 0)
return;
let data = JSON.parse(settings.get_string('plugin-ranking'));
const data = JSON.parse(settings.get_string('plugin-ranking'));
data.splice(this.activeIndex, 1);
settings.set_string('plugin-ranking', JSON.stringify(data));
}
_onApplyCellEdited(cell, path)
{
let newState = !cell.active;
const newState = !cell.active;
this.updatePlugin(path, 'apply', newState);
}
@@ -323,18 +323,11 @@ class ClapperTweaksPage extends PrefsBase.Grid
super._init();
this.addTitle('Appearance');
let darkCheck = this.addCheckButton('Enable dark theme', 'dark-theme');
let brighterCheck = this.addCheckButton('Make sliders brighter', 'brighter-sliders');
this._onDarkThemeToggled(brighterCheck, darkCheck);
darkCheck.connect('toggled', this._onDarkThemeToggled.bind(this, brighterCheck));
const darkCheck = this.addCheckButton('Enable dark theme', 'dark-theme');
const brighterCheck = this.addCheckButton('Make sliders brighter', 'brighter-sliders');
darkCheck.bind_property('active', brighterCheck, 'visible', GObject.BindingFlags.SYNC_CREATE);
this.addTitle('Performance');
this.addCheckButton('Render window shadows', 'render-shadows');
}
_onDarkThemeToggled(brighterCheck, darkCheck)
{
let isActive = darkCheck.get_active();
brighterCheck.set_visible(isActive);
}
});

View File

@@ -2,8 +2,8 @@ const { Gio, GObject, Gtk } = imports.gi;
const Debug = imports.clapper_src.debug;
const Misc = imports.clapper_src.misc;
let { debug } = Debug;
let { settings } = Misc;
const { debug } = Debug;
const { settings } = Misc;
var Notebook = GObject.registerClass(
class ClapperPrefsNotebook extends Gtk.Notebook
@@ -32,7 +32,7 @@ class ClapperPrefsNotebook extends Gtk.Notebook
addObjectPages(item)
{
let widget = (item.pages)
const widget = (item.pages)
? new Notebook(item.pages, true)
: new item.widget();
@@ -41,7 +41,7 @@ class ClapperPrefsNotebook extends Gtk.Notebook
addToNotebook(widget, title)
{
let label = new Gtk.Label({
const label = new Gtk.Label({
label: title,
});
this.append_page(widget, label);
@@ -49,11 +49,11 @@ class ClapperPrefsNotebook extends Gtk.Notebook
_onClose()
{
let totalPages = this.get_n_pages();
const totalPages = this.get_n_pages();
let index = 0;
while(index < totalPages) {
let page = this.get_nth_page(index);
const page = this.get_nth_page(index);
page._onClose();
index++;
}
@@ -99,38 +99,38 @@ class ClapperPrefsGrid extends Gtk.Grid
addTitle(text)
{
let label = this.getLabel(text, true);
const label = this.getLabel(text, true);
return this.addToGrid(label);
}
addComboBoxText(text, entries, setting)
{
let label = this.getLabel(text + ':');
let widget = this.getComboBoxText(entries, setting);
const label = this.getLabel(text + ':');
const widget = this.getComboBoxText(entries, setting);
return this.addToGrid(label, widget);
}
addSpinButton(text, min, max, setting, precision)
{
let label = this.getLabel(text + ':');
let widget = this.getSpinButton(min, max, setting, precision);
const label = this.getLabel(text + ':');
const widget = this.getSpinButton(min, max, setting, precision);
return this.addToGrid(label, widget);
}
addCheckButton(text, setting)
{
let widget = this.getCheckButton(text, setting);
const widget = this.getCheckButton(text, setting);
return this.addToGrid(widget);
}
addPlayFlagCheckButton(text, flag)
{
let checkButton = this.addCheckButton(text);
let playFlags = settings.get_int('play-flags');
const checkButton = this.addCheckButton(text);
const playFlags = settings.get_int('play-flags');
checkButton.active = ((playFlags & flag) === flag);
checkButton.connect('toggled', this._onPlayFlagToggled.bind(this, flag));
@@ -140,17 +140,18 @@ class ClapperPrefsGrid extends Gtk.Grid
addFontButton(text, setting)
{
let label = this.getLabel(text + ':');
let widget = this.getFontButton(setting);
const label = this.getLabel(text + ':');
const widget = this.getFontButton(setting);
return this.addToGrid(label, widget);
}
getLabel(text, isTitle)
{
const marginTop = (isTitle && this.gridIndex > 0) ? 16 : 0;
const marginBottom = (isTitle) ? 2 : 0;
let marginLR = 0;
let marginTop = (isTitle && this.gridIndex > 0) ? 16 : 0;
let marginBottom = (isTitle) ? 2 : 0;
if(isTitle)
text = '<span font="12"><b>' + text + '</b></span>';
@@ -171,7 +172,7 @@ class ClapperPrefsGrid extends Gtk.Grid
getComboBoxText(entries, setting)
{
let comboBox = new Gtk.ComboBoxText(this.widgetDefaults);
const comboBox = new Gtk.ComboBoxText(this.widgetDefaults);
for(let entry of entries)
comboBox.append(entry[0], entry[1]);
@@ -185,7 +186,7 @@ class ClapperPrefsGrid extends Gtk.Grid
{
precision = precision || 1;
let spinButton = new Gtk.SpinButton(this.widgetDefaults);
const spinButton = new Gtk.SpinButton(this.widgetDefaults);
spinButton.set_range(min, max);
spinButton.set_digits(precision % 1 === 0 ? 0 : 3);
spinButton.set_increments(precision, 1);
@@ -196,7 +197,7 @@ class ClapperPrefsGrid extends Gtk.Grid
getCheckButton(text, setting)
{
let checkButton = new Gtk.CheckButton({
const checkButton = new Gtk.CheckButton({
label: text || null,
});
@@ -208,7 +209,7 @@ class ClapperPrefsGrid extends Gtk.Grid
getFontButton(setting)
{
let fontButton = new Gtk.FontButton({
const fontButton = new Gtk.FontButton({
use_font: true,
use_size: true,
});

View File

@@ -3,7 +3,7 @@ const Debug = imports.clapper_src.debug;
const REVEAL_TIME = 800;
let { debug } = Debug;
const { debug } = Debug;
var CustomRevealer = GObject.registerClass(
class ClapperCustomRevealer extends Gtk.Revealer
@@ -12,7 +12,7 @@ class ClapperCustomRevealer extends Gtk.Revealer
{
opts = opts || {};
let defaults = {
const defaults = {
visible: false,
can_focus: false,
};
@@ -96,9 +96,9 @@ class ClapperRevealerTop extends CustomRevealer
transition_type: Gtk.RevealerTransitionType.CROSSFADE,
valign: Gtk.Align.START,
});
this.revealerName = 'top';
let initTime = GLib.DateTime.new_now_local().format('%X');
const initTime = GLib.DateTime.new_now_local().format('%X');
this.timeFormat = (initTime.length > 8)
? '%I:%M %p'
: '%H:%M';
@@ -119,7 +119,7 @@ class ClapperRevealerTop extends CustomRevealer
yalign: 0,
});
let timeLabelOpts = {
const timeLabelOpts = {
margin_end: 10,
xalign: 1,
yalign: 0,
@@ -127,9 +127,8 @@ class ClapperRevealerTop extends CustomRevealer
this.currentTime = new Gtk.Label(timeLabelOpts);
this.currentTime.add_css_class('osdtime');
this.endTime = new Gtk.Label(
Object.assign(timeLabelOpts, { visible: false })
);
timeLabelOpts.visible = false;
this.endTime = new Gtk.Label(timeLabelOpts);
this.endTime.add_css_class('osdendtime');
this.revealerGrid.attach(this.mediaTitle, 0, 0, 1, 1);
@@ -146,16 +145,16 @@ class ClapperRevealerTop extends CustomRevealer
setTimes(currTime, endTime)
{
let now = currTime.format(this.timeFormat);
let end = endTime.format(this.timeFormat);
let endText = `Ends at: ${end}`;
const now = currTime.format(this.timeFormat);
const end = endTime.format(this.timeFormat);
const endText = `Ends at: ${end}`;
this.currentTime.set_label(now);
this.endTime.set_label(endText);
/* Make sure that next timeout is always run after clock changes,
* by delaying it for additional few milliseconds */
let nextUpdate = 60002 - parseInt(currTime.get_seconds() * 1000);
const nextUpdate = 60002 - parseInt(currTime.get_seconds() * 1000);
debug(`updated current time: ${now}, ends at: ${end}`);
return nextUpdate;
@@ -195,27 +194,27 @@ class ClapperRevealerBottom extends CustomRevealer
if(isFloating === this.revealerBox.has_css_class('floatingcontrols'))
return;
let action = (isFloating) ? 'add' : 'remove';
const action = (isFloating) ? 'add' : 'remove';
this.revealerBox[`${action}_css_class`]('floatingcontrols');
}
set_visible(isVisible)
{
let isChange = super.set_visible(isVisible);
const isChange = super.set_visible(isVisible);
if(!isChange || !this.can_focus) return;
let parent = this.get_parent();
let playerWidget = parent.get_first_child();
const parent = this.get_parent();
const playerWidget = parent.get_first_child();
if(!playerWidget) return;
if(isVisible) {
let box = this.get_first_child();
const box = this.get_first_child();
if(!box) return;
let controls = box.get_first_child();
const controls = box.get_first_child();
if(!controls) return;
let togglePlayButton = controls.get_first_child();
const togglePlayButton = controls.get_first_child();
if(togglePlayButton) {
togglePlayButton.grab_focus();
debug('focus moved to toggle play button');
@@ -240,7 +239,7 @@ class ClapperButtonsRevealer extends Gtk.Revealer
transition_type: Gtk.RevealerTransitionType[trType],
});
let revealerBox = new Gtk.Box({
const revealerBox = new Gtk.Box({
orientation: Gtk.Orientation.HORIZONTAL,
});
this.set_child(revealerBox);
@@ -257,7 +256,7 @@ class ClapperButtonsRevealer extends Gtk.Revealer
if(this.reveal_child === isReveal)
return;
let grandson = this.child.get_first_child();
const grandson = this.child.get_first_child();
if(grandson && grandson.isFloating && !grandson.isFullscreen)
return;

View File

@@ -2,7 +2,7 @@ const { Gio, GObject } = imports.gi;
const Debug = imports.clapper_src.debug;
const Misc = imports.clapper_src.misc;
let { debug } = Debug;
const { debug } = Debug;
var WebApp = GObject.registerClass(
class ClapperWebApp extends Gio.SubprocessLauncher

View File

@@ -3,8 +3,8 @@ const Debug = imports.clapper_src.debug;
const Misc = imports.clapper_src.misc;
const WebHelpers = imports.clapper_src.webHelpers;
let { debug } = Debug;
let { settings } = Misc;
const { debug } = Debug;
const { settings } = Misc;
var WebClient = GObject.registerClass(
class ClapperWebClient extends Soup.Session

View File

@@ -2,7 +2,7 @@ const { Soup } = imports.gi;
const ByteArray = imports.byteArray;
const Debug = imports.clapper_src.debug;
let { debug } = Debug;
const { debug } = Debug;
function parseData(dataType, bytes)
{

View File

@@ -2,7 +2,7 @@ const { Soup, GObject } = imports.gi;
const Debug = imports.clapper_src.debug;
const WebHelpers = imports.clapper_src.webHelpers;
let { debug } = Debug;
const { debug } = Debug;
var WebServer = GObject.registerClass(
class ClapperWebServer extends Soup.Server

View File

@@ -5,8 +5,8 @@ const Misc = imports.clapper_src.misc;
const { Player } = imports.clapper_src.player;
const Revealers = imports.clapper_src.revealers;
let { debug } = Debug;
let { settings } = Misc;
const { debug } = Debug;
const { settings } = Misc;
var Widget = GObject.registerClass({
Signals: {
@@ -60,7 +60,7 @@ var Widget = GObject.registerClass({
this.overlay.add_overlay(this.revealerTop);
this.overlay.add_overlay(this.revealerBottom);
let motionController = new Gtk.EventControllerMotion();
const motionController = new Gtk.EventControllerMotion();
motionController.connect('leave', this._onLeave.bind(this));
this.add_controller(motionController);
}
@@ -79,10 +79,10 @@ var Widget = GObject.registerClass({
toggleFullscreen()
{
let root = this.get_root();
const root = this.get_root();
if(!root) return;
let un = (this.fullscreenMode) ? 'un' : '';
const un = (this.fullscreenMode) ? 'un' : '';
root[`${un}fullscreen`]();
}
@@ -93,8 +93,8 @@ var Widget = GObject.registerClass({
this.fullscreenMode = isFullscreen;
let root = this.get_root();
let action = (isFullscreen) ? 'add' : 'remove';
const root = this.get_root();
const action = (isFullscreen) ? 'add' : 'remove';
root[action + '_css_class']('gpufriendlyfs');
if(!this.floatingMode)
@@ -121,8 +121,8 @@ var Widget = GObject.registerClass({
if(this.floatingMode === isFloating)
return;
let root = this.get_root();
let size = (Misc.isOldGtk)
const root = this.get_root();
const size = (Misc.isOldGtk)
? root.get_size()
: root.get_default_size();
@@ -145,7 +145,7 @@ var Widget = GObject.registerClass({
this.controls.unfloatButton.set_visible(isFloating);
this._setWindowFloating(isFloating);
let resize = (isFloating)
const resize = (isFloating)
? this.floatSize
: this.windowSize;
@@ -162,19 +162,19 @@ var Widget = GObject.registerClass({
_setWindowFloating(isFloating)
{
let root = this.get_root();
const root = this.get_root();
const cssClass = 'floatingwindow';
let cssClass = 'floatingwindow';
if(isFloating === root.has_css_class(cssClass))
return;
let action = (isFloating) ? 'add' : 'remove';
const action = (isFloating) ? 'add' : 'remove';
root[action + '_css_class'](cssClass);
}
_saveWindowSize(size)
{
let rootName = (this.floatingMode)
const rootName = (this.floatingMode)
? 'float'
: 'window';
@@ -198,7 +198,7 @@ var Widget = GObject.registerClass({
_updateMediaInfo()
{
let mediaInfo = this.player.get_media_info();
const mediaInfo = this.player.get_media_info();
if(!mediaInfo)
return GLib.SOURCE_REMOVE;
@@ -206,12 +206,12 @@ var Widget = GObject.registerClass({
this.updateTitles(mediaInfo);
/* Show/hide position scale on LIVE */
let isLive = mediaInfo.is_live();
const isLive = mediaInfo.is_live();
this.isSeekable = mediaInfo.is_seekable();
this.controls.setLiveMode(isLive, this.isSeekable);
let streamList = mediaInfo.get_stream_list();
let parsedInfo = {
const streamList = mediaInfo.get_stream_list();
const parsedInfo = {
videoTracks: [],
audioTracks: [],
subtitleTracks: []
@@ -253,7 +253,7 @@ var Widget = GObject.registerClass({
debug(`unrecognized media info type: ${info.constructor}`);
break;
}
let tracksArr = parsedInfo[`${type}Tracks`];
const tracksArr = parsedInfo[`${type}Tracks`];
if(!tracksArr.length)
{
tracksArr[0] = {
@@ -272,15 +272,15 @@ var Widget = GObject.registerClass({
let anyButtonShown = false;
for(let type of ['video', 'audio', 'subtitle']) {
let currStream = this.player[`get_current_${type}_track`]();
let activeId = (currStream) ? currStream.get_index() : -1;
const currStream = this.player[`get_current_${type}_track`]();
const activeId = (currStream) ? currStream.get_index() : -1;
if(currStream && type !== 'subtitle') {
let caps = currStream.get_caps();
const caps = currStream.get_caps();
debug(`${type} caps: ${caps.to_string()}`, 'LEVEL_INFO');
}
if(type === 'video') {
let isShowVis = (parsedInfo[`${type}Tracks`].length === 0);
const isShowVis = (parsedInfo[`${type}Tracks`].length === 0);
this.showVisualizationsButton(isShowVis);
}
if(!parsedInfo[`${type}Tracks`].length) {
@@ -324,8 +324,8 @@ var Widget = GObject.registerClass({
subtitle = null;
}
let root = this.get_root();
let headerbar = root.get_titlebar();
const root = this.get_root();
const headerbar = root.get_titlebar();
if(headerbar && headerbar.updateHeaderBar)
headerbar.updateHeaderBar(title, subtitle);
@@ -338,11 +338,11 @@ var Widget = GObject.registerClass({
if(!this.revealerTop.visible)
return null;
let currTime = GLib.DateTime.new_now_local();
let endTime = currTime.add_seconds(
const currTime = GLib.DateTime.new_now_local();
const endTime = currTime.add_seconds(
this.controls.positionAdjustment.get_upper() - this.controls.currentPosition
);
let nextUpdate = this.revealerTop.setTimes(currTime, endTime);
const nextUpdate = this.revealerTop.setTimes(currTime, endTime);
return nextUpdate;
}
@@ -351,11 +351,11 @@ var Widget = GObject.registerClass({
{
if(isShow && !this.controls.visualizationsButton.isVisList) {
debug('creating visualizations list');
let visArr = GstPlayer.Player.visualizations_get();
const visArr = GstPlayer.Player.visualizations_get();
if(!visArr.length)
return;
let parsedVisArr = [{
const parsedVisArr = [{
label: 'Disabled',
type: 'visualization',
activeId: null
@@ -381,7 +381,7 @@ var Widget = GObject.registerClass({
if(this.controls.visualizationsButton.visible === isShow)
return;
let action = (isShow) ? 'show' : 'hide';
const action = (isShow) ? 'show' : 'hide';
this.controls.visualizationsButton[action]();
debug(`show visualizations button: ${isShow}`);
}
@@ -421,13 +421,13 @@ var Widget = GObject.registerClass({
break;
}
let isNotStopped = (state !== GstPlayer.PlayerState.STOPPED);
const isNotStopped = (state !== GstPlayer.PlayerState.STOPPED);
this.revealerTop.endTime.set_visible(isNotStopped);
}
_onPlayerDurationChanged(player)
{
let duration = Math.floor(player.get_duration() / 1000000000);
const duration = Math.floor(player.get_duration() / 1000000000);
/* Sometimes GstPlayer might re-emit
* duration changed during playback */
@@ -451,7 +451,7 @@ var Widget = GObject.registerClass({
)
return;
let positionSeconds = Math.round(position / 1000000000);
const positionSeconds = Math.round(position / 1000000000);
if(positionSeconds === this.controls.currentPosition)
return;
@@ -460,7 +460,7 @@ var Widget = GObject.registerClass({
_onPlayerVolumeChanged(player)
{
let volume = player.get_volume();
const volume = player.get_volume();
/* FIXME: This check should not be needed, GstPlayer should not
* emit 'volume-changed' with the same values, but it does. */
@@ -470,13 +470,13 @@ var Widget = GObject.registerClass({
/* Once above is fixed in GstPlayer, remove this var too */
this.controls.currentVolume = volume;
let cubicVolume = Misc.getCubicValue(volume);
const cubicVolume = Misc.getCubicValue(volume);
this.controls._updateVolumeButtonIcon(cubicVolume);
}
_onStateNotify(toplevel)
{
let isFullscreen = Boolean(
const isFullscreen = Boolean(
toplevel.state & Gdk.ToplevelState.FULLSCREEN
);
@@ -504,10 +504,10 @@ var Widget = GObject.registerClass({
{
this.disconnect(this.mapSignal);
let root = this.get_root();
const root = this.get_root();
if(!root) return;
let surface = root.get_surface();
const surface = root.get_surface();
surface.connect('notify::state', this._onStateNotify.bind(this));
}
});

View File

@@ -62,7 +62,7 @@ class ClapperWidgetRemote extends Gtk.Grid
}
break;
case 'close':
let root = this.get_root();
const root = this.get_root();
root.run_dispose();
break;
default: