| 1 |
/* exported FlatpakPersistentModel getDefault */ |
| 2 |
|
| 3 |
/* persistent.js |
| 4 |
* |
| 5 |
* Copyright 2020 Martin Abente Lahaye |
| 6 |
* |
| 7 |
* This program is free software: you can redistribute it and/or modify |
| 8 |
* it under the terms of the GNU General Public License as published by |
| 9 |
* the Free Software Foundation, either version 3 of the License, or |
| 10 |
* (at your option) any later version. |
| 11 |
* |
| 12 |
* This program is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License |
| 18 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 |
*/ |
| 20 |
|
| 21 |
const {GObject} = imports.gi; |
| 22 |
|
| 23 |
const {FlatpakSharedModel} = imports.models.shared; |
| 24 |
|
| 25 |
|
| 26 |
var FlatpakPersistentModel = GObject.registerClass({ |
| 27 |
GTypeName: 'FlatpakPersistentModel', |
| 28 |
}, class FlatpakPersistentModel extends FlatpakSharedModel { |
| 29 |
_init() { |
| 30 |
super._init({}); |
| 31 |
} |
| 32 |
|
| 33 |
getPermissions() { |
| 34 |
return { |
| 35 |
persistent: { |
| 36 |
supported: this._info.supports('0.4.0'), |
| 37 |
description: _('Files'), |
| 38 |
option: null, |
| 39 |
value: this.constructor.getDefault(), |
| 40 |
example: _('e.g. .thunderbird'), |
| 41 |
}, |
| 42 |
}; |
| 43 |
} |
| 44 |
|
| 45 |
static getGroup() { |
| 46 |
return 'Context'; |
| 47 |
} |
| 48 |
|
| 49 |
static getKey() { |
| 50 |
return 'persistent'; |
| 51 |
} |
| 52 |
|
| 53 |
static getStyle() { |
| 54 |
return 'persistent'; |
| 55 |
} |
| 56 |
|
| 57 |
static getTitle() { |
| 58 |
return 'Persistent'; |
| 59 |
} |
| 60 |
|
| 61 |
static getDescription() { |
| 62 |
return _('List of homedir-relative paths created in the sandbox'); |
| 63 |
} |
| 64 |
|
| 65 |
static getType() { |
| 66 |
return 'relativePath'; |
| 67 |
} |
| 68 |
|
| 69 |
static getDefault() { |
| 70 |
return ''; |
| 71 |
} |
| 72 |
|
| 73 |
getOptions() { // eslint-disable-line class-methods-use-this |
| 74 |
return null; |
| 75 |
} |
| 76 |
|
| 77 |
updateFromProxyProperty(property, value) { |
| 78 |
const originals = new Set([...this._originals, ...this._globals]); |
| 79 |
|
| 80 |
const overrides = new Set(this.constructor.deserialize(value) |
| 81 |
.filter(p => p.length !== 0) |
| 82 |
.filter(p => !originals.has(p))); |
| 83 |
|
| 84 |
this._overrides = overrides; |
| 85 |
} |
| 86 |
|
| 87 |
updateStatusProperty(proxy) { |
| 88 |
const values = proxy.persistent |
| 89 |
.split(';') |
| 90 |
.filter(p => p.length !== 0) |
| 91 |
.map(p => this._getStatusForPermission(p)); |
| 92 |
|
| 93 |
proxy.set_property('persistent-status', this.constructor.serialize(values)); |
| 94 |
} |
| 95 |
|
| 96 |
updateProxyProperty(proxy) { |
| 97 |
const paths = new Set([...this._originals, ...this._globals, ...this._overrides]); |
| 98 |
|
| 99 |
const persistent = [...paths].join(';'); |
| 100 |
|
| 101 |
proxy.set_property('persistent', persistent); |
| 102 |
} |
| 103 |
|
| 104 |
loadFromKeyFile(group, key, value, overrides, global) { |
| 105 |
if (value.length === 0) |
| 106 |
return; |
| 107 |
const set = this._findProperSet(overrides, global); |
| 108 |
set.add(value); |
| 109 |
} |
| 110 |
|
| 111 |
isOriginal(value) { |
| 112 |
const originals = new Set([...this._originals, ...this._globals]); |
| 113 |
return originals.has(value); |
| 114 |
} |
| 115 |
}); |
| 116 |
|
| 117 |
var getDefault = (function() { |
| 118 |
let instance; |
| 119 |
return function() { |
| 120 |
if (typeof instance === 'undefined') |
| 121 |
instance = new FlatpakPersistentModel(); |
| 122 |
return instance; |
| 123 |
}; |
| 124 |
}()); |