Open new file in the same window. Closes #31

This commit is contained in:
Rafostar
2020-12-24 00:23:49 +01:00
parent f2d8d8ad4f
commit 6afbbc767a
6 changed files with 63 additions and 35 deletions

View File

@@ -1,4 +1,4 @@
const { GObject } = imports.gi; const { Gio, GObject } = imports.gi;
const { AppBase } = imports.clapper_src.appBase; const { AppBase } = imports.clapper_src.appBase;
const { HeaderBar } = imports.clapper_src.headerbar; const { HeaderBar } = imports.clapper_src.headerbar;
const { Widget } = imports.clapper_src.widget; const { Widget } = imports.clapper_src.widget;
@@ -9,6 +9,17 @@ let { debug } = Debug;
var App = GObject.registerClass( var App = GObject.registerClass(
class ClapperApp extends AppBase class ClapperApp extends AppBase
{ {
_init()
{
super._init();
this.set_flags(
this.get_flags()
| Gio.ApplicationFlags.HANDLES_OPEN
);
this.playlist = [];
}
vfunc_startup() vfunc_startup()
{ {
super.vfunc_startup(); super.vfunc_startup();
@@ -27,13 +38,22 @@ class ClapperApp extends AppBase
debug(`restored window size: ${size[0]}x${size[1]}`); 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) _onWindowShow(window)
{ {
super._onWindowShow(window); super._onWindowShow(window);
if(this.playlist.length) { if(!this.playlist.length)
let { player } = window.get_child(); return;
player.set_playlist(this.playlist);
} let { player } = window.get_child();
player.set_playlist(this.playlist);
} }
}); });

View File

@@ -9,15 +9,8 @@ let { settings } = Misc;
var AppBase = GObject.registerClass( var AppBase = GObject.registerClass(
class ClapperAppBase extends Gtk.Application class ClapperAppBase extends Gtk.Application
{ {
_init(opts) _init()
{ {
opts = opts || {};
let defaults = {
playlist: [],
};
Object.assign(this, defaults, opts);
super._init({ super._init({
application_id: Misc.appId, application_id: Misc.appId,
}); });
@@ -58,10 +51,7 @@ class ClapperAppBase extends Gtk.Application
{ {
super.vfunc_activate(); super.vfunc_activate();
if(!this.doneFirstActivate) this._handleAppStart();
this._onFirstActivate();
this.active_window.present();
} }
run(arr) run(arr)
@@ -69,6 +59,15 @@ class ClapperAppBase extends Gtk.Application
super.run(arr || []); super.run(arr || []);
} }
_handleAppStart()
{
if(this.doneFirstActivate)
return this._onWindowShow(this.active_window);
this._onFirstActivate();
this.active_window.present();
}
_onFirstActivate() _onFirstActivate()
{ {
let gtkSettings = Gtk.Settings.get_default(); let gtkSettings = Gtk.Settings.get_default();
@@ -89,6 +88,9 @@ class ClapperAppBase extends Gtk.Application
_onWindowShow(window) _onWindowShow(window)
{ {
if(!this.windowShowSignal)
return;
window.disconnect(this.windowShowSignal); window.disconnect(this.windowShowSignal);
this.windowShowSignal = null; this.windowShowSignal = null;
} }

View File

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

View File

@@ -1,6 +1,7 @@
imports.gi.versions.Gdk = '4.0'; imports.gi.versions.Gdk = '4.0';
imports.gi.versions.Gtk = '4.0'; imports.gi.versions.Gtk = '4.0';
const System = imports.system;
const { Gst } = imports.gi; const { Gst } = imports.gi;
const { App } = imports.clapper_src.app; const { App } = imports.clapper_src.app;
@@ -8,7 +9,5 @@ Gst.init(null);
function main() function main()
{ {
let clapper = new App({ new App().run([System.programInvocationName].concat(ARGV));
playlist: ARGV
}).run();
} }

View File

@@ -2,5 +2,5 @@ const { Daemon } = imports.clapper_src.daemon;
function main() function main()
{ {
new Daemon(ARGV[0]); new Daemon();
} }

View File

@@ -73,21 +73,27 @@ class ClapperPlayer extends PlayerBase
set_media(source) set_media(source)
{ {
if(!Gst.uri_is_valid(source)) let file;
source = Gst.filename_to_uri(source);
if(!source) if(source.get_path)
return debug('parsing source to URI failed'); 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') { debug(`parsed source to URI: ${source}`);
this.is_local_file = false;
return this.set_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)) { if(!file.query_exists(null)) {
debug(`file does not exist: ${source}`, 'LEVEL_WARNING'); debug(`file does not exist: ${source}`, 'LEVEL_WARNING');
this._trackId++; this._trackId++;
@@ -98,11 +104,12 @@ class ClapperPlayer extends PlayerBase
return this.set_media(this._playlist[this._trackId]); 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); return this.load_playlist_file(file);
this.is_local_file = true; this.is_local_file = true;
this.set_uri(source); this.set_uri(fileUri);
} }
load_playlist_file(file) load_playlist_file(file)