Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 17 additions & 27 deletions langselector1/locale.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2018 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand All @@ -22,10 +22,10 @@ import (
"github.com/linuxdeepin/dde-api/userenv"
"github.com/linuxdeepin/dde-daemon/common/dconfig"
ddbus "github.com/linuxdeepin/dde-daemon/dbus"
libnetwork "github.com/linuxdeepin/go-dbus-factory/session/org.deepin.dde.network1"
notifications "github.com/linuxdeepin/go-dbus-factory/session/org.freedesktop.notifications"
lastore "github.com/linuxdeepin/go-dbus-factory/system/org.deepin.dde.lastore1"
localehelper "github.com/linuxdeepin/go-dbus-factory/system/org.deepin.dde.localehelper1"
networkmanager "github.com/linuxdeepin/go-dbus-factory/system/org.freedesktop.networkmanager"
"github.com/linuxdeepin/go-lib/dbusutil"
. "github.com/linuxdeepin/go-lib/gettext"
"github.com/linuxdeepin/go-lib/strv"
Expand Down Expand Up @@ -260,21 +260,18 @@ func sendNotify(icon, summary, body string) {
}

func isNetworkEnable() (bool, error) {
sessionBus, err := dbus.SessionBus()
systemBus, err := dbus.SystemBus()
if err != nil {
return false, err
}
network := libnetwork.NewNetwork(sessionBus)
state, err := network.State().Get(0)
network := networkmanager.NewManager(systemBus)
state, err := network.PropState().Get(0)
if err != nil {
return false, err
}
// if state < 50, network disconnect
if state < 50 {
return false, nil
}

return true, nil
// NM_STATE_CONNECTED_GLOBAL: local/site connectivity alone is insufficient.
const connectedGlobal = 70
return state == connectedGlobal, nil
}

func getCurrentUserLocale() (locale string) {
Expand Down Expand Up @@ -420,15 +417,13 @@ func (lang *LangSelector) setLocale(locale string) {
logger.Debug("failed to get support packages", err)
}

// only language support packages not installed and network enabled should install
isInstalled := len(pkg) != 0
// ByLocale excludes installed packages, so a nonempty list needs installation.
needsInstall := len(pkg) != 0

if !isInstalled {
if networkEnabled {
sendNotify(localeIconStart, "", notifyTxtStartWithInstall)
} else {
sendNotify(localeIconStart, "", notifyTxtStart)
}
if needsInstall && networkEnabled {
sendNotify(localeIconStart, "", notifyTxtStartWithInstall)
} else {
sendNotify(localeIconStart, "", notifyTxtStart)
}

// generate locale
Expand Down Expand Up @@ -466,7 +461,7 @@ func (lang *LangSelector) setLocale(locale string) {
}

// install language support packages
if !isInstalled && networkEnabled {
if needsInstall && networkEnabled {
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
err = lang.installLangSupportPackages(locale)
if err != nil {
logger.Warning("failed to install packages:", err)
Expand Down Expand Up @@ -590,20 +585,15 @@ func (lang *LangSelector) getInstallLangSupportPackages(locale string) ([]string
return nil, dbusutil.ToError(err)
}

packages := ls.ByLocale(locale, false)
ls.Destroy()
return packages, nil
return ls.ByLocale(locale, false), nil
}

func (lang *LangSelector) installLangSupportPackages(locale string) error {
logger.Debug("install language support packages for locale", locale)
ls, err := language_support.NewLanguageSupport()
pkgs, err := lang.getInstallLangSupportPackages(locale)
if err != nil {
return err
}

pkgs := ls.ByLocale(locale, false)
ls.Destroy()
logger.Info("need to install:", pkgs)
return lang.installPackages(pkgs)
}
Expand Down
Loading