mirror of
https://github.com/Rafostar/clapper.git
synced 2025-08-31 08:21:59 +02:00
Open new file in the same window. Closes #31
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
const { GObject } = imports.gi;
|
||||
const { Gio, GObject } = imports.gi;
|
||||
const { AppBase } = imports.clapper_src.appBase;
|
||||
const { HeaderBar } = imports.clapper_src.headerbar;
|
||||
const { Widget } = imports.clapper_src.widget;
|
||||
@@ -9,6 +9,17 @@ let { debug } = Debug;
|
||||
var App = GObject.registerClass(
|
||||
class ClapperApp extends AppBase
|
||||
{
|
||||
_init()
|
||||
{
|
||||
super._init();
|
||||
|
||||
this.set_flags(
|
||||
this.get_flags()
|
||||
| Gio.ApplicationFlags.HANDLES_OPEN
|
||||
);
|
||||
this.playlist = [];
|
||||
}
|
||||
|
||||
vfunc_startup()
|
||||
{
|
||||
super.vfunc_startup();
|
||||
@@ -27,13 +38,22 @@ class ClapperApp extends AppBase
|
||||
debug(`restored window size: ${size[0]}x${size[1]}`);
|
||||
}
|
||||
|
||||
vfunc_open(files, hint)
|
||||
{
|
||||
super.vfunc_open(files, hint);
|
||||
|
||||
this.playlist = files;
|
||||
this._handleAppStart();
|
||||
}
|
||||
|
||||
_onWindowShow(window)
|
||||
{
|
||||
super._onWindowShow(window);
|
||||
|
||||
if(this.playlist.length) {
|
||||
let { player } = window.get_child();
|
||||
player.set_playlist(this.playlist);
|
||||
}
|
||||
if(!this.playlist.length)
|
||||
return;
|
||||
|
||||
let { player } = window.get_child();
|
||||
player.set_playlist(this.playlist);
|
||||
}
|
||||
});
|
||||
|
@@ -9,15 +9,8 @@ let { settings } = Misc;
|
||||
var AppBase = GObject.registerClass(
|
||||
class ClapperAppBase extends Gtk.Application
|
||||
{
|
||||
_init(opts)
|
||||
_init()
|
||||
{
|
||||
opts = opts || {};
|
||||
|
||||
let defaults = {
|
||||
playlist: [],
|
||||
};
|
||||
Object.assign(this, defaults, opts);
|
||||
|
||||
super._init({
|
||||
application_id: Misc.appId,
|
||||
});
|
||||
@@ -58,10 +51,7 @@ class ClapperAppBase extends Gtk.Application
|
||||
{
|
||||
super.vfunc_activate();
|
||||
|
||||
if(!this.doneFirstActivate)
|
||||
this._onFirstActivate();
|
||||
|
||||
this.active_window.present();
|
||||
this._handleAppStart();
|
||||
}
|
||||
|
||||
run(arr)
|
||||
@@ -69,6 +59,15 @@ class ClapperAppBase extends Gtk.Application
|
||||
super.run(arr || []);
|
||||
}
|
||||
|
||||
_handleAppStart()
|
||||
{
|
||||
if(this.doneFirstActivate)
|
||||
return this._onWindowShow(this.active_window);
|
||||
|
||||
this._onFirstActivate();
|
||||
this.active_window.present();
|
||||
}
|
||||
|
||||
_onFirstActivate()
|
||||
{
|
||||
let gtkSettings = Gtk.Settings.get_default();
|
||||
@@ -89,6 +88,9 @@ class ClapperAppBase extends Gtk.Application
|
||||
|
||||
_onWindowShow(window)
|
||||
{
|
||||
if(!this.windowShowSignal)
|
||||
return;
|
||||
|
||||
window.disconnect(this.windowShowSignal);
|
||||
this.windowShowSignal = null;
|
||||
}
|
||||
|
@@ -6,9 +6,9 @@ let { debug } = Debug;
|
||||
var Daemon = GObject.registerClass(
|
||||
class ClapperDaemon extends Gio.SubprocessLauncher
|
||||
{
|
||||
_init(port)
|
||||
_init()
|
||||
{
|
||||
port = port || 8080;
|
||||
let port = ARGV[0] || 8080;
|
||||
|
||||
/* FIXME: show output when debugging is on */
|
||||
const flags = Gio.SubprocessFlags.STDOUT_SILENCE
|
||||
|
@@ -1,6 +1,7 @@
|
||||
imports.gi.versions.Gdk = '4.0';
|
||||
imports.gi.versions.Gtk = '4.0';
|
||||
|
||||
const System = imports.system;
|
||||
const { Gst } = imports.gi;
|
||||
const { App } = imports.clapper_src.app;
|
||||
|
||||
@@ -8,7 +9,5 @@ Gst.init(null);
|
||||
|
||||
function main()
|
||||
{
|
||||
let clapper = new App({
|
||||
playlist: ARGV
|
||||
}).run();
|
||||
new App().run([System.programInvocationName].concat(ARGV));
|
||||
}
|
||||
|
@@ -2,5 +2,5 @@ const { Daemon } = imports.clapper_src.daemon;
|
||||
|
||||
function main()
|
||||
{
|
||||
new Daemon(ARGV[0]);
|
||||
new Daemon();
|
||||
}
|
||||
|
@@ -73,21 +73,27 @@ class ClapperPlayer extends PlayerBase
|
||||
|
||||
set_media(source)
|
||||
{
|
||||
if(!Gst.uri_is_valid(source))
|
||||
source = Gst.filename_to_uri(source);
|
||||
let file;
|
||||
|
||||
if(!source)
|
||||
return debug('parsing source to URI failed');
|
||||
if(source.get_path)
|
||||
file = source;
|
||||
else {
|
||||
if(!Gst.uri_is_valid(source))
|
||||
source = Gst.filename_to_uri(source);
|
||||
|
||||
debug(`parsed source to URI: ${source}`);
|
||||
if(!source)
|
||||
return debug('parsing source to URI failed');
|
||||
|
||||
if(Gst.Uri.get_protocol(source) !== 'file') {
|
||||
this.is_local_file = false;
|
||||
return this.set_uri(source);
|
||||
debug(`parsed source to URI: ${source}`);
|
||||
|
||||
if(Gst.Uri.get_protocol(source) !== 'file') {
|
||||
this.is_local_file = false;
|
||||
return this.set_uri(source);
|
||||
}
|
||||
|
||||
file = Gio.file_new_for_uri(source);
|
||||
}
|
||||
|
||||
let file = Gio.file_new_for_uri(source);
|
||||
|
||||
if(!file.query_exists(null)) {
|
||||
debug(`file does not exist: ${source}`, 'LEVEL_WARNING');
|
||||
this._trackId++;
|
||||
@@ -98,11 +104,12 @@ class ClapperPlayer extends PlayerBase
|
||||
return this.set_media(this._playlist[this._trackId]);
|
||||
}
|
||||
|
||||
if(file.get_path().endsWith('.claps'))
|
||||
let fileUri = file.get_uri();
|
||||
if(fileUri.endsWith('.claps'))
|
||||
return this.load_playlist_file(file);
|
||||
|
||||
this.is_local_file = true;
|
||||
this.set_uri(source);
|
||||
this.set_uri(fileUri);
|
||||
}
|
||||
|
||||
load_playlist_file(file)
|
||||
|
Reference in New Issue
Block a user