.gitlab
.gitlab-ci
.settings
data
docs
js
dbusServices
extensions
gdm
misc
portalHelper
ui
components
status
accessibility.js
autoRotate.js
backgroundApps.js
backlight.js
bluetooth.js
brightness.js
camera.js
darkMode.js
dwellClick.js
keyboard.js
location.js
network.js
nightLight.js
powerProfiles.js
remoteAccess.js
rfkill.js
system.js
thunderbolt.js
volume.js
accessDialog.js
altTab.js
animation.js
appDisplay.js
appFavorites.js
appMenu.js
audioDeviceSelection.js
background.js
backgroundMenu.js
barLevel.js
boxpointer.js
calendar.js
checkBox.js
closeDialog.js
components.js
ctrlAltTab.js
dash.js
dateMenu.js
dialog.js
dnd.js
edgeDragAction.js
endSessionDialog.js
environment.js
extensionDownloader.js
extensionSystem.js
focusCaretTracker.js
grabHelper.js
ibusCandidatePopup.js
iconGrid.js
inhibitShortcutsDialog.js
init.js
kbdA11yDialog.js
keyboard.js
layout.js
lightbox.js
listModes.js
locatePointer.js
lookingGlass.js
magnifier.js
main.js
messageList.js
messageTray.js
modalDialog.js
mpris.js
notificationDaemon.js
osdMonitorLabeler.js
osdWindow.js
overview.js
overviewControls.js
padOsd.js
pageIndicators.js
panel.js
panelMenu.js
pointerA11yTimeout.js
pointerWatcher.js
popupMenu.js
quickSettings.js
remoteSearch.js
ripples.js
runDialog.js
screenShield.js
screenshot.js
scripting.js
search.js
searchController.js
sessionMode.js
shellDBus.js
shellEntry.js
shellMountOperation.js
slider.js
swipeTracker.js
switchMonitor.js
switcherPopup.js
unlockDialog.js
userWidget.js
welcomeDialog.js
windowAttentionHandler.js
windowManager.js
windowMenu.js
windowPreview.js
workspace.js
workspaceAnimation.js
workspaceSwitcherPopup.js
workspaceThumbnail.js
workspacesView.js
xdndHandler.js
js-resources.gresource.xml
meson.build
portal-resources.gresource.xml
lint
man
meson
po
src
subprojects
tests
tools
.editorconfig
.eslintrc.yml
.gitignore
.gitlab-ci.yml
.gitmodules
.jscheckignore
COPYING
NEWS
README.md
config.h.meson
gnome-shell.doap
meson.build
meson_options.txt
142 lines
4.1 KiB
JavaScript
142 lines
4.1 KiB
JavaScript
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
|
|
|
import Gio from 'gi://Gio';
|
|
import GLib from 'gi://GLib';
|
|
import GObject from 'gi://GObject';
|
|
|
|
import {QuickToggle, SystemIndicator} from '../quickSettings.js';
|
|
|
|
import {loadInterfaceXML} from '../../misc/fileUtils.js';
|
|
|
|
const BUS_NAME = 'org.gnome.SettingsDaemon.Rfkill';
|
|
const OBJECT_PATH = '/org/gnome/SettingsDaemon/Rfkill';
|
|
|
|
const RfkillManagerInterface = loadInterfaceXML('org.gnome.SettingsDaemon.Rfkill');
|
|
const rfkillManagerInfo = Gio.DBusInterfaceInfo.new_for_xml(RfkillManagerInterface);
|
|
|
|
const RfkillManager = GObject.registerClass({
|
|
Properties: {
|
|
'airplane-mode': GObject.ParamSpec.boolean(
|
|
'airplane-mode', '', '',
|
|
GObject.ParamFlags.READWRITE,
|
|
false),
|
|
'hw-airplane-mode': GObject.ParamSpec.boolean(
|
|
'hw-airplane-mode', '', '',
|
|
GObject.ParamFlags.READABLE,
|
|
false),
|
|
'show-airplane-mode': GObject.ParamSpec.boolean(
|
|
'show-airplane-mode', '', '',
|
|
GObject.ParamFlags.READABLE,
|
|
false),
|
|
},
|
|
}, class RfkillManager extends GObject.Object {
|
|
constructor() {
|
|
super();
|
|
|
|
this._proxy = new Gio.DBusProxy({
|
|
g_connection: Gio.DBus.session,
|
|
g_name: BUS_NAME,
|
|
g_object_path: OBJECT_PATH,
|
|
g_interface_name: rfkillManagerInfo.name,
|
|
g_interface_info: rfkillManagerInfo,
|
|
});
|
|
this._proxy.connect('g-properties-changed', this._changed.bind(this));
|
|
this._proxy.init_async(GLib.PRIORITY_DEFAULT, null)
|
|
.catch(e => console.error(e.message));
|
|
}
|
|
|
|
/* eslint-disable camelcase */
|
|
get airplane_mode() {
|
|
return this._proxy.AirplaneMode;
|
|
}
|
|
|
|
set airplane_mode(v) {
|
|
this._proxy.AirplaneMode = v;
|
|
}
|
|
|
|
get hw_airplane_mode() {
|
|
return this._proxy.HardwareAirplaneMode;
|
|
}
|
|
|
|
get show_airplane_mode() {
|
|
return this._proxy.HasAirplaneMode && this._proxy.ShouldShowAirplaneMode;
|
|
}
|
|
/* eslint-enable camelcase */
|
|
|
|
_changed(proxy, properties) {
|
|
for (const prop in properties.deepUnpack()) {
|
|
switch (prop) {
|
|
case 'AirplaneMode':
|
|
this.notify('airplane-mode');
|
|
break;
|
|
case 'HardwareAirplaneMode':
|
|
this.notify('hw-airplane-mode');
|
|
break;
|
|
case 'HasAirplaneMode':
|
|
case 'ShouldShowAirplaneMode':
|
|
this.notify('show-airplane-mode');
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
let _manager;
|
|
|
|
/**
|
|
* @returns {RfkillManager}
|
|
*/
|
|
export function getRfkillManager() {
|
|
if (_manager != null)
|
|
return _manager;
|
|
|
|
_manager = new RfkillManager();
|
|
return _manager;
|
|
}
|
|
|
|
const RfkillToggle = GObject.registerClass(
|
|
class RfkillToggle extends QuickToggle {
|
|
_init() {
|
|
super._init({
|
|
title: _('Airplane Mode'),
|
|
iconName: 'airplane-mode-symbolic',
|
|
});
|
|
|
|
this._manager = getRfkillManager();
|
|
this._manager.bind_property('show-airplane-mode',
|
|
this, 'visible',
|
|
GObject.BindingFlags.SYNC_CREATE);
|
|
this._manager.bind_property('airplane-mode',
|
|
this, 'checked',
|
|
GObject.BindingFlags.SYNC_CREATE);
|
|
|
|
this.connect('clicked',
|
|
() => (this._manager.airplaneMode = !this._manager.airplaneMode));
|
|
}
|
|
});
|
|
|
|
export const Indicator = GObject.registerClass(
|
|
class Indicator extends SystemIndicator {
|
|
_init() {
|
|
super._init();
|
|
|
|
this._indicator = this._addIndicator();
|
|
this._indicator.icon_name = 'airplane-mode-symbolic';
|
|
|
|
this._rfkillToggle = new RfkillToggle();
|
|
this._rfkillToggle.connectObject(
|
|
'notify::visible', () => this._sync(),
|
|
'notify::checked', () => this._sync(),
|
|
this);
|
|
this.quickSettingsItems.push(this._rfkillToggle);
|
|
|
|
this._sync();
|
|
}
|
|
|
|
_sync() {
|
|
// Only show indicator when airplane mode is on
|
|
const {visible, checked} = this._rfkillToggle;
|
|
this._indicator.visible = visible && checked;
|
|
}
|
|
});
|