mirror of
https://github.com/Rafostar/clapper.git
synced 2025-08-29 15:22:11 +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;
|
||||
case 'shortcuts':
|
||||
if(!window.get_help_overlay()) {
|
||||
const clapperPath = Misc.getClapperPath();
|
||||
const helpBuilder = Gtk.Builder.new_from_file(
|
||||
`${clapperPath}/ui/help-overlay.ui`
|
||||
);
|
||||
const helpBuilder = Misc.getBuilderForName('help-overlay.ui');
|
||||
window.set_help_overlay(helpBuilder.get_object('help_overlay'));
|
||||
}
|
||||
clapperWidget.activate_action('win.show-help-overlay', null);
|
||||
|
@@ -60,7 +60,7 @@ class ClapperIconToggleButton extends CustomButton
|
||||
|
||||
var PopoverSeparator = GObject.registerClass({
|
||||
GTypeName: 'ClapperPopoverSeparator',
|
||||
Template: `file://${Misc.getClapperPath()}/ui/popover-separator.ui`,
|
||||
Template: Misc.getResourceUri('ui/popover-separator.ui'),
|
||||
InternalChildren: ['middle_label'],
|
||||
Properties: {
|
||||
'label': GObject.ParamSpec.string(
|
||||
@@ -138,7 +138,7 @@ class ClapperPopoverButtonBase extends Gtk.MenuButton
|
||||
|
||||
var ElapsedTimeButton = GObject.registerClass({
|
||||
GTypeName: 'ClapperElapsedTimeButton',
|
||||
Template: `file://${Misc.getClapperPath()}/ui/elapsed-time-button.ui`,
|
||||
Template: Misc.getResourceUri('ui/elapsed-time-button.ui'),
|
||||
Children: ['scrolledWindow', 'speedScale'],
|
||||
},
|
||||
class ClapperElapsedTimeButton extends PopoverButtonBase
|
||||
@@ -177,7 +177,7 @@ class ClapperElapsedTimeButton extends PopoverButtonBase
|
||||
|
||||
var TrackSelectButton = GObject.registerClass({
|
||||
GTypeName: 'ClapperTrackSelectButton',
|
||||
Template: `file://${Misc.getClapperPath()}/ui/track-select-button.ui`,
|
||||
Template: Misc.getResourceUri('ui/track-select-button.ui'),
|
||||
Children: ['popoverBox'],
|
||||
InternalChildren: ['scrolled_window', 'decoder_separator'],
|
||||
},
|
||||
@@ -204,7 +204,7 @@ class ClapperTrackSelectButton extends PopoverButtonBase
|
||||
|
||||
var VolumeButton = GObject.registerClass({
|
||||
GTypeName: 'ClapperVolumeButton',
|
||||
Template: `file://${Misc.getClapperPath()}/ui/volume-button.ui`,
|
||||
Template: Misc.getResourceUri('ui/volume-button.ui'),
|
||||
Children: ['volumeScale'],
|
||||
},
|
||||
class ClapperVolumeButton extends PopoverButtonBase
|
||||
|
@@ -25,10 +25,7 @@ class ClapperHeaderBarBase extends Gtk.Box
|
||||
this.isMenuOnLeft = true;
|
||||
this.hasPipIcons = false;
|
||||
|
||||
const clapperPath = Misc.getClapperPath();
|
||||
const uiBuilder = Gtk.Builder.new_from_file(
|
||||
`${clapperPath}/ui/clapper.ui`
|
||||
);
|
||||
const uiBuilder = Misc.getBuilderForName('clapper.ui');
|
||||
|
||||
this.menuWidget = new Gtk.Box({
|
||||
orientation: Gtk.Orientation.HORIZONTAL,
|
||||
|
@@ -4,14 +4,11 @@ imports.gi.versions.Soup = '2.4';
|
||||
|
||||
pkg.initGettext();
|
||||
|
||||
const Misc = imports.src.misc;
|
||||
Misc.appId += '.Remote';
|
||||
|
||||
const { Gtk, Adw } = imports.gi;
|
||||
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)
|
||||
{
|
||||
|
55
src/misc.js
55
src/misc.js
@@ -10,8 +10,6 @@ var subsMimes = [
|
||||
'text/x-ssa',
|
||||
];
|
||||
|
||||
var clapperPath = null;
|
||||
|
||||
var settings = new Gio.Settings({
|
||||
schema_id: appId,
|
||||
});
|
||||
@@ -30,13 +28,41 @@ const subsKeys = Object.keys(subsTitles);
|
||||
|
||||
let inhibitCookie;
|
||||
|
||||
function getClapperPath()
|
||||
function getResourceUri(path)
|
||||
{
|
||||
return (clapperPath)
|
||||
? clapperPath
|
||||
: (pkg)
|
||||
? `${pkg.datadir}/${pkg.name}`
|
||||
: '.';
|
||||
/* TODO: support gresources */
|
||||
let res = `file://${pkg.pkgdatadir}/${path}`;
|
||||
|
||||
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()
|
||||
@@ -101,19 +127,6 @@ function getSubsTitle(infoTitle)
|
||||
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)
|
||||
{
|
||||
let isInhibited = false;
|
||||
|
@@ -428,7 +428,7 @@ class ClapperPrefsPluginExpander extends Adw.ExpanderRow
|
||||
|
||||
let PrefsPluginRankingSubpage = GObject.registerClass({
|
||||
GTypeName: 'ClapperPrefsPluginRankingSubpage',
|
||||
Template: `file://${Misc.getClapperPath()}/ui/preferences-plugin-ranking-subpage.ui`,
|
||||
Template: Misc.getResourceUri('ui/preferences-plugin-ranking-subpage.ui'),
|
||||
InternalChildren: ['decoders_group'],
|
||||
},
|
||||
class ClapperPrefsPluginRankingSubpage extends Gtk.Box
|
||||
@@ -506,7 +506,7 @@ class ClapperPrefsPluginRankingSubpage extends Gtk.Box
|
||||
|
||||
var PrefsWindow = GObject.registerClass({
|
||||
GTypeName: 'ClapperPrefsWindow',
|
||||
Template: `file://${Misc.getClapperPath()}/ui/preferences-window.ui`,
|
||||
Template: Misc.getResourceUri('ui/preferences-window.ui'),
|
||||
},
|
||||
class ClapperPrefsWindow extends Adw.PreferencesWindow
|
||||
{
|
||||
|
Reference in New Issue
Block a user