forked from linuxdeepin/dde-daemon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manager_init.go
106 lines (94 loc) · 2.6 KB
/
manager_init.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* Copyright (C) 2016 ~ 2018 Deepin Technology Co., Ltd.
*
* Author: jouyouyun <jouyouwen717@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package launcher
import (
"path/filepath"
"unicode/utf8"
"pkg.deepin.io/lib/appinfo/desktopappinfo"
"pkg.deepin.io/lib/dbusutil/proxy"
)
func (m *Manager) initItems() {
// load items
m.items = make(map[string]*Item)
skipDirs := make(map[string][]string)
skipDirs["/usr/share/applications"] = []string{"screensavers"}
userAppsDir := getUserAppDir()
skipDirs[userAppsDir] = []string{"menu-xdg"}
allApps := desktopappinfo.GetAll(skipDirs)
for _, ai := range allApps {
if !ai.IsExecutableOk() ||
!utf8.ValidString(ai.GetId()) ||
isDeepinCustomDesktopFile(ai.GetFileName()) {
continue
}
item := NewItemWithDesktopAppInfo(ai)
m.setItemID(item)
if m.hiddenByGSettings(item.ID) {
continue
}
m.addItem(item)
}
logger.Debug("load items count:", len(m.items))
}
func shouldCheckDesktopFile(filename string) bool {
dir, basename := filepath.Split(filename)
dir = filepath.Clean(dir)
matched, _ := filepath.Match(desktopFilePattern, basename)
if !matched {
return false
}
// ignore $HOME/.local/share/applications/menu-xdg/
skipDir := filepath.Join(getUserAppDir(), "menu-xdg")
return dir != skipDir
}
type popPushOp struct {
popCount int
runesPush []rune
}
func (m *Manager) handlePopPushOps() {
stack := m.searchTaskStack
for op := range m.popPushOpChan {
logger.Debug("op:", op)
for i := 0; i < op.popCount; i++ {
stack.Pop()
}
if len(op.runesPush) == 0 {
// emit top result
top := stack.topTask()
if top == nil {
logger.Debug("emit SearchDone []")
err := m.service.Emit(m, "SearchDone", []string{})
if err != nil {
logger.Warning("emit SearchDone Failed:", err)
}
} else {
top.emitResult()
}
}
for _, v := range op.runesPush {
stack.Push(v)
}
}
}
func (m *Manager) destroy() {
m.appsObj.RemoveHandler(proxy.RemoveAllHandlers)
m.syncConfig.Destroy()
m.sysSigLoop.Stop()
m.sessionSigLoop.Stop()
}