From eaf0878883d9ffd69fb17fc2bfbf3886d1083236 Mon Sep 17 00:00:00 2001 From: zhangkun Date: Thu, 15 Oct 2026 20:26:22 +0800 Subject: [PATCH] fix(langselector): install missing language packages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. A nonempty ByLocale result means packages are missing, so the inverted check treated them as already installed and nothing was ever installed; decide with needsInstall instead. 2. Read State from NetworkManager on the system bus instead of the session org.deepin.dde.Network1, whose dde-network-core 2.0 compatibility stub always returns 0 and made the daemon believe it was offline. 3. Require NM_STATE_CONNECTED_GLOBAL (70) before installing, because local or site connectivity alone cannot reach the package mirrors. 4. Send the start notification even when no package needs installation. 5. Reuse getInstallLangSupportPackages in the install path, removing the duplicated query code. Log: Switching the system language installs the missing language packages again. Influence: Language packages are installed when the internet is reachable. fix(langselector): 联网时安装缺失的语言支持包 1. ByLocale 返回非空即表示有包尚未安装,原判断写反导致被当成已安装,从不安装;改用 needsInstall 判断。 2. 改为读取系统总线上 NetworkManager 的 State,不再依赖 dde-network-core 2.0 中固定返回 0 的会话 org.deepin.dde.Network1 兼容层,该兼容层使程序始终认为断网。 3. 只有 NM_STATE_CONNECTED_GLOBAL(70)才安装,仅本地或站点连通无法访问软件源。 4. 没有缺包时也发送开始通知。 5. 安装流程复用 getInstallLangSupportPackages,去掉重复的查询代码。 Log: 切换系统语言后能够正常安装缺失的语言支持包。 PMS: BUG-379697 PMS: BUG-379687 PMS: BUG-379685 Influence: 联网可达时自动补装语言支持包。 --- langselector1/locale.go | 44 ++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/langselector1/locale.go b/langselector1/locale.go index 97c6186b3..0ab3a3a33 100644 --- a/langselector1/locale.go +++ b/langselector1/locale.go @@ -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 @@ -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" @@ -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) { @@ -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 @@ -466,7 +461,7 @@ func (lang *LangSelector) setLocale(locale string) { } // install language support packages - if !isInstalled && networkEnabled { + if needsInstall && networkEnabled { err = lang.installLangSupportPackages(locale) if err != nil { logger.Warning("failed to install packages:", err) @@ -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) }