app suggenstions when no app is installed

This commit is contained in:
Vinicius Moreira
2019-08-05 22:06:37 -03:00
parent 193c8bc2bc
commit 3f01ba8c3b
10 changed files with 133 additions and 23 deletions

View File

@@ -90,6 +90,10 @@ class ApplicationManager(ABC):
def list_warnings(self) -> List[str]:
pass
@abstractmethod
def list_suggestions(self, limit: int) -> List[Application]:
pass
class GenericApplicationManager(ApplicationManager):
@@ -285,3 +289,11 @@ class GenericApplicationManager(ApplicationManager):
warnings.extend(man_warnings)
return warnings
def list_suggestions(self, limit: int) -> List[Application]:
if self.managers:
suggestions = []
for man in self.managers:
if self._is_enabled(man):
suggestions.extend(man.list_suggestions(5))
return suggestions

View File

@@ -46,7 +46,9 @@ class FlatpakManager(ApplicationManager):
if not api_data or expired_data:
if not app_json['runtime']:
disk_loader.add(app) # preloading cached disk data
if disk_loader:
disk_loader.add(app) # preloading cached disk data
FlatpakAsyncDataLoader(app=app, api_cache=self.api_cache, manager=self, http_session=self.http_session).start()
else:
@@ -181,3 +183,22 @@ class FlatpakManager(ApplicationManager):
def list_warnings(self) -> List[str]:
if not flatpak.has_remotes_set():
return [self.locale_keys['flatpak.notification.no_remotes']]
def list_suggestions(self, limit: int) -> List[FlatpakApplication]:
res = []
if limit != 0:
for app_id in ('com.spotify.Client', 'com.skype.Client', 'com.dropbox.Client', 'us.zoom.Zoom', 'com.visualstudio.code', 'org.inkscape.Inkscape', 'org.libretro.RetroArch', 'org.kde.kdenlive', 'org.videolan.VLC'):
app_json = flatpak.search(app_id, app_id=True)
if app_json:
res.append(self._map_to_model(app_json[0], False, None))
if len(res) == limit:
break
return res

View File

@@ -153,7 +153,7 @@ def get_app_commits_data(app_ref: str, origin: str) -> List[dict]:
return commits
def search(word: str) -> List[dict]:
def search(word: str, app_id: bool = False) -> List[dict]:
cli_version = get_version()
res = system.run_cmd('{} search {}'.format(BASE_CMD, word))
@@ -166,13 +166,17 @@ def search(word: str) -> List[dict]:
for info in split_res:
if info:
info_list = info.split('\t')
if cli_version >= '1.3.0':
id_ = info_list[2].strip()
if app_id and id_ != word:
continue
version = info_list[3].strip()
found.append({
app = {
'name': info_list[0].strip(),
'description': info_list[1].strip(),
'id': info_list[2].strip(),
'id': id_,
'version': version,
'latest_version': version,
'branch': info_list[4].strip(),
@@ -180,14 +184,19 @@ def search(word: str) -> List[dict]:
'runtime': False,
'arch': None, # unknown at this moment,
'ref': None # unknown at this moment
})
}
elif cli_version >= '1.2.0':
id_ = info_list[1].strip()
if app_id and id_ != word:
continue
desc = info_list[0].split('-')
version = info_list[2].strip()
found.append({
app = {
'name': desc[0].strip(),
'description': desc[1].strip(),
'id': info_list[1].strip(),
'id': id_,
'version': version,
'latest_version': version,
'branch': info_list[3].strip(),
@@ -195,13 +204,18 @@ def search(word: str) -> List[dict]:
'runtime': False,
'arch': None, # unknown at this moment,
'ref': None # unknown at this moment
})
}
else:
id_ = info_list[0].strip()
if app_id and id_ != word:
continue
version = info_list[1].strip()
found.append({
app = {
'name': '',
'description': info_list[4].strip(),
'id': info_list[0].strip(),
'id': id_,
'version': version,
'latest_version': version,
'branch': info_list[2].strip(),
@@ -209,7 +223,13 @@ def search(word: str) -> List[dict]:
'runtime': False,
'arch': None, # unknown at this moment,
'ref': None # unknown at this moment
})
}
found.append(app)
if app_id and len(found) > 0:
break
return found

View File

@@ -137,3 +137,18 @@ class SnapManager(ApplicationManager):
def list_warnings(self) -> List[str]:
if snap.get_snapd_version() == 'unavailable':
return [self.locale_keys['snap.notification.snapd_unavailable']]
def list_suggestions(self, limit: int) -> List[SnapApplication]:
suggestions = []
if limit != 0:
for name in ('whatsdesk', 'slack', 'yakyak', 'instagraph', 'eclipse', 'gimp', 'supertuxkart'):
res = snap.search(name, exact_name=True)
if res:
suggestions.append(self.map_json(res[0], installed=False, disk_loader=None))
if len(suggestions) == limit:
break
return suggestions

View File

@@ -86,7 +86,7 @@ def read_installed() -> List[dict]:
return apps
def search(word: str) -> List[dict]:
def search(word: str, exact_name: bool = False) -> List[dict]:
apps = []
res = system.run_cmd('{} find "{}"'.format(BASE_CMD, word), print_error=False)
@@ -98,6 +98,10 @@ def search(word: str) -> List[dict]:
for idx, app_str in enumerate(res):
if idx > 0 and app_str:
app_data = [word for word in app_str.split(' ') if word]
if exact_name and app_data[0] != word:
continue
apps.append({
'name': app_data[0],
'version': app_data[1],
@@ -109,6 +113,9 @@ def search(word: str) -> List[dict]:
'type': None
})
if exact_name and len(apps) > 0:
break
return apps