manager.vue 9.17 KB
Newer Older
FabioWidmer's avatar
FabioWidmer committed
1
<template>
FabioWidmer's avatar
FabioWidmer committed
2
	<f7-page name="manager" @page:beforein="checkApps">
FabioWidmer's avatar
FabioWidmer committed
3
4
		<f7-navbar large>
			<f7-nav-left>
FabioWidmer's avatar
FabioWidmer committed
5
				<f7-link href="/about/" icon-aurora="f7:menu" icon-ios="f7:menu" icon-md="material:menu"/>
FabioWidmer's avatar
FabioWidmer committed
6
7
8
9
			</f7-nav-left>
			<f7-nav-title>{{ $t('pages.manager.title') }}</f7-nav-title>
			<f7-nav-title-large>{{ $t('pages.manager.title') }}</f7-nav-title-large>
			<f7-nav-right>
FabioWidmer's avatar
FabioWidmer committed
10
				<f7-link href="/sources/apps/search/" icon-aurora="f7:search" icon-ios="f7:search" icon-md="material:search"/>
FabioWidmer's avatar
FabioWidmer committed
11
12
			</f7-nav-right>
		</f7-navbar>
FabioWidmer's avatar
FabioWidmer committed
13
		<popover-anti-features/>
FabioWidmer's avatar
FabioWidmer committed
14
15
16
17
18
19
20
21
		<div v-show="!loading && apps.length">
			<div v-show="apps.filter(app => app.packageUpdate).length">
				<f7-block-title>{{ $t('pages.manager.updateAvailable') }} <!--<f7-link class="float-right" :text="$t('pages.manager.updateAll')" @click="() => {}" />--></f7-block-title>
				<f7-list class="list-outdated">
					<ul>
						<f7-list-item
							v-for="(app, index) in apps.filter(app => app.packageUpdate)"
							:key="app.packageName"
FabioWidmer's avatar
FabioWidmer committed
22
							:badge="app.packageSuggestion.versionName"
FabioWidmer's avatar
FabioWidmer committed
23
							:data-icon="app.icon"
FabioWidmer's avatar
FabioWidmer committed
24
							:footer="`${app.packageSuggestion.added.toLocaleDateString()}, ${Math.round(app.packageSuggestion.size / 1024 / 1024 * 10) / 10} MB`"
FabioWidmer's avatar
FabioWidmer committed
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
							:title="app.name"
							accordion-item
							badge-color="blue"
						>
							<img v-if="icons[app.icon]" slot="media" :src="icons[app.icon]" alt="" class="icon-40"/>
							<f7-skeleton-block v-if="app.icon && !icons[app.icon]" slot="media" class="icon-40"></f7-skeleton-block>
							<f7-accordion-content>
								<div v-if="app.whatsNew">
									<f7-block-title>{{ $t('words.whatsNew') }}</f7-block-title>
									<f7-block v-html="app.whatsNew"></f7-block>
								</div>
								<div v-if="app.packageDifferences">
									<div v-if="app.packageDifferences.antiFeatures.length">
										<f7-block-title>{{ $t('words.antiFeatures') }} ({{ $t('words.differences') }})</f7-block-title>
										<f7-block>
FabioWidmer's avatar
FabioWidmer committed
40
41
42
43
44
45
											<chip-anti-feature
												v-for="antiFeature in app.packageDifferences.antiFeatures || app.antiFeatures"
												:key="antiFeature"
												:name="antiFeature"
												class="padding-horizontal-half"
											/>
FabioWidmer's avatar
FabioWidmer committed
46
47
48
49
										</f7-block>
									</div>
								</div>
								<f7-block>
FabioWidmer's avatar
FabioWidmer committed
50
									<f7-button :href="`/sources/${encodeURIComponent(app.sourceId)}/apps/${app.packageName}/`" :text="$t('words.update')" fill raised></f7-button>
FabioWidmer's avatar
FabioWidmer committed
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
								</f7-block>
							</f7-accordion-content>
						</f7-list-item>
					</ul>
				</f7-list>
			</div>
			<f7-block-title>{{ $t('words.installed') }}</f7-block-title>
			<f7-list class="list-installed">
				<ul>
					<f7-list-item
						v-for="(app, index) in apps"
						:key="app.packageName"
						:badge="app.packageInstalled.versionName"
						:badge-color="app.packageUpdate ? 'orange' : 'green'"
						:data-icon="app.icon"
						:footer="app.packageName"
						:link="`/sources/${encodeURIComponent(app.sourceId)}/apps/${app.packageName}/`"
						:swipeout="!app.packageInstalled.applicationSystem"
FabioWidmer's avatar
FabioWidmer committed
69
						:title="app.name"
FabioWidmer's avatar
FabioWidmer committed
70
71
72
73
					>
						<img v-if="icons[app.icon]" slot="media" :src="icons[app.icon]" alt="" class="icon-40"/>
						<f7-skeleton-block v-if="app.icon && !icons[app.icon]" slot="media" class="icon-40"></f7-skeleton-block>
						<f7-swipeout-actions right>
FabioWidmer's avatar
FabioWidmer committed
74
75
							<f7-swipeout-button color="blue" @click="() => submitLaunch(app)">{{ $t('words.launch') }}</f7-swipeout-button>
							<f7-swipeout-button color="red" @click="() => submitUninstall(app)">{{ $t('words.uninstall') }}</f7-swipeout-button>
FabioWidmer's avatar
FabioWidmer committed
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
						</f7-swipeout-actions>
					</f7-list-item>
				</ul>
			</f7-list>
		</div>
		<f7-list v-if="loading">
			<f7-list-item v-for="index in 25" :key="index" class="skeleton-text" title="Lorem ipsum dolor sit amet.">
				<f7-skeleton-block slot="media" class="icon-40"/>
			</f7-list-item>
		</f7-list>
		<div v-else-if="!apps.length" class="display-flex justify-content-center align-items-center height-100">
			<f7-block>
				<f7-icon aurora="f7:circle_grid_3x3" class="display-block" ios="f7:circle_grid_3x3" md="material:apps" size="100"/>
			</f7-block>
			<f7-block>
				<p>{{ $t('pages.manager.noApps') }}</p>
				<f7-button :text="$t('words.explore')" href="/home/" outline raised/>
			</f7-block>
		</div>
	</f7-page>
</template>
<script>
FabioWidmer's avatar
FabioWidmer committed
98
import {fetchIcons, suggestPackage} from '../js/utils';
FabioWidmer's avatar
FabioWidmer committed
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import ChipAntiFeature from '../components/chips/antifeature';
import PopoverAntiFeatures from '../components/popovers/antifeatures.vue';

export default {
	components: {ChipAntiFeature, PopoverAntiFeatures},
	data: function() {
		return {
			apps: [],
			icons: {},
			iconsTimeout: null,
		};
	},
	computed: {
		loading: function() {
			const loading = this.$store.state.sources.loading;

			if(!loading) {
				this.checkApps();
			}

			return loading;
		},
	},
	methods: {
		fetchIcons: function() {
			clearTimeout(this.iconsTimeout);

			this.iconsTimeout = setTimeout(() => {
				const items = [];

				this.$$('[class^="list-"] li[data-icon]').each((index, app) => {
					if(this.$$(app).offset().top > 0 && this.$$(app).offset().top < window.innerHeight) {
						items.push({icon: this.$$(app).data('icon')});
					}
				});

FabioWidmer's avatar
FabioWidmer committed
135
				fetchIcons(items, this.icons, this.$f7.data.server, this.$store.state.settings.assetsAge).then(icons => {
FabioWidmer's avatar
FabioWidmer committed
136
137
138
139
140
141
142
143
144
145
146
147
					this.icons = {
						...this.icons,
						...icons,
					};
				});
			}, 5000);
		},
		checkApps: function() {
			ablota.store.package.list(data => {
				if(data.status === 'success') {
					const apps = [];

FabioWidmer's avatar
FabioWidmer committed
148
					const promises = data.packages.map(installedPackage => new Promise(resolve => {
FabioWidmer's avatar
FabioWidmer committed
149
150
151
152
153
154
155
156
157
158
159
160
161
162
						const packages = this.$store.getters['sources/getPackages'](installedPackage.packageName);
						let appPackage = null;

						if(packages.some(appPackage => installedPackage.signatures.includes(appPackage.signer) && installedPackage.versionCode === appPackage.versionCode)) {
							appPackage = packages.find(appPackage => installedPackage.signatures.includes(appPackage.signer) && installedPackage.versionCode === appPackage.versionCode);
						} else if(packages.some(appPackage => installedPackage.signatures.includes(appPackage.signer))) {
							appPackage = packages.find(appPackage => installedPackage.signatures.includes(appPackage.signer));
						} else if(installedPackage.installerPackageName === this.$f7.params.id && packages.length) {
							appPackage = packages[0];
						}

						if(appPackage) {
							const app = this.$store.getters['sources/getApp'](appPackage.sourceId, appPackage.packageName, this.$f7.language);

FabioWidmer's avatar
FabioWidmer committed
163
164
165
166
167
168
169
							suggestPackage(app, packages, this.$f7.data.deviceInfo).then(data => {
								let packageDifferences = null;

								if(data.package) {
									packageDifferences = {
										antiFeatures: data.package.antiFeatures.filter(antiFeature => !appPackage.antiFeatures.includes(antiFeature)),
									};
FabioWidmer's avatar
FabioWidmer committed
170
								}
FabioWidmer's avatar
FabioWidmer committed
171
172
173
174
175
176
177
178
179
180
181
182
183
184

								apps.push({
									...app,
									package: appPackage,
									packageSuggestion: data.package,
									packageUpdate: data.outdated,
									packageInstalled: installedPackage,
									packageDifferences,
								});

								resolve();
							}).catch(data => this.$f7.dialog.alert(this.$t(data)));
						} else {
							resolve();
FabioWidmer's avatar
FabioWidmer committed
185
						}
FabioWidmer's avatar
FabioWidmer committed
186
					}));
FabioWidmer's avatar
FabioWidmer committed
187

FabioWidmer's avatar
FabioWidmer committed
188
189
190
					Promise.all(promises).then(() => {
						if(!this.apps.some(app => app.packageName === this.$f7.id && app.packageUpdate) && apps.some(app => app.packageName === this.$f7.id && app.packageUpdate)) {
							const app = apps.find(app => app.packageName === this.$f7.id && app.packageUpdate);
FabioWidmer's avatar
FabioWidmer committed
191

FabioWidmer's avatar
FabioWidmer committed
192
193
194
195
							this.$f7.dialog.alert(this.$t('pages.manager.updateSystem'), () => {
								this.$f7router.navigate(`/sources/${encodeURIComponent(app.sourceId)}/apps/${app.packageName}/`);
							});
						}
FabioWidmer's avatar
FabioWidmer committed
196

FabioWidmer's avatar
FabioWidmer committed
197
198
199
						this.apps = apps.sort((a, b) => a.lastUpdated < b.lastUpdated);
						this.fetchIcons();
					});
FabioWidmer's avatar
FabioWidmer committed
200
201
202
203
204
205
206
207
				} else {
					this.$f7.dialog.alert(this.$t('pages.manager.errors.list'));
				}
			}, () => {
				this.$f7.dialog.alert(this.$t('pages.manager.errors.list'));
			});
		},
		submitLaunch: function(app) {
FabioWidmer's avatar
FabioWidmer committed
208
209
			ablota.store.package.launch(app.packageName, () => {
			}, () => {
FabioWidmer's avatar
FabioWidmer committed
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
				this.$f7.dialog.alert(this.$t('pages.manager.errors.launch'));
			});
		},
		submitUninstall: function(app) {
			this.$f7.dialog.confirm(this.$t('pages.manager.uninstall.before'), () => {
				ablota.store.package.uninstall(app.packageName, data => {
					if(data.status === 'success') {
						if(data.code === 0) {
							this.$f7.toast.show({
								text: this.$t('pages.manager.uninstall.after'),
							});
							this.$f7.swipeout.delete(this.$$(`.list-installed li[data-icon="${app.icon}"]`), () => this.checkApps());
						} else if(data.code !== 3) {
							this.$f7.dialog.alert(this.$t('pages.manager.errors.uninstall'));
						}
					}
				}, () => {
					this.$f7.dialog.alert(this.$t('pages.manager.errors.uninstall'));
				});
			});
		},
	},
	mounted() {
		this.$f7ready(() => {
			let interactionTimeout = null;

			this.$$(document).on('resume', () => this.checkApps());
			this.$$(window).on('touchstart touchmove', () => {
				clearTimeout(interactionTimeout);
				interactionTimeout = setTimeout(() => this.fetchIcons(), 1000);
			});

			this.$$('.page-content').on('scroll', () => {
				clearTimeout(interactionTimeout);
				interactionTimeout = setTimeout(() => this.fetchIcons(), 1000);
			});
FabioWidmer's avatar
FabioWidmer committed
246
247

			setInterval(() => this.checkApps(), 60000);
FabioWidmer's avatar
FabioWidmer committed
248
249
250
251
		});
	},
};
</script>