forked from ignaci0/appimage-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.js
More file actions
64 lines (54 loc) · 2.39 KB
/
extension.js
File metadata and controls
64 lines (54 loc) · 2.39 KB
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
59
60
61
62
63
64
import {Extension} from 'resource:///org/gnome/shell/extensions/extension.js';
import Gio from 'gi://Gio';
import GLib from 'gi://GLib';
import {FileMonitor} from './fileMonitor.js';
import {AppImageManager} from './appImageManager.js';
import {LauncherService} from './launcherService.js';
import {SettingsManager} from './settingsManager.js';
import { log, logError } from './logger.js';
export default class AppImageManagerExtension extends Extension {
constructor(metadata) {
super(metadata);
}
async enable() {
log(`Enabling ${this.metadata.name} extension`);
this._settingsManager = new SettingsManager(this);
this._fileMonitor = new FileMonitor();
this._appImageManager = new AppImageManager(this._fileMonitor);
this._launcherService = new LauncherService();
let monitoredDirectory = this._settingsManager.getMonitoredDirectory();
await this._appImageManager.rescan(monitoredDirectory);
this._fileMonitor.startMonitoring(
monitoredDirectory,
(filePath) => {
this._appImageManager.addAppImage(filePath);
},
(filePath) => {
this._appImageManager.removeAppImage(filePath);
}
);
}
disable() {
log(`Disabling ${this.metadata.name} extension`);
this._fileMonitor.stopMonitoring();
let monitoredDirectory = this._settingsManager.getMonitoredDirectory();
let dir = Gio.File.new_for_path(monitoredDirectory);
if (dir.query_exists(null)) {
let enumerator = dir.enumerate_children('standard::name,standard::type', Gio.FileQueryInfoFlags.NONE, null);
let fileInfo;
while ((fileInfo = enumerator.next_file(null)) !== null) {
let child = dir.get_child(fileInfo.get_name());
if (fileInfo.get_file_type() === Gio.FileType.REGULAR && this._appImageManager.isAppImage(child.get_path())) {
let fileName = GLib.path_get_basename(child.get_path());
let appImageName = fileName.replace(/\.AppImage$/, '');
this._launcherService.deleteLauncher(appImageName);
}
}
enumerator.close(null);
}
this._launcherService = null;
this._appImageManager = null;
this._fileMonitor = null;
this._settingsManager = null;
}
}