forked from rhinstaller/anaconda
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Timezone module DBus API access for the Web UI
Provide access for the necessary DBus calls from the Date and time screen on the Web UI.
- Loading branch information
Showing
1 changed file
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
/* | ||
* Copyright (C) 2023 Red Hat, Inc. | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation; either version 2.1 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with This program; If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import cockpit from "cockpit"; | ||
|
||
export class TimezoneClient { | ||
constructor (address) { | ||
if (TimezoneClient.instance) { | ||
return TimezoneClient.instance; | ||
} | ||
TimezoneClient.instance = this; | ||
|
||
this.client = cockpit.dbus( | ||
"org.fedoraproject.Anaconda.Modules.Timezone", | ||
{ superuser: "try", bus: "none", address } | ||
); | ||
} | ||
|
||
init () { | ||
this.client.addEventListener("close", () => console.error("Timezone client closed")); | ||
} | ||
} | ||
|
||
/** | ||
* @returns {Promise} The current system Timezone | ||
*/ | ||
export const getTimezone = () => { | ||
return ( | ||
new TimezoneClient().client.call( | ||
"/org/fedoraproject/Anaconda/Modules/Timezone", | ||
"org.freedesktop.DBus.Properties", | ||
"Get", | ||
[ | ||
"org.fedoraproject.Anaconda.Modules.Timezone", | ||
"Timezone" | ||
] | ||
) | ||
.then(res => res[0].v) | ||
); | ||
}; | ||
|
||
/** | ||
* @param {string} timezone Timezone id | ||
*/ | ||
export const setTimezone = ({ timezone }) => { | ||
return new TimezoneClient().client.call( | ||
"/org/fedoraproject/Anaconda/Modules/Timezone", | ||
"org.freedesktop.DBus.Properties", | ||
"Set", | ||
[ | ||
"org.fedoraproject.Anaconda.Modules.Timezone", | ||
"Timezone", | ||
cockpit.variant("s", timezone) | ||
] | ||
); | ||
}; | ||
|
||
/** | ||
* @returns {Promise} Resolves a list of timezones | ||
*/ | ||
export const getTimezones = () => { | ||
return new TimezoneClient().client.call( | ||
"/org/fedoraproject/Anaconda/Modules/Timezone", | ||
"org.fedoraproject.Anaconda.Modules.Timezone", | ||
"GetTimezones", [] | ||
); | ||
}; | ||
|
||
/** | ||
* @returns {Promise} NTP enabled | ||
*/ | ||
export const getNTPEnabled = () => { | ||
return ( | ||
new TimezoneClient().client.call( | ||
"/org/fedoraproject/Anaconda/Modules/Timezone", | ||
"org.freedesktop.DBus.Properties", | ||
"Get", | ||
["org.fedoraproject.Anaconda.Modules.Timezone", "NTPEnabled"] | ||
) | ||
.then(res => res[0].v) | ||
); | ||
}; | ||
|
||
/** | ||
* @param {bool} enabled - enable/disable NTP | ||
* | ||
* @returns {Promise} FIXME: what does it return in this case ?? | ||
*/ | ||
|
||
export const setNTPEnabled = ({ enabled }) => { | ||
return ( | ||
new TimezoneClient().client.call( | ||
"/org/fedoraproject/Anaconda/Modules/Timezone", | ||
"org.freedesktop.DBus.Properties", | ||
"Set", | ||
[ | ||
"org.fedoraproject.Anaconda.Modules.Timezone", | ||
"NTPEnabled", | ||
cockpit.variant("b", enabled) | ||
] | ||
) | ||
); | ||
}; | ||
|
||
/** | ||
* @returns {Promise} NTP sync status | ||
*/ | ||
export const getNTPStatus = () => { | ||
return ( | ||
new TimezoneClient().client.call( | ||
"/org/fedoraproject/Anaconda/Modules/Timezone", | ||
"org.freedesktop.DBus.Properties", | ||
"Get", | ||
["org.fedoraproject.Anaconda.Modules.Timezone", "NTPStatus"] | ||
) | ||
.then(res => res[0].v) | ||
); | ||
}; | ||
|
||
/** | ||
* @returns {Promise} Resolves the DBus path to the partitioning | ||
*/ | ||
export const getSystemDateTime = () => { | ||
return new TimezoneClient().client.call( | ||
"/org/fedoraproject/Anaconda/Modules/Timezone", | ||
"org.fedoraproject.Anaconda.Modules.Timezone", | ||
"GetSystemDateTime", [] | ||
); | ||
}; | ||
|
||
/** | ||
* @param {string} datetimespec date time specification in ISO 8601 format | ||
* | ||
* @returns {Promise} FIXME: what does it return in this case ?? | ||
*/ | ||
export const setSystemDateTime = ({ datetimespec }) => { | ||
return new TimezoneClient().client.call( | ||
"/org/fedoraproject/Anaconda/Modules/Timezone", | ||
"org.fedoraproject.Anaconda.Modules.Timezone", | ||
"SetSystemDateTime", [datetimespec] | ||
); | ||
}; |