mirror of
https://github.com/Rafostar/clapper.git
synced 2025-08-30 16:02:00 +02:00
Major code cleanup
This commit is contained in:
51
clapper_src/misc.js
Normal file
51
clapper_src/misc.js
Normal file
@@ -0,0 +1,51 @@
|
||||
const { GstPlayer, Gtk } = imports.gi;
|
||||
const Debug = imports.clapper_src.debug;
|
||||
|
||||
let { debug } = Debug;
|
||||
let inhibitCookie;
|
||||
|
||||
function inhibitForState(state, window)
|
||||
{
|
||||
let isInhibited = false;
|
||||
let flags = Gtk.ApplicationInhibitFlags.SUSPEND
|
||||
| Gtk.ApplicationInhibitFlags.IDLE;
|
||||
|
||||
if(state === GstPlayer.PlayerState.PLAYING) {
|
||||
if(inhibitCookie)
|
||||
return;
|
||||
|
||||
let app = window.get_application();
|
||||
|
||||
inhibitCookie = app.inhibit(
|
||||
window,
|
||||
flags,
|
||||
'video is playing'
|
||||
);
|
||||
if(!inhibitCookie)
|
||||
debug(new Error('could not inhibit session!'));
|
||||
|
||||
isInhibited = (inhibitCookie > 0);
|
||||
}
|
||||
else {
|
||||
//if(!inhibitCookie)
|
||||
return;
|
||||
|
||||
/* Uninhibit seems to be broken as of GTK 3.99.2
|
||||
this.uninhibit(inhibitCookie);
|
||||
inhibitCookie = null;
|
||||
*/
|
||||
}
|
||||
|
||||
debug(`set prevent suspend to: ${isInhibited}`);
|
||||
}
|
||||
|
||||
function getFormatedTime(time)
|
||||
{
|
||||
let hours = ('0' + Math.floor(time / 3600)).slice(-2);
|
||||
time -= hours * 3600;
|
||||
let minutes = ('0' + Math.floor(time / 60)).slice(-2);
|
||||
time -= minutes * 60;
|
||||
let seconds = ('0' + Math.floor(time)).slice(-2);
|
||||
|
||||
return `${hours}:${minutes}:${seconds}`;
|
||||
}
|
Reference in New Issue
Block a user