Skip to content

Commit

Permalink
webui: adding PRETTY_NAME to use in title instead of anaconda generic…
Browse files Browse the repository at this point in the history
… title
  • Loading branch information
acruzgon committed Jun 16, 2023
1 parent 30e4f3a commit 5cb9ea9
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 6 deletions.
10 changes: 7 additions & 3 deletions ui/webui/src/components/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ import { PayloadsClient } from "../apis/payloads";

import { readBuildstamp, getIsFinal } from "../helpers/betanag.js";
import { readConf } from "../helpers/conf.js";

const _ = cockpit.gettext;
import { getOsReleaseByKey } from "../helpers/product.js";

export const Application = () => {
const [address, setAddress] = useState();
Expand All @@ -46,6 +45,7 @@ export const Application = () => {
const [notifications, setNotifications] = useState({});
const [isHelpExpanded, setIsHelpExpanded] = useState(false);
const [helpContent, setHelpContent] = useState("");
const [prettyName, setPrettyName] = useState("");

useEffect(() => {
cockpit.file("/run/anaconda/bus.address").watch(address => {
Expand All @@ -69,6 +69,10 @@ export const Application = () => {
buildstamp => setBeta(!getIsFinal(buildstamp)),
ex => console.error("Failed to parse anaconda buildstamp file")
);

getOsReleaseByKey("PRETTY_NAME").then(
setPrettyName
);
}, []);

const onAddNotification = (notificationProps) => {
Expand All @@ -95,7 +99,7 @@ export const Application = () => {
}
console.info("conf: ", conf);

const title = _("Anaconda installer");
const title = cockpit.format("$0 installation", prettyName);

const page = (
<Page
Expand Down
12 changes: 10 additions & 2 deletions ui/webui/src/components/localization/InstallationLanguage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with This program; If not, see <http://www.gnu.org/licenses/>.
*/

import React from "react";
import React, { useEffect, useState } from "react";
import cockpit from "cockpit";

import {
Expand Down Expand Up @@ -53,6 +53,7 @@ import {
setLangCookie
} from "../../helpers/language.js";
import { AnacondaPage } from "../AnacondaPage.jsx";
import { getOsReleaseByKey } from "../../helpers/product.js";

import "./InstallationLanguage.scss";

Expand Down Expand Up @@ -317,9 +318,16 @@ LanguageSelector.contextType = AddressContext;
export const InstallationLanguage = ({ idPrefix, setIsFormValid, onAddErrorNotification }) => {
const [nativeName, setNativeName] = React.useState(false);
const { setLanguage } = React.useContext(LanguageContext);
const [distributionName, setDistributionName] = useState("");

useEffect(() => {
getOsReleaseByKey("NAME").then(
setDistributionName
);
}, []);

return (
<AnacondaPage title={_("Welcome to the Anaconda installer")}>
<AnacondaPage title={cockpit.format("Welcome to $0", distributionName)}>
<Title
headingLevel="h3"
>
Expand Down
33 changes: 33 additions & 0 deletions ui/webui/src/helpers/product.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2022 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 const getOsReleaseByKey = (key) => {
const confFile = cockpit.file("/etc/os-release");
console.log(confFile);

return confFile
.read()
.then((content) =>
content
.split(/\r?\n/)
?.find((item) => item?.includes(key))
.split("=")[1]
.replace(/['"]+/g, "")
)
.finally(confFile.close);
};

0 comments on commit 5cb9ea9

Please sign in to comment.