Ejemplo n.º 1
0
func (m *ItemManager) GetAllTimeInstalled() (map[ItemId]int64, error) {
	infos := map[ItemId]int64{}
	var err error
	for id, _ := range m.itemTable {
		infos[id] = 0
	}

	store, err := storeApi.NewDStoreDesktop("com.deepin.store.Api", "/com/deepin/store/Api")
	if err != nil {
		return infos, fmt.Errorf("create store api failed: %v", err)
	}
	defer storeApi.DestroyDStoreDesktop(store)

	datasStr, err := store.GetAllDesktops()
	if err != nil {
		return infos, fmt.Errorf("get all desktops' info failed: %v", err)
	}

	datas := [][]interface{}{}
	err = json.Unmarshal([]byte(datasStr), &datas)
	if err != nil {
		return infos, err
	}

	for _, data := range datas {
		id := GenId(data[0].(string))
		t := int64(data[1].(float64))
		infos[id] = t
	}

	return infos, err
}
Ejemplo n.º 2
0
func (self *ItemManager) GetAllNewInstalledApps() ([]ItemId, error) {
	ids := []ItemId{}
	store, err := storeApi.NewDStoreDesktop("com.deepin.store.Api", "/com/deepin/store/Api")
	if err != nil {
		return ids, fmt.Errorf("create store api failed: %v", err)
	}
	defer storeApi.DestroyDStoreDesktop(store)

	dataStr, err := store.GetNewDesktops()
	if err != nil {
		return ids, err
	}

	datas := [][]interface{}{}
	err = json.Unmarshal([]byte(dataStr), &datas)
	if err != nil {
		return ids, err
	}

	for _, data := range datas {
		id := GenId(data[0].(string))
		ids = append(ids, id)
	}
	return ids, nil
}
Ejemplo n.º 3
0
func (self *ItemManager) MarkLaunched(_id ItemId) error {
	store, err := storeApi.NewDStoreDesktop("com.deepin.store.Api", "/com/deepin/store/Api")
	if err != nil {
		return fmt.Errorf("create store api failed: %v", err)
	}
	defer storeApi.DestroyDStoreDesktop(store)

	_, ok := store.MarkLaunched(string(_id))
	return ok
}
Ejemplo n.º 4
0
func Start() {
	if launcher != nil {
		return
	}

	var err error

	logger.BeginTracing()

	InitI18n()

	// DesktopAppInfo.ShouldShow does not know deepin.
	gio.DesktopAppInfoSetDesktopEnv("Deepin")

	soft, err := NewSoftwareCenter()
	if err != nil {
		startFailed(err)
		return
	}

	im := NewItemManager(soft)
	cm := NewCategoryManager()

	timeInfo, _ := im.GetAllTimeInstalled()

	appChan := make(chan *gio.AppInfo)
	go func() {
		allApps := gio.AppInfoGetAll()
		for _, app := range allApps {
			appChan <- app
		}
		close(appChan)
	}()

	dbPath, _ := GetDBPath(SoftwareCenterDataDir, CategoryNameDBPath)
	db, err := sql.Open("sqlite3", dbPath)

	var wg sync.WaitGroup
	const N = 20
	wg.Add(N)
	for i := 0; i < N; i++ {
		go func() {
			for app := range appChan {
				if !app.ShouldShow() {
					app.Unref()
					continue
				}

				desktopApp := gio.ToDesktopAppInfo(app)
				item := NewItem(desktopApp)
				cid, err := QueryCategoryId(desktopApp, db)
				if err != nil {
					item.SetCategoryId(OtherID)
				}
				item.SetCategoryId(cid)
				item.SetTimeInstalled(timeInfo[item.Id()])

				im.AddItem(item)
				cm.AddItem(item.Id(), item.GetCategoryId())

				app.Unref()
			}
			wg.Done()
		}()
	}
	wg.Wait()
	if err == nil {
		db.Close()
	}

	launcher = NewLauncher()
	launcher.setItemManager(im)
	launcher.setCategoryManager(cm)

	store, err := storeApi.NewDStoreDesktop("com.deepin.store.Api", "/com/deepin/store/Api")
	if err == nil {
		launcher.setStoreApi(store)
	}

	names := []string{}
	for _, item := range im.GetAllItems() {
		names = append(names, item.Name())
	}
	pinyinObj, err := NewPinYinSearchAdapter(names)
	launcher.setPinYinObject(pinyinObj)

	launcher.listenItemChanged()

	err = dbus.InstallOnSession(launcher)
	if err != nil {
		startFailed(err)
		return
	}

	coreSetting := gio.NewSettings("com.deepin.dde.launcher")
	if coreSetting == nil {
		startFailed(errors.New("get schema failed"))
		return
	}
	setting, err := NewSetting(coreSetting)
	if err != nil {
		startFailed(err)
		return
	}
	err = dbus.InstallOnSession(setting)
	if err != nil {
		startFailed(err)
		return
	}
	launcher.setSetting(setting)
}