-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
原有逻辑: lastore的通知都是dde-session-daemon去监听com.deepin.lastore.Job的状态,持续监听占用资源,而且交互不方便. 逻辑优化: lastore-daemon定义一套agent接口,由dde-daemon的lastore模块实现相关接口并导出,需要发通知和需要获取系统代理时,lastore-daemon调用agent接口完成. Log: lastore模块逻辑修改 Task: https://pms.uniontech.com/task-view-214983.html Influence: 通知和apt代理获取 Change-Id: I27df48576528a5932e7263f3945e156dda53dc3b
- Loading branch information
lichangze
committed
Nov 22, 2022
1 parent
e1d25fa
commit 538f692
Showing
8 changed files
with
310 additions
and
671 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,108 @@ | ||
package lastore | ||
|
||
import ( | ||
"github.com/godbus/dbus" | ||
"sync" | ||
|
||
lastore "github.com/linuxdeepin/go-dbus-factory/com.deepin.lastore" | ||
"github.com/linuxdeepin/go-lib/dbusutil" | ||
) | ||
|
||
// lastore agent的interface name | ||
const ( | ||
sessionAgentInterface = "com.deepin.lastore.Agent" | ||
) | ||
|
||
// 对应com.deepin.daemon.Network.GetProxy方法的key值 | ||
const ( | ||
proxyTypeHttp = "http" | ||
proxyTypeHttps = "https" | ||
proxyTypeFtp = "ftp" | ||
proxyTypeSocks = "socks" | ||
) | ||
|
||
// 对应系统代理环境变量 | ||
const ( | ||
envHttpProxy = "http_proxy" | ||
envHttpsProxy = "https_proxy" | ||
envFtpProxy = "ftp_proxy" | ||
envAllProxy = "all_proxy" | ||
) | ||
|
||
// lastoreNotifyType 通知类型 | ||
type lastoreNotifyType string | ||
|
||
const ( | ||
AutoCleanDone lastoreNotifyType = "AutoCleanDone" | ||
AppRemove lastoreNotifyType = "AppRemove" | ||
CanUpdate lastoreNotifyType = "CanUpdate" | ||
AutoDownloading lastoreNotifyType = "AutoDownloading" | ||
CanUpgrade lastoreNotifyType = "CanUpgrade" | ||
UpgradeFailed lastoreNotifyType = "UpgradeFailed" | ||
) | ||
|
||
// Status com.deepin.lastore.Job中的Status属性 | ||
type Status string | ||
|
||
const ( | ||
ReadyStatus Status = "ready" | ||
RunningStatus Status = "running" | ||
FailedStatus Status = "failed" | ||
SucceedStatus Status = "succeed" | ||
PausedStatus Status = "paused" | ||
EndStatus Status = "end" | ||
) | ||
|
||
// JobInfo com.deepin.lastore.Job中需要的属性 | ||
type JobInfo struct { | ||
Id string | ||
Status Status | ||
Name string | ||
Progress float64 | ||
Type string | ||
} | ||
|
||
// Agent 需要实现GetManualProxy和SendNotify两个接口 | ||
type Agent struct { | ||
sysService *dbusutil.Service | ||
lastoreObj *Lastore | ||
sysLastore lastore.Lastore | ||
mu sync.Mutex | ||
} | ||
|
||
func newAgent(l *Lastore) (*Agent, error) { | ||
sysBus, err := dbusutil.NewSystemService() | ||
if err != nil { | ||
logger.Warning(err) | ||
return nil, err | ||
} | ||
a := &Agent{ | ||
sysService: sysBus, | ||
} | ||
a.lastoreObj = l | ||
a.sysLastore = lastore.NewLastore(a.sysService.Conn()) | ||
return a, nil | ||
} | ||
|
||
func (a *Agent) init() { | ||
err := a.sysService.Export("/com/deepin/lastore/agent", a) | ||
if err != nil { | ||
logger.Warning(err) | ||
return | ||
} | ||
err = a.sysLastore.Manager().RegisterAgent(0, "/com/deepin/lastore/agent") | ||
if err != nil { | ||
logger.Warning(err) | ||
} | ||
} | ||
|
||
func (a *Agent) destroy() { | ||
err := a.sysLastore.Manager().UnRegisterAgent(0, "/com/deepin/lastore/agent") | ||
if err != nil { | ||
logger.Warning(err) | ||
} | ||
} | ||
|
||
func (a *Agent) checkCallerAuth(sender dbus.Sender) bool { | ||
return false | ||
} |
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,96 @@ | ||
package lastore | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/godbus/dbus" | ||
lastore "github.com/linuxdeepin/go-dbus-factory/com.deepin.lastore" | ||
"github.com/linuxdeepin/go-lib/dbusutil" | ||
"github.com/linuxdeepin/go-lib/gettext" | ||
) | ||
|
||
func (*Agent) GetInterfaceName() string { | ||
return sessionAgentInterface | ||
} | ||
|
||
func (a *Agent) GetManualProxy(sender dbus.Sender) (map[string]string, *dbus.Error) { | ||
// TODO 获取代理认证信息 | ||
a.checkCallerAuth(sender) | ||
method, err := a.lastoreObj.network.GetProxyMethod(0) | ||
if err != nil { | ||
logger.Warning(err) | ||
return nil, dbusutil.ToError(err) | ||
} | ||
if method != "manual" { | ||
return nil, dbusutil.ToError(errors.New("only support manual proxy")) | ||
} | ||
proxyTypeList := []string{ | ||
proxyTypeHttp, proxyTypeHttps, proxyTypeFtp, | ||
} | ||
proxyEnvMap := make(map[string]string) | ||
for _, typ := range proxyTypeList { | ||
host, port, err := a.lastoreObj.network.GetProxy(0, typ) | ||
if err != nil { | ||
logger.Warning(err) | ||
continue | ||
} | ||
proxyEnvMap[fmt.Sprintf("%s_proxy", typ)] = fmt.Sprintf("%s://%s:%s", proxyTypeHttp, host, port) | ||
} | ||
host, port, err := a.lastoreObj.network.GetProxy(0, proxyTypeSocks) | ||
if err != nil { | ||
logger.Warning(err) | ||
return proxyEnvMap, dbusutil.ToError(err) | ||
} | ||
proxyEnvMap[envAllProxy] = fmt.Sprintf("%s://%s:%s", proxyTypeSocks, host, port) | ||
return proxyEnvMap, nil | ||
} | ||
|
||
func (a *Agent) SendNotify(sender dbus.Sender, typ lastoreNotifyType, jobPath dbus.ObjectPath, args []string) *dbus.Error { | ||
a.checkCallerAuth(sender) | ||
logger.Info("receive notify from lastore") | ||
var jobInfo JobInfo | ||
if jobPath != "" { | ||
notifyJob, err := lastore.NewJob(a.sysService.Conn(), jobPath) | ||
if err != nil { | ||
logger.Warning(err) | ||
return dbusutil.ToError(err) | ||
} | ||
|
||
jobInfo.Id, _ = notifyJob.Id().Get(dbus.FlagNoAutoStart) | ||
jobInfo.Type, _ = notifyJob.Type().Get(dbus.FlagNoAutoStart) | ||
status, _ := notifyJob.Status().Get(dbus.FlagNoAutoStart) | ||
jobInfo.Status = Status(status) | ||
jobInfo.Name, _ = notifyJob.Name().Get(dbus.FlagNoAutoStart) | ||
} | ||
switch typ { | ||
case AutoCleanDone: | ||
a.lastoreObj.notifyAutoClean() | ||
case AppRemove: | ||
switch jobInfo.Status { | ||
case FailedStatus: | ||
a.lastoreObj.notifyRemove("", false, a.lastoreObj.createJobFailedActions(jobInfo.Id)) | ||
case SucceedStatus: | ||
a.lastoreObj.notifyRemove("", true, nil) | ||
} | ||
case CanUpdate: | ||
if strings.Contains(jobInfo.Name, "+notify") { | ||
a.lastoreObj.notifyUpdateSource(a.lastoreObj.createUpdateActions()) | ||
} | ||
case AutoDownloading: | ||
msg := gettext.Tr("Auto Downloading") | ||
a.lastoreObj.sendNotify("preferences-system", "", msg, a.lastoreObj.createUpdateActions(), nil, notifyExpireTimeoutDefault, "dde-control-center") | ||
case CanUpgrade: | ||
msg := gettext.Tr("Upgrade Available") | ||
a.lastoreObj.sendNotify("preferences-system", "", msg, a.lastoreObj.createCanUpgradeActions(), nil, notifyExpireTimeoutDefault, "dde-control-center") | ||
case UpgradeFailed: | ||
// TODO 还需要失败的reason | ||
msg := gettext.Tr("Upgrade Failed") | ||
a.lastoreObj.sendNotify("preferences-system", "", msg, a.lastoreObj.createUpgradeFailedActions(), nil, notifyExpireTimeoutDefault, "dde-control-center") | ||
// TODO 电量低的通知 | ||
// TODO 下载完成通知用户去更新 | ||
} | ||
|
||
return nil | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.