mirror of
https://github.com/Rafostar/clapper.git
synced 2025-08-30 16:02:00 +02:00
Prepare for resource loading
Cleanup the Clapper install path detection code in a way to make gresources loading eventually possible for compiled builds
This commit is contained in:
@@ -47,10 +47,7 @@ function handleAction(action, window)
|
|||||||
break;
|
break;
|
||||||
case 'shortcuts':
|
case 'shortcuts':
|
||||||
if(!window.get_help_overlay()) {
|
if(!window.get_help_overlay()) {
|
||||||
const clapperPath = Misc.getClapperPath();
|
const helpBuilder = Misc.getBuilderForName('help-overlay.ui');
|
||||||
const helpBuilder = Gtk.Builder.new_from_file(
|
|
||||||
`${clapperPath}/ui/help-overlay.ui`
|
|
||||||
);
|
|
||||||
window.set_help_overlay(helpBuilder.get_object('help_overlay'));
|
window.set_help_overlay(helpBuilder.get_object('help_overlay'));
|
||||||
}
|
}
|
||||||
clapperWidget.activate_action('win.show-help-overlay', null);
|
clapperWidget.activate_action('win.show-help-overlay', null);
|
||||||
|
@@ -60,7 +60,7 @@ class ClapperIconToggleButton extends CustomButton
|
|||||||
|
|
||||||
var PopoverSeparator = GObject.registerClass({
|
var PopoverSeparator = GObject.registerClass({
|
||||||
GTypeName: 'ClapperPopoverSeparator',
|
GTypeName: 'ClapperPopoverSeparator',
|
||||||
Template: `file://${Misc.getClapperPath()}/ui/popover-separator.ui`,
|
Template: Misc.getResourceUri('ui/popover-separator.ui'),
|
||||||
InternalChildren: ['middle_label'],
|
InternalChildren: ['middle_label'],
|
||||||
Properties: {
|
Properties: {
|
||||||
'label': GObject.ParamSpec.string(
|
'label': GObject.ParamSpec.string(
|
||||||
@@ -138,7 +138,7 @@ class ClapperPopoverButtonBase extends Gtk.MenuButton
|
|||||||
|
|
||||||
var ElapsedTimeButton = GObject.registerClass({
|
var ElapsedTimeButton = GObject.registerClass({
|
||||||
GTypeName: 'ClapperElapsedTimeButton',
|
GTypeName: 'ClapperElapsedTimeButton',
|
||||||
Template: `file://${Misc.getClapperPath()}/ui/elapsed-time-button.ui`,
|
Template: Misc.getResourceUri('ui/elapsed-time-button.ui'),
|
||||||
Children: ['scrolledWindow', 'speedScale'],
|
Children: ['scrolledWindow', 'speedScale'],
|
||||||
},
|
},
|
||||||
class ClapperElapsedTimeButton extends PopoverButtonBase
|
class ClapperElapsedTimeButton extends PopoverButtonBase
|
||||||
@@ -177,7 +177,7 @@ class ClapperElapsedTimeButton extends PopoverButtonBase
|
|||||||
|
|
||||||
var TrackSelectButton = GObject.registerClass({
|
var TrackSelectButton = GObject.registerClass({
|
||||||
GTypeName: 'ClapperTrackSelectButton',
|
GTypeName: 'ClapperTrackSelectButton',
|
||||||
Template: `file://${Misc.getClapperPath()}/ui/track-select-button.ui`,
|
Template: Misc.getResourceUri('ui/track-select-button.ui'),
|
||||||
Children: ['popoverBox'],
|
Children: ['popoverBox'],
|
||||||
InternalChildren: ['scrolled_window', 'decoder_separator'],
|
InternalChildren: ['scrolled_window', 'decoder_separator'],
|
||||||
},
|
},
|
||||||
@@ -204,7 +204,7 @@ class ClapperTrackSelectButton extends PopoverButtonBase
|
|||||||
|
|
||||||
var VolumeButton = GObject.registerClass({
|
var VolumeButton = GObject.registerClass({
|
||||||
GTypeName: 'ClapperVolumeButton',
|
GTypeName: 'ClapperVolumeButton',
|
||||||
Template: `file://${Misc.getClapperPath()}/ui/volume-button.ui`,
|
Template: Misc.getResourceUri('ui/volume-button.ui'),
|
||||||
Children: ['volumeScale'],
|
Children: ['volumeScale'],
|
||||||
},
|
},
|
||||||
class ClapperVolumeButton extends PopoverButtonBase
|
class ClapperVolumeButton extends PopoverButtonBase
|
||||||
|
@@ -25,10 +25,7 @@ class ClapperHeaderBarBase extends Gtk.Box
|
|||||||
this.isMenuOnLeft = true;
|
this.isMenuOnLeft = true;
|
||||||
this.hasPipIcons = false;
|
this.hasPipIcons = false;
|
||||||
|
|
||||||
const clapperPath = Misc.getClapperPath();
|
const uiBuilder = Misc.getBuilderForName('clapper.ui');
|
||||||
const uiBuilder = Gtk.Builder.new_from_file(
|
|
||||||
`${clapperPath}/ui/clapper.ui`
|
|
||||||
);
|
|
||||||
|
|
||||||
this.menuWidget = new Gtk.Box({
|
this.menuWidget = new Gtk.Box({
|
||||||
orientation: Gtk.Orientation.HORIZONTAL,
|
orientation: Gtk.Orientation.HORIZONTAL,
|
||||||
|
@@ -4,14 +4,11 @@ imports.gi.versions.Soup = '2.4';
|
|||||||
|
|
||||||
pkg.initGettext();
|
pkg.initGettext();
|
||||||
|
|
||||||
|
const Misc = imports.src.misc;
|
||||||
|
Misc.appId += '.Remote';
|
||||||
|
|
||||||
const { Gtk, Adw } = imports.gi;
|
const { Gtk, Adw } = imports.gi;
|
||||||
const { AppRemote } = imports.src.appRemote;
|
const { AppRemote } = imports.src.appRemote;
|
||||||
const Misc = imports.src.misc;
|
|
||||||
|
|
||||||
const ID_POSTFIX = 'Remote';
|
|
||||||
|
|
||||||
Misc.clapperPath = `${pkg.datadir}/${Misc.appId}`;
|
|
||||||
Misc.appId += '.' + ID_POSTFIX;
|
|
||||||
|
|
||||||
function main(argv)
|
function main(argv)
|
||||||
{
|
{
|
||||||
|
55
src/misc.js
55
src/misc.js
@@ -10,8 +10,6 @@ var subsMimes = [
|
|||||||
'text/x-ssa',
|
'text/x-ssa',
|
||||||
];
|
];
|
||||||
|
|
||||||
var clapperPath = null;
|
|
||||||
|
|
||||||
var settings = new Gio.Settings({
|
var settings = new Gio.Settings({
|
||||||
schema_id: appId,
|
schema_id: appId,
|
||||||
});
|
});
|
||||||
@@ -30,13 +28,41 @@ const subsKeys = Object.keys(subsTitles);
|
|||||||
|
|
||||||
let inhibitCookie;
|
let inhibitCookie;
|
||||||
|
|
||||||
function getClapperPath()
|
function getResourceUri(path)
|
||||||
{
|
{
|
||||||
return (clapperPath)
|
/* TODO: support gresources */
|
||||||
? clapperPath
|
let res = `file://${pkg.pkgdatadir}/${path}`;
|
||||||
: (pkg)
|
|
||||||
? `${pkg.datadir}/${pkg.name}`
|
debug(`importing ${res}`);
|
||||||
: '.';
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getBuilderForName(name)
|
||||||
|
{
|
||||||
|
const uri = getResourceUri(`ui/${name}`);
|
||||||
|
|
||||||
|
if(uri.startsWith('resource'))
|
||||||
|
return Gtk.Builder.new_from_resource(uri.substring(11));
|
||||||
|
|
||||||
|
return Gtk.Builder.new_from_file(uri.substring(7));
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadCustomCss()
|
||||||
|
{
|
||||||
|
const uri = getResourceUri(`css/styles.css`);
|
||||||
|
const cssProvider = new Gtk.CssProvider();
|
||||||
|
|
||||||
|
if(uri.startsWith('resource'))
|
||||||
|
cssProvider.load_from_resource(uri);
|
||||||
|
else
|
||||||
|
cssProvider.load_from_path(uri.substring(7));
|
||||||
|
|
||||||
|
Gtk.StyleContext.add_provider_for_display(
|
||||||
|
Gdk.Display.get_default(),
|
||||||
|
cssProvider,
|
||||||
|
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getClapperThemeIconUri()
|
function getClapperThemeIconUri()
|
||||||
@@ -101,19 +127,6 @@ function getSubsTitle(infoTitle)
|
|||||||
return (found) ? subsTitles[found] : null;
|
return (found) ? subsTitles[found] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadCustomCss()
|
|
||||||
{
|
|
||||||
const clapperPath = getClapperPath();
|
|
||||||
const cssProvider = new Gtk.CssProvider();
|
|
||||||
|
|
||||||
cssProvider.load_from_path(`${clapperPath}/css/styles.css`);
|
|
||||||
Gtk.StyleContext.add_provider_for_display(
|
|
||||||
Gdk.Display.get_default(),
|
|
||||||
cssProvider,
|
|
||||||
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function setAppInhibit(isInhibit, window)
|
function setAppInhibit(isInhibit, window)
|
||||||
{
|
{
|
||||||
let isInhibited = false;
|
let isInhibited = false;
|
||||||
|
@@ -428,7 +428,7 @@ class ClapperPrefsPluginExpander extends Adw.ExpanderRow
|
|||||||
|
|
||||||
let PrefsPluginRankingSubpage = GObject.registerClass({
|
let PrefsPluginRankingSubpage = GObject.registerClass({
|
||||||
GTypeName: 'ClapperPrefsPluginRankingSubpage',
|
GTypeName: 'ClapperPrefsPluginRankingSubpage',
|
||||||
Template: `file://${Misc.getClapperPath()}/ui/preferences-plugin-ranking-subpage.ui`,
|
Template: Misc.getResourceUri('ui/preferences-plugin-ranking-subpage.ui'),
|
||||||
InternalChildren: ['decoders_group'],
|
InternalChildren: ['decoders_group'],
|
||||||
},
|
},
|
||||||
class ClapperPrefsPluginRankingSubpage extends Gtk.Box
|
class ClapperPrefsPluginRankingSubpage extends Gtk.Box
|
||||||
@@ -506,7 +506,7 @@ class ClapperPrefsPluginRankingSubpage extends Gtk.Box
|
|||||||
|
|
||||||
var PrefsWindow = GObject.registerClass({
|
var PrefsWindow = GObject.registerClass({
|
||||||
GTypeName: 'ClapperPrefsWindow',
|
GTypeName: 'ClapperPrefsWindow',
|
||||||
Template: `file://${Misc.getClapperPath()}/ui/preferences-window.ui`,
|
Template: Misc.getResourceUri('ui/preferences-window.ui'),
|
||||||
},
|
},
|
||||||
class ClapperPrefsWindow extends Adw.PreferencesWindow
|
class ClapperPrefsWindow extends Adw.PreferencesWindow
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user