mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 00:27:24 +00:00
Merge branch 'main' of gitlab.com:soapbox-pub/act2 into consoleFramev2
This commit is contained in:
commit
6296fc4366
12 files changed
+802
-92
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { Buffer } from 'buffer';
|
||||
import type { Git } from '@/lib/git';
|
||||
import type { JSRuntimeFS } from '@/lib/JSRuntime';
|
||||
import { ensurePersistentStorage } from '@/lib/persistentStorage';
|
||||
|
||||
// Polyfill Buffer for browser
|
||||
if (typeof window !== 'undefined') {
|
||||
@@ -92,6 +93,14 @@ export class ProjectsManager {
|
||||
},
|
||||
});
|
||||
|
||||
// Automatically request persistent storage after project creation
|
||||
try {
|
||||
await ensurePersistentStorage();
|
||||
} catch (error) {
|
||||
// Don't fail project creation if persistent storage request fails
|
||||
console.warn('Failed to request persistent storage after project creation:', error);
|
||||
}
|
||||
|
||||
return project;
|
||||
}
|
||||
|
||||
@@ -119,6 +128,14 @@ export class ProjectsManager {
|
||||
const stats = await this.fs.stat(projectPath);
|
||||
const timestamp = stats.mtimeMs ? new Date(stats.mtimeMs) : new Date();
|
||||
|
||||
// Automatically request persistent storage after project cloning
|
||||
try {
|
||||
await ensurePersistentStorage();
|
||||
} catch (error) {
|
||||
// Don't fail project cloning if persistent storage request fails
|
||||
console.warn('Failed to request persistent storage after project cloning:', error);
|
||||
}
|
||||
|
||||
// Return the full project object with dynamically generated properties
|
||||
return {
|
||||
id,
|
||||
|
||||
@@ -242,6 +242,17 @@ const resources = {
|
||||
dataClearedSuccessfully: 'Data cleared successfully',
|
||||
dataClearedDescription: 'All local data has been removed. Redirecting to homepage...',
|
||||
failedToClearData: 'Failed to clear data',
|
||||
persistData: 'Persist Data',
|
||||
persistDataDescription: 'Request persistent storage to prevent data loss when browser storage is low. This helps protect your projects and settings.',
|
||||
persistentStorageGranted: 'Persistent storage granted',
|
||||
persistentStorageGrantedDescription: 'Your browser will now protect your data from automatic cleanup.',
|
||||
persistentStorageAlreadyGranted: 'Persistent storage already granted',
|
||||
persistentStorageAlreadyGrantedDescription: 'Your data is already protected from automatic cleanup.',
|
||||
persistentStorageDenied: 'Persistent storage request denied',
|
||||
persistentStorageDeniedDescription: 'Your browser declined the request. Data may still be cleared automatically when storage is low.',
|
||||
persistentStorageNotSupported: 'Persistent storage not supported',
|
||||
persistentStorageNotSupportedDescription: 'Your browser does not support persistent storage requests.',
|
||||
failedToRequestPersistentStorage: 'Failed to request persistent storage',
|
||||
|
||||
// 404 Page
|
||||
pageNotFound: 'Oops! Page not found',
|
||||
@@ -534,6 +545,17 @@ const resources = {
|
||||
dataClearedSuccessfully: 'Dados limpos com sucesso',
|
||||
dataClearedDescription: 'Todos os dados locais foram removidos. Redirecionando para a página inicial...',
|
||||
failedToClearData: 'Falha ao limpar dados',
|
||||
persistData: 'Persistir Dados',
|
||||
persistDataDescription: 'Solicitar armazenamento persistente para evitar perda de dados quando o armazenamento do navegador estiver baixo. Isso ajuda a proteger seus projetos e configurações.',
|
||||
persistentStorageGranted: 'Armazenamento persistente concedido',
|
||||
persistentStorageGrantedDescription: 'Seu navegador agora protegerá seus dados da limpeza automática.',
|
||||
persistentStorageAlreadyGranted: 'Armazenamento persistente já concedido',
|
||||
persistentStorageAlreadyGrantedDescription: 'Seus dados já estão protegidos da limpeza automática.',
|
||||
persistentStorageDenied: 'Solicitação de armazenamento persistente negada',
|
||||
persistentStorageDeniedDescription: 'Seu navegador recusou a solicitação. Os dados ainda podem ser limpos automaticamente quando o armazenamento estiver baixo.',
|
||||
persistentStorageNotSupported: 'Armazenamento persistente não suportado',
|
||||
persistentStorageNotSupportedDescription: 'Seu navegador não suporta solicitações de armazenamento persistente.',
|
||||
failedToRequestPersistentStorage: 'Falha ao solicitar armazenamento persistente',
|
||||
|
||||
// About Settings
|
||||
aboutShakespeare: 'Sobre o Shakespeare',
|
||||
@@ -836,6 +858,17 @@ const resources = {
|
||||
dataClearedSuccessfully: '数据清除成功',
|
||||
dataClearedDescription: '所有本地数据已删除。正在重定向到主页...',
|
||||
failedToClearData: '清除数据失败',
|
||||
persistData: '持久化数据',
|
||||
persistDataDescription: '请求持久存储以防止浏览器存储不足时数据丢失。这有助于保护您的项目和设置。',
|
||||
persistentStorageGranted: '已授予持久存储',
|
||||
persistentStorageGrantedDescription: '您的浏览器现在将保护您的数据免受自动清理。',
|
||||
persistentStorageAlreadyGranted: '已授予持久存储',
|
||||
persistentStorageAlreadyGrantedDescription: '您的数据已受到保护,不会被自动清理。',
|
||||
persistentStorageDenied: '持久存储请求被拒绝',
|
||||
persistentStorageDeniedDescription: '您的浏览器拒绝了请求。当存储不足时,数据仍可能被自动清理。',
|
||||
persistentStorageNotSupported: '不支持持久存储',
|
||||
persistentStorageNotSupportedDescription: '您的浏览器不支持持久存储请求。',
|
||||
failedToRequestPersistentStorage: '请求持久存储失败',
|
||||
|
||||
// About Settings
|
||||
aboutShakespeare: '关于Shakespeare',
|
||||
@@ -1138,6 +1171,17 @@ const resources = {
|
||||
dataClearedSuccessfully: 'An share bayanai cikin nasara',
|
||||
dataClearedDescription: 'An cire duk bayanan gida. Ana turawa zuwa shafin gida...',
|
||||
failedToClearData: 'Ya gaza share bayanai',
|
||||
persistData: 'Kiyaye Bayanai',
|
||||
persistDataDescription: 'Nemi ajiyar bayanai ta dindindin don hana asarar bayanai lokacin da ajiyar burauzar ta ragu. Wannan yana taimakawa wajen kare ayyukan ku da saitunan.',
|
||||
persistentStorageGranted: 'An ba da ajiyar ta dindindin',
|
||||
persistentStorageGrantedDescription: 'Burauzar ku yanzu za ta kare bayananku daga share mai sarrafa kansa.',
|
||||
persistentStorageAlreadyGranted: 'An riga an ba da ajiyar ta dindindin',
|
||||
persistentStorageAlreadyGrantedDescription: 'An riga an kare bayananku daga share mai sarrafa kansa.',
|
||||
persistentStorageDenied: 'An ki neman ajiyar ta dindindin',
|
||||
persistentStorageDeniedDescription: 'Burauzar ku ta ki bukatar. Ana iya share bayanai ta atomatik lokacin da ajiya ta ragu.',
|
||||
persistentStorageNotSupported: 'Ba a goyan bayan ajiyar ta dindindin ba',
|
||||
persistentStorageNotSupportedDescription: 'Burauzar ku ba ta goyan bayan bukatun ajiyar ta dindindin ba.',
|
||||
failedToRequestPersistentStorage: 'Ya gaza neman ajiyar ta dindindin',
|
||||
|
||||
// About Settings
|
||||
aboutShakespeare: 'Game da Shakespeare',
|
||||
@@ -1440,6 +1484,17 @@ const resources = {
|
||||
dataClearedSuccessfully: 'Data ti nu ni aṣeyọri',
|
||||
dataClearedDescription: 'Gbogbo data agbegbe ti yọ kuro. N ṣe atunṣe si oju-iwe ile...',
|
||||
failedToClearData: 'O kuna lati nu data',
|
||||
persistData: 'Fi Data Pamọ',
|
||||
persistDataDescription: 'Beere ibi ipamọ ti o wa nigbagbogbo lati yago fun isonu data nigbati ibi ipamọ aṣawakiri ba kere. Eyi ṣe iranlọwọ lati daabobo awọn iṣẹ akanṣe ati awọn eto rẹ.',
|
||||
persistentStorageGranted: 'Ibi ipamọ ti o wa nigbagbogbo ti funni',
|
||||
persistentStorageGrantedDescription: 'Aṣawakiri rẹ yoo daabobo data rẹ lati imukuro adaṣe.',
|
||||
persistentStorageAlreadyGranted: 'Ibi ipamọ ti o wa nigbagbogbo ti funni tẹlẹ',
|
||||
persistentStorageAlreadyGrantedDescription: 'Data rẹ ti wa ni aabo lati imukuro adaṣe.',
|
||||
persistentStorageDenied: 'Ibeere ibi ipamọ ti o wa nigbagbogbo ti kọ',
|
||||
persistentStorageDeniedDescription: 'Aṣawakiri rẹ ti kọ ibeere naa. Data le tun jẹ imukuro adaṣe nigbati ibi ipamọ ba kere.',
|
||||
persistentStorageNotSupported: 'Ibi ipamọ ti o wa nigbagbogbo ko ni atilẹyin',
|
||||
persistentStorageNotSupportedDescription: 'Aṣawakiri rẹ ko ni atilẹyin awọn ibeere ibi ipamọ ti o wa nigbagbogbo.',
|
||||
failedToRequestPersistentStorage: 'O kuna lati beere ibi ipamọ ti o wa nigbagbogbo',
|
||||
|
||||
// About Settings
|
||||
aboutShakespeare: 'Nipa Shakespeare',
|
||||
@@ -1737,6 +1792,17 @@ const resources = {
|
||||
dataClearedSuccessfully: 'Ehichapụrụ data nke ọma',
|
||||
dataClearedDescription: 'Ewepụrụ data mpaghara niile. Na-atụgharị gaa na ibe ụlọ...',
|
||||
failedToClearData: 'O dara ihichapụ data',
|
||||
persistData: 'Chekwaa Data Ogologo Oge',
|
||||
persistDataDescription: 'Rịọ nchekwa na-adịgide adịgide iji gbochie mfu data mgbe nchekwa browser dị ala. Nke a na-enyere aka ichebe ọrụ gị na ntọala.',
|
||||
persistentStorageGranted: 'Enyere nchekwa na-adịgide adịgide',
|
||||
persistentStorageGrantedDescription: 'Browser gị ga-echebe data gị ugbu a site na nhicha akpaaka.',
|
||||
persistentStorageAlreadyGranted: 'Enyerela nchekwa na-adịgide adịgide',
|
||||
persistentStorageAlreadyGrantedDescription: 'Echebeela data gị site na nhicha akpaaka.',
|
||||
persistentStorageDenied: 'Ajụrụ arịrịọ nchekwa na-adịgide adịgide',
|
||||
persistentStorageDeniedDescription: 'Browser gị jụrụ arịrịọ ahụ. Enwere ike ihichapụ data akpaaka mgbe nchekwa dị ala.',
|
||||
persistentStorageNotSupported: 'Akwadoghị nchekwa na-adịgide adịgide',
|
||||
persistentStorageNotSupportedDescription: 'Browser gị akwadoghị arịrịọ nchekwa na-adịgide adịgide.',
|
||||
failedToRequestPersistentStorage: 'O dara ịrịọ nchekwa na-adịgide adịgide',
|
||||
|
||||
// About Settings
|
||||
aboutShakespeare: 'Gbasara Shakespeare',
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
/**
|
||||
* Utility functions for managing persistent storage in the browser
|
||||
*/
|
||||
|
||||
/**
|
||||
* Checks if persistent storage is supported by the browser
|
||||
*/
|
||||
export function isPersistentStorageSupported(): boolean {
|
||||
return 'storage' in navigator && 'persist' in navigator.storage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if persistent storage is already granted
|
||||
*/
|
||||
export async function isPersistentStorageGranted(): Promise<boolean> {
|
||||
if (!isPersistentStorageSupported()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
return await navigator.storage.persisted();
|
||||
} catch (error) {
|
||||
console.warn('Failed to check persistent storage status:', error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests persistent storage from the browser
|
||||
* Returns true if granted, false if denied or not supported
|
||||
*/
|
||||
export async function requestPersistentStorage(): Promise<boolean> {
|
||||
if (!isPersistentStorageSupported()) {
|
||||
console.warn('Persistent storage is not supported in this browser');
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
// Check if already granted
|
||||
const alreadyGranted = await isPersistentStorageGranted();
|
||||
if (alreadyGranted) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Request persistent storage
|
||||
const granted = await navigator.storage.persist();
|
||||
return granted;
|
||||
} catch (error) {
|
||||
console.warn('Failed to request persistent storage:', error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Automatically requests persistent storage if not already granted
|
||||
* This is intended to be called silently after project creation/cloning
|
||||
* Returns true if persistent storage is available (either already granted or newly granted)
|
||||
*/
|
||||
export async function ensurePersistentStorage(): Promise<boolean> {
|
||||
try {
|
||||
// Check if already granted
|
||||
const alreadyGranted = await isPersistentStorageGranted();
|
||||
if (alreadyGranted) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Only request if supported
|
||||
if (!isPersistentStorageSupported()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Silently request persistent storage
|
||||
const granted = await requestPersistentStorage();
|
||||
|
||||
if (granted) {
|
||||
console.log('Persistent storage granted automatically');
|
||||
} else {
|
||||
console.log('Persistent storage request denied or failed');
|
||||
}
|
||||
|
||||
return granted;
|
||||
} catch (error) {
|
||||
console.warn('Failed to ensure persistent storage:', error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets current storage usage information
|
||||
*/
|
||||
export async function getStorageInfo(): Promise<{
|
||||
quota: number;
|
||||
usage: number;
|
||||
usageDetails?: Record<string, number>;
|
||||
} | null> {
|
||||
if (!('storage' in navigator)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
const estimate = await navigator.storage.estimate();
|
||||
return {
|
||||
quota: estimate.quota || 0,
|
||||
usage: estimate.usage || 0,
|
||||
usageDetails: (estimate as StorageEstimate & { usageDetails?: Record<string, number> }).usageDetails,
|
||||
};
|
||||
} catch (error) {
|
||||
console.warn('Failed to get storage information:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user