blob: 701da6a18f196f653123ebbec3948d6d47f2394a (
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
59
60
61
62
63
64
|
// SPDX-FileCopyrightText: 2023 Deminder <tremminder@gmail.com>
// SPDX-License-Identifier: GPL-3.0-or-later
import GLib from 'gi://GLib';
import Gio from 'gi://Gio';
import { gettext as _ } from './translation.js';
import { execCheck, installedScriptPath } from '../dbus-service/control.js';
import { logDebug } from './util.js';
export class Install {
destroy() {
if (this.installCancel !== undefined) {
this.installCancel.cancel();
}
this.installCancel = undefined;
}
/**
* @param installerScriptPath
* @param action
* @param logInstall
*/
async installAction(installerScriptPath, action, logInstall) {
const label = this.actionLabel(action);
if (this.installCancel !== undefined) {
logDebug(`Trigger cancel install. ${label}`);
this.installCancel.cancel();
} else {
logDebug(`Trigger ${action} action.`);
this.installCancel = new Gio.Cancellable();
logInstall(`[${_('START')} ${label}]`);
try {
const user = GLib.get_user_name();
logDebug(`? installer.sh --tool-user ${user} ${action}`);
await execCheck(
['pkexec', installerScriptPath, '--tool-user', user, action],
this.installCancel,
false,
logInstall
);
logInstall(`[${_('END')} ${label}]`);
} catch (err) {
logInstall(`[${_('FAIL')} ${label}]\n# ${err}`);
console.error(err, 'InstallError');
} finally {
this.installCancel = undefined;
}
}
}
checkInstalled() {
const scriptPath = installedScriptPath();
const isScriptInstalled = scriptPath !== null;
if (isScriptInstalled) {
logDebug(`Existing installation at: ${scriptPath}`);
}
return isScriptInstalled;
}
actionLabel(action) {
return { install: _('install'), uninstall: _('uninstall') }[action];
}
}
|