Обновления приложений Angular + Combacitor Android с помощью пользовательской работы по Zip Source работают только до теAndroid

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Обновления приложений Angular + Combacitor Android с помощью пользовательской работы по Zip Source работают только до те

Сообщение Anonymous »

Я разрабатываю приложение для Android с использованием Angular + емкость. Я внедрил пользовательский механизм обновления, который загружает файл .zip с моего сервера, извлекает его в пользовательскую папку внутри файловой системы. /> Новая версия отображается после window.location.reload ().
Я сохраняю извлеченный путь и версию с использованием @концентрации/хранилища. Делайте в main.ts перед платформой browserdynamic (): < /p>
const STORAGE_KEY = 'customBasePath';
let customWebDirPath: any = null;

const setCustomBasePath = async (): Promise => {

const platform = Capacitor.getPlatform();
const isAlreadyInCustomPath = await Storage.get({ key: STORAGE_KEY });

if (platform !== 'web' && isAlreadyInCustomPath.value !== 'true') {
try {

customWebDirPath = await Storage.get({ key: 'customBasePath' });

alert(`customWebDirPath: ${customWebDirPath.value}`)

await Filesystem.stat({
directory: Directory.Data,
path: `${customWebDirPath.value}/index.html`,
});

const uri = await Filesystem.getUri({
directory: Directory.Data,
path: customWebDirPath.value,
});

const absolutePath = uri.uri.replace('file://', '');

await WebView.setServerBasePath({ path: absolutePath });

await Storage.set({ key: STORAGE_KEY, value: 'true' });

} catch (err) {
alert('catch')
console.warn('⚠️ Could not set custom base path. Error:', err);
}
} else {
const currentBasePath = await WebView.getServerBasePath();
}
};
< /code>
и app.component.ts (только функция UNZIP) < /p>
this.zip.unzip(zipFilePath, unpackDirPath, async (status: any) => {
if (status === 0) {
alert('🎉 Unzipped successfully!');

try {
// Удаляем предыдущую custom_www директорию, если существует
try {
await Filesystem.rmdir({
directory: Directory.Data,
path: customWebDirPath,
recursive: true
});
} catch (e) {
// log error
}

// copu to custom_www
await this.copyFolder(unpackPath, customWebDirPath);

// get absolute path custom_www
const webDirUri = await Filesystem.getUri({
directory: Directory.Data,
path: customWebDirPath
});
const absoluteWebDirPath = webDirUri.uri.replace('file://', '');

// set
await WebView.setServerBasePath({ path: absoluteWebDirPath });

// save custom path to the storage
await Storage.set({ key: 'customBasePath', value: absoluteWebDirPath });
await Storage.set({ key: 'app_version', value: version });

alert(`✅ Set new base path: ${absoluteWebDirPath}`);

// restart app
window.location.reload();

} catch (e) {
console.error('❌ Error copying files:', e);
}
} else {
console.warn('❌ Failed to unzip update');
}
});
```

after update my app shows correct version all good. but after restart(close from memory) it loads start version.

It seems that WebView.setServerBasePath() does not persist across app restarts.

Question:
How can I make Capacitor/Angular app consistently load from the updated custom_www folder (inside FilesystemDirectory.Data) even after the app is killed and restarted?



Подробнее здесь: https://stackoverflow.com/questions/796 ... y-until-ap
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»