loginDialog: Support loading banner message from file
Support the new `banner-message-path` and `banner-message-source` settings, which allows loading the banner message from a path instead of GSettings. This is mainly useful for `/etc/motd` and similar mechanisms, to show the same message for both graphical and non-graphical logins. Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3558>
This commit is contained in:
parent
5f92c12c72
commit
a73a4f8455
@ -46,6 +46,8 @@ const _SCROLL_ANIMATION_TIME = 500;
|
|||||||
const _TIMED_LOGIN_IDLE_THRESHOLD = 5.0;
|
const _TIMED_LOGIN_IDLE_THRESHOLD = 5.0;
|
||||||
const _CONFLICTING_SESSION_DIALOG_TIMEOUT = 60;
|
const _CONFLICTING_SESSION_DIALOG_TIMEOUT = 60;
|
||||||
|
|
||||||
|
Gio._promisify(Gio.File.prototype, 'load_contents_async');
|
||||||
|
|
||||||
export const UserListItem = GObject.registerClass({
|
export const UserListItem = GObject.registerClass({
|
||||||
Signals: {'activate': {}},
|
Signals: {'activate': {}},
|
||||||
}, class UserListItem extends St.Button {
|
}, class UserListItem extends St.Button {
|
||||||
@ -508,6 +510,16 @@ export const LoginDialog = GObject.registerClass({
|
|||||||
() => this._updateBanner().catch(logError));
|
() => this._updateBanner().catch(logError));
|
||||||
this._settings.connect(`changed::${GdmUtil.BANNER_MESSAGE_TEXT_KEY}`,
|
this._settings.connect(`changed::${GdmUtil.BANNER_MESSAGE_TEXT_KEY}`,
|
||||||
() => this._updateBanner().catch(logError));
|
() => this._updateBanner().catch(logError));
|
||||||
|
this._settings.connect(`changed::${GdmUtil.BANNER_MESSAGE_SOURCE_KEY}`,
|
||||||
|
() => {
|
||||||
|
if (this._updateBannerMessageFile())
|
||||||
|
this._updateBanner().catch(logError);
|
||||||
|
});
|
||||||
|
this._settings.connect(`changed::${GdmUtil.BANNER_MESSAGE_PATH_KEY}`,
|
||||||
|
() => {
|
||||||
|
if (this._updateBannerMessageFile())
|
||||||
|
this._updateBanner().catch(logError);
|
||||||
|
});
|
||||||
this._settings.connect(`changed::${GdmUtil.DISABLE_USER_LIST_KEY}`,
|
this._settings.connect(`changed::${GdmUtil.DISABLE_USER_LIST_KEY}`,
|
||||||
this._updateDisableUserList.bind(this));
|
this._updateDisableUserList.bind(this));
|
||||||
this._settings.connect(`changed::${GdmUtil.LOGO_KEY}`,
|
this._settings.connect(`changed::${GdmUtil.LOGO_KEY}`,
|
||||||
@ -576,6 +588,8 @@ export const LoginDialog = GObject.registerClass({
|
|||||||
this._bannerLabel.clutter_text.line_wrap = true;
|
this._bannerLabel.clutter_text.line_wrap = true;
|
||||||
this._bannerLabel.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
|
this._bannerLabel.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
|
||||||
bannerBox.add_child(this._bannerLabel);
|
bannerBox.add_child(this._bannerLabel);
|
||||||
|
|
||||||
|
this._updateBannerMessageFile();
|
||||||
this._updateBanner().catch(logError);
|
this._updateBanner().catch(logError);
|
||||||
|
|
||||||
this._sessionMenuButton = new SessionMenuButton();
|
this._sessionMenuButton = new SessionMenuButton();
|
||||||
@ -873,13 +887,48 @@ export const LoginDialog = GObject.registerClass({
|
|||||||
this._authPrompt.cancelButton.visible = cancelVisible;
|
this._authPrompt.cancelButton.visible = cancelVisible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_updateBannerMessageFile() {
|
||||||
|
const path = this._settings.get_string(GdmUtil.BANNER_MESSAGE_SOURCE_KEY) === 'file'
|
||||||
|
? this._settings.get_string(GdmUtil.BANNER_MESSAGE_PATH_KEY)
|
||||||
|
: null;
|
||||||
|
const file = path
|
||||||
|
? Gio.File.new_for_path(path)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
if (!file && !this._bannerMessageFile)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (file && this._bannerMessageFile && this._bannerMessageFile.equal(file))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
this._bannerMessageMonitor?.disconnectObject(this);
|
||||||
|
this._bannerMessageMonitor = null;
|
||||||
|
|
||||||
|
this._bannerMessageFile = file;
|
||||||
|
|
||||||
|
if (file) {
|
||||||
|
this._bannerMessageMonitor = file.monitor_file(Gio.FileMonitorFlags.NONE, null);
|
||||||
|
this._bannerMessageMonitor.connectObject(
|
||||||
|
'changed', () => this._updateBanner().catch(logError), this);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
async _getBannerText() {
|
async _getBannerText() {
|
||||||
const enabled = this._settings.get_boolean(GdmUtil.BANNER_MESSAGE_KEY);
|
const enabled = this._settings.get_boolean(GdmUtil.BANNER_MESSAGE_KEY);
|
||||||
if (!enabled)
|
if (!enabled)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
// placeholder
|
if (this._bannerMessageFile) {
|
||||||
await false;
|
try {
|
||||||
|
const [contents] = await this._bannerMessageFile.load_contents_async(null);
|
||||||
|
return new TextDecoder().decode(contents);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(`Failed to read banner from ${this._bannerMessageFile.get_path()}: ${e.message}`);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return this._settings.get_string(GdmUtil.BANNER_MESSAGE_TEXT_KEY);
|
return this._settings.get_string(GdmUtil.BANNER_MESSAGE_TEXT_KEY);
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,9 @@ export const PASSWORD_AUTHENTICATION_KEY = 'enable-password-authentication';
|
|||||||
export const FINGERPRINT_AUTHENTICATION_KEY = 'enable-fingerprint-authentication';
|
export const FINGERPRINT_AUTHENTICATION_KEY = 'enable-fingerprint-authentication';
|
||||||
export const SMARTCARD_AUTHENTICATION_KEY = 'enable-smartcard-authentication';
|
export const SMARTCARD_AUTHENTICATION_KEY = 'enable-smartcard-authentication';
|
||||||
export const BANNER_MESSAGE_KEY = 'banner-message-enable';
|
export const BANNER_MESSAGE_KEY = 'banner-message-enable';
|
||||||
|
export const BANNER_MESSAGE_SOURCE_KEY = 'banner-message-source';
|
||||||
export const BANNER_MESSAGE_TEXT_KEY = 'banner-message-text';
|
export const BANNER_MESSAGE_TEXT_KEY = 'banner-message-text';
|
||||||
|
export const BANNER_MESSAGE_PATH_KEY = 'banner-message-path';
|
||||||
export const ALLOWED_FAILURES_KEY = 'allowed-failures';
|
export const ALLOWED_FAILURES_KEY = 'allowed-failures';
|
||||||
|
|
||||||
export const LOGO_KEY = 'logo';
|
export const LOGO_KEY = 'logo';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user