summaryrefslogtreecommitdiff
path: root/raveos-gnome-theme/theme-data/extensions/installed/ShutdownTimer@deminder/extension.js
blob: ffb9142f10989509f85027e413b1741b7c6932ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// SPDX-FileCopyrightText: 2023 Deminder <tremminder@gmail.com>, D. Neumann <neumann89@gmail.com>
// SPDX-License-Identifier: GPL-3.0-or-later

import { Extension } from 'resource:///org/gnome/shell/extensions/extension.js';

import { currentSessionMode } from './modules/session-mode-aware.js';
import { ShutdownTimerIndicator } from './modules/menu-item.js';
import { logDebug } from './modules/util.js';
import { addExternalIndicator } from './modules/quicksettings.js';
import { InjectionTracker } from './modules/injection.js';
import { ShutdownTimerDBus } from './dbus-service/shutdown-timer-dbus.js';

export default class ShutdownTimer extends Extension {
  #sdt = null;
  #disableTimestamp = 0;

  enable() {
    const settings = this.getSettings();

    if (!this.#disableTimestamp || Date.now() > this.#disableTimestamp + 100) {
      logDebug('[ENABLE] Clear shutdown schedule');
      settings.set_int('shutdown-timestamp-value', -1);
    }

    logDebug(`[ENABLE] '${currentSessionMode()}'`);
    this.#sdt = new ShutdownTimerDBus({ settings });

    const indicator = new ShutdownTimerIndicator({
      path: this.path,
      settings,
    });
    indicator.connect('open-preferences', () => this.openPreferences());

    // Add ShutdownTimer indicator to quicksettings menu
    this._tracker = new InjectionTracker();
    addExternalIndicator(this._tracker, indicator);

    this._indicator = indicator;

    logDebug(`[ENABLE-DONE] '${currentSessionMode()}'`);
  }

  disable() {
    // Extension should not be disabled during unlock-dialog`:
    // When the `unlock-dialog` is active, the quicksettings indicator and item
    // should remain visible.
    logDebug(`[DISABLE] '${currentSessionMode()}'`);
    this._tracker.clearAll();
    this._tracker = null;

    this._indicator.destroy();
    this._indicator = null;

    this.#sdt.destroy();
    this.#sdt = null;
    this.#disableTimestamp = Date.now();
  }
}