keeweb/app/scripts/comp/app/app-rights-checker.js

81 lines
2.3 KiB
JavaScript
Raw Normal View History

2019-09-15 14:16:32 +02:00
import { Launcher } from 'comp/launcher';
import { Alerts } from 'comp/ui/alerts';
import { AppSettingsModel } from 'models/app-settings-model';
import { Features } from 'util/features';
import { Locale } from 'util/locale';
const AppRightsChecker = {
AppPath: '/Applications/KeeWeb.app',
init() {
2019-09-15 08:11:11 +02:00
if (!Features.isDesktop || !Features.isMac) {
return;
}
2019-09-17 19:50:42 +02:00
if (AppSettingsModel.skipFolderRightsWarning) {
return;
}
if (!Launcher.getAppPath().startsWith(this.AppPath)) {
return;
}
2020-06-01 16:53:51 +02:00
this.needRunInstaller((needRun) => {
if (needRun) {
this.showAlert();
this.runInstaller();
}
});
},
needRunInstaller(callback) {
2020-06-01 16:53:51 +02:00
Launcher.statFile(this.AppPath, (stat) => {
const folderIsRoot = stat && stat.uid === 0;
callback(!folderIsRoot);
});
},
showAlert() {
2017-06-05 11:32:18 +02:00
const command = 'sudo chown -R root ' + this.AppPath;
this.alert = Alerts.alert({
icon: 'lock',
header: Locale.appRightsAlert,
2019-08-16 23:05:39 +02:00
body:
2020-04-23 19:55:52 +02:00
Locale.appRightsAlertBody1.replace('{}', this.AppPath) +
'\n' +
Locale.appRightsAlertBody2,
pre: command,
2019-08-18 08:05:38 +02:00
buttons: [
{ result: 'skip', title: Locale.alertDoNotAsk, error: true },
Alerts.buttons.ok
],
2020-06-01 16:53:51 +02:00
success: (result) => {
if (result === 'skip') {
this.dontAskAnymore();
}
this.alert = null;
}
});
},
runInstaller() {
Launcher.spawn({
2019-08-16 23:05:39 +02:00
cmd: this.AppPath + '/Contents/Installer/KeeWeb Installer.app/Contents/MacOS/applet',
complete: () => {
2020-06-01 16:53:51 +02:00
this.needRunInstaller((needRun) => {
if (this.alert && !needRun) {
this.alert.closeWithResult('cancel');
}
});
}
});
},
dontAskAnymore() {
2020-06-01 16:53:51 +02:00
this.needRunInstaller((needRun) => {
if (needRun) {
2019-09-17 19:50:42 +02:00
AppSettingsModel.skipFolderRightsWarning = true;
}
});
}
};
2019-09-15 14:16:32 +02:00
export { AppRightsChecker };