Compare commits
16 Commits
android-fi
...
meeting-me
| Author | SHA1 | Date | |
|---|---|---|---|
| e8e00d3eae | |||
| 5c0ce2d1fb | |||
| 9e1c267bc0 | |||
| 723a0095a0 | |||
| 9a94843b68 | |||
| 9f3c62a29c | |||
| 39173a8db2 | |||
| 7ea6a2ef69 | |||
| f0f0f1681e | |||
|
|
2f1eeb6700 | ||
|
|
e048e4c86b | ||
|
|
16ed5131c4 | ||
|
|
ad51c187aa | ||
|
|
6fbc9c2a5b | ||
|
|
035509224b | ||
|
|
e9ea89edae |
@@ -9,6 +9,10 @@ echo "🔍 Running pre-commit hooks..."
|
||||
|
||||
# Run lint-fix first
|
||||
echo "📝 Running lint-fix..."
|
||||
|
||||
# Capture git status before lint-fix to detect changes
|
||||
git_status_before=$(git status --porcelain)
|
||||
|
||||
npm run lint-fix || {
|
||||
echo
|
||||
echo "❌ Linting failed. Please fix the issues and try again."
|
||||
@@ -18,6 +22,36 @@ npm run lint-fix || {
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Check if lint-fix made any changes
|
||||
git_status_after=$(git status --porcelain)
|
||||
|
||||
if [ "$git_status_before" != "$git_status_after" ]; then
|
||||
echo
|
||||
echo "⚠️ lint-fix made changes to your files!"
|
||||
echo "📋 Changes detected:"
|
||||
git diff --name-only
|
||||
echo
|
||||
echo "❓ What would you like to do?"
|
||||
echo " [c] Continue commit without the new changes"
|
||||
echo " [a] Abort commit (recommended - review and stage the changes)"
|
||||
echo
|
||||
printf "Choose [c/a]: "
|
||||
# The `< /dev/tty` is necessary to make read work in git's non-interactive shell
|
||||
read choice < /dev/tty
|
||||
|
||||
case $choice in
|
||||
[Cc]* )
|
||||
echo "✅ Continuing commit without lint-fix changes..."
|
||||
sleep 3
|
||||
;;
|
||||
[Aa]* | * )
|
||||
echo "🛑 Commit aborted. Please review the changes made by lint-fix."
|
||||
echo "💡 You can stage the changes with 'git add .' and commit again."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Then run Build Architecture Guard
|
||||
|
||||
#echo "🏗️ Running Build Architecture Guard..."
|
||||
|
||||
@@ -1,251 +0,0 @@
|
||||
# Android File Saver Plugin Implementation Guide
|
||||
|
||||
## Overview
|
||||
|
||||
This document outlines the implementation of the `AndroidFileSaver` Capacitor plugin that provides Storage Access Framework (SAF) and MediaStore functionality for direct file saving on Android devices.
|
||||
|
||||
## Plugin Purpose
|
||||
|
||||
The `AndroidFileSaver` plugin enables two key file operations:
|
||||
1. **`saveToDownloads`**: Direct save to Downloads folder using MediaStore (API 29+)
|
||||
2. **`saveAs`**: User-chosen location using Storage Access Framework (SAF)
|
||||
|
||||
## Implementation Requirements
|
||||
|
||||
### 1. Plugin Structure
|
||||
|
||||
```typescript
|
||||
// Plugin interface
|
||||
interface AndroidFileSaverPlugin {
|
||||
saveToDownloads(options: {
|
||||
fileName: string;
|
||||
content: string;
|
||||
mimeType: string
|
||||
}): Promise<{
|
||||
success: boolean;
|
||||
path?: string;
|
||||
error?: string
|
||||
}>;
|
||||
|
||||
saveAs(options: {
|
||||
fileName: string;
|
||||
content: string;
|
||||
mimeType: string
|
||||
}): Promise<{
|
||||
success: boolean;
|
||||
path?: string;
|
||||
error?: string
|
||||
}>;
|
||||
}
|
||||
```
|
||||
|
||||
### 2. Android Implementation
|
||||
|
||||
#### MediaStore for Downloads (API 29+)
|
||||
|
||||
```java
|
||||
@PluginMethod
|
||||
public void saveToDownloads(PluginCall call) {
|
||||
String fileName = call.getString("fileName");
|
||||
String content = call.getString("content");
|
||||
String mimeType = call.getString("mimeType");
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
// Use MediaStore for Downloads
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(MediaStore.Downloads.DISPLAY_NAME, fileName);
|
||||
values.put(MediaStore.Downloads.MIME_TYPE, mimeType);
|
||||
values.put(MediaStore.Downloads.IS_PENDING, 1);
|
||||
|
||||
ContentResolver resolver = getContext().getContentResolver();
|
||||
Uri uri = resolver.insert(MediaStore.Downloads.EXTERNAL_CONTENT_URI, values);
|
||||
|
||||
if (uri != null) {
|
||||
try (ParcelFileDescriptor pfd = resolver.openFileDescriptor(uri, "w")) {
|
||||
if (pfd != null) {
|
||||
try (FileOutputStream fos = new FileOutputStream(pfd.getFileDescriptor())) {
|
||||
fos.write(content.getBytes());
|
||||
fos.flush();
|
||||
|
||||
// Mark as no longer pending
|
||||
values.clear();
|
||||
values.put(MediaStore.Downloads.IS_PENDING, 0);
|
||||
resolver.update(uri, values, null, null);
|
||||
|
||||
call.resolve(new JSObject()
|
||||
.put("success", true)
|
||||
.put("path", uri.toString()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
resolver.delete(uri, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
call.resolve(new JSObject()
|
||||
.put("success", false)
|
||||
.put("error", "Failed to save file"));
|
||||
} else {
|
||||
// Fallback for older Android versions
|
||||
call.resolve(new JSObject()
|
||||
.put("success", false)
|
||||
.put("error", "Requires Android API 29+"));
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Storage Access Framework (SAF) for Save As
|
||||
|
||||
```java
|
||||
@PluginMethod
|
||||
public void saveAs(PluginCall call) {
|
||||
String fileName = call.getString("fileName");
|
||||
String content = call.getString("content");
|
||||
String mimeType = call.getString("mimeType");
|
||||
|
||||
// Store call for later use
|
||||
bridge.saveCall(call);
|
||||
|
||||
// Create intent for SAF
|
||||
Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
intent.setType(mimeType);
|
||||
intent.putExtra(Intent.EXTRA_TITLE, fileName);
|
||||
|
||||
// Start activity for result
|
||||
bridge.startActivityForResult(call, intent, "saveAsResult");
|
||||
}
|
||||
|
||||
@ActivityCallback
|
||||
private void saveAsResult(PluginCall call, ActivityResult result) {
|
||||
if (result.getResultCode() == Activity.RESULT_OK && result.getData() != null) {
|
||||
Uri uri = result.getData().getData();
|
||||
String content = call.getString("content");
|
||||
|
||||
try (ParcelFileDescriptor pfd = getContext().getContentResolver()
|
||||
.openFileDescriptor(uri, "w")) {
|
||||
if (pfd != null) {
|
||||
try (FileOutputStream fos = new FileOutputStream(pfd.getFileDescriptor())) {
|
||||
fos.write(content.getBytes());
|
||||
fos.flush();
|
||||
|
||||
call.resolve(new JSObject()
|
||||
.put("success", true)
|
||||
.put("path", uri.toString()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// Handle error
|
||||
}
|
||||
|
||||
call.resolve(new JSObject()
|
||||
.put("success", false)
|
||||
.put("error", "Failed to save file"));
|
||||
} else {
|
||||
call.resolve(new JSObject()
|
||||
.put("success", false)
|
||||
.put("error", "User cancelled or failed"));
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 3. Plugin Registration
|
||||
|
||||
```java
|
||||
@CapacitorPlugin(name = "AndroidFileSaver")
|
||||
public class AndroidFileSaverPlugin extends Plugin {
|
||||
// Implementation methods here
|
||||
}
|
||||
```
|
||||
|
||||
## Integration Steps
|
||||
|
||||
### 1. Create Plugin Project
|
||||
|
||||
```bash
|
||||
# Create new Capacitor plugin
|
||||
npx @capacitor/cli plugin:generate android-file-saver
|
||||
cd android-file-saver
|
||||
```
|
||||
|
||||
### 2. Add to Android Project
|
||||
|
||||
```bash
|
||||
# In your main project
|
||||
npm install ./android-file-saver
|
||||
npx cap sync android
|
||||
```
|
||||
|
||||
### 3. Update Android Manifest
|
||||
|
||||
Ensure the following permissions are present:
|
||||
|
||||
```xml
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
||||
android:maxSdkVersion="28" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
|
||||
android:maxSdkVersion="32" />
|
||||
```
|
||||
|
||||
## Fallback Behavior
|
||||
|
||||
When the plugin is not available, the system falls back to:
|
||||
1. **Web**: Browser download mechanism
|
||||
2. **Electron**: Native file save via IPC
|
||||
3. **Capacitor**: Share dialog (existing behavior)
|
||||
|
||||
## Testing
|
||||
|
||||
### 1. Plugin Availability
|
||||
|
||||
```typescript
|
||||
// Check if plugin is available
|
||||
if (AndroidFileSaver) {
|
||||
// Plugin available - use native methods
|
||||
} else {
|
||||
// Plugin not available - use fallback
|
||||
}
|
||||
```
|
||||
|
||||
### 2. Error Handling
|
||||
|
||||
```typescript
|
||||
try {
|
||||
const result = await AndroidFileSaver.saveToDownloads({
|
||||
fileName: "test.json",
|
||||
content: '{"test": "data"}',
|
||||
mimeType: "application/json"
|
||||
});
|
||||
|
||||
if (result.success) {
|
||||
logger.info("File saved:", result.path);
|
||||
} else {
|
||||
logger.error("Save failed:", result.error);
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error("Plugin error:", error);
|
||||
}
|
||||
```
|
||||
|
||||
## Security Considerations
|
||||
|
||||
1. **Content Validation**: Validate file content before saving
|
||||
2. **MIME Type Verification**: Ensure MIME type matches file content
|
||||
3. **Permission Handling**: Request storage permissions appropriately
|
||||
4. **Error Logging**: Log errors without exposing sensitive data
|
||||
|
||||
## Future Enhancements
|
||||
|
||||
1. **Progress Callbacks**: Add progress reporting for large files
|
||||
2. **Batch Operations**: Support saving multiple files
|
||||
3. **Custom Locations**: Allow saving to app-specific directories
|
||||
4. **File Compression**: Add optional file compression
|
||||
|
||||
## References
|
||||
|
||||
- [Android Storage Access Framework](https://developer.android.com/guide/topics/providers/document-provider)
|
||||
- [MediaStore Downloads](https://developer.android.com/reference/android/provider/MediaStore.Downloads)
|
||||
- [Capacitor Plugin Development](https://capacitorjs.com/docs/plugins/android)
|
||||
- [Android Scoped Storage](https://developer.android.com/training/data-storage)
|
||||
376
src/components/AdmitPendingMembersDialog.vue
Normal file
376
src/components/AdmitPendingMembersDialog.vue
Normal file
@@ -0,0 +1,376 @@
|
||||
<template>
|
||||
<div v-if="visible" class="dialog-overlay">
|
||||
<div class="dialog">
|
||||
<div class="text-slate-900 text-center">
|
||||
<h3 class="text-lg font-semibold leading-[1.25] mb-2">
|
||||
Admit Pending Members
|
||||
</h3>
|
||||
<p class="text-sm mb-4">
|
||||
The following members are waiting to be admitted to the meeting. You
|
||||
can choose to admit them and optionally add them as contacts with
|
||||
visibility settings.
|
||||
</p>
|
||||
|
||||
<!-- Custom table area - you can customize this -->
|
||||
<div class="mb-4">
|
||||
<table
|
||||
class="w-full border-collapse border border-slate-300 text-sm text-start"
|
||||
>
|
||||
<thead v-if="membersData && membersData.length > 0">
|
||||
<tr class="bg-slate-100 font-medium">
|
||||
<th class="border border-slate-300 px-3 py-2">
|
||||
<label class="flex items-center gap-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
:checked="isAllSelected"
|
||||
:indeterminate="isIndeterminate"
|
||||
@change="toggleSelectAll"
|
||||
/>
|
||||
Select All
|
||||
</label>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<!-- Dynamic data from MembersList -->
|
||||
<tr v-if="!membersData || membersData.length === 0">
|
||||
<td
|
||||
class="border border-slate-300 px-3 py-2 text-center italic text-gray-500"
|
||||
>
|
||||
No pending members to admit
|
||||
</td>
|
||||
</tr>
|
||||
<tr
|
||||
v-for="member in membersData || []"
|
||||
:key="member.member.memberId"
|
||||
>
|
||||
<td class="border border-slate-300 px-3 py-2">
|
||||
<div class="flex items-center justify-between gap-2">
|
||||
<label class="flex items-center gap-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
:checked="isMemberSelected(member.did)"
|
||||
@change="toggleMemberSelection(member.did)"
|
||||
/>
|
||||
<div class="">
|
||||
<div class="text-sm font-semibold">
|
||||
{{ member.name || SOMEONE_UNNAMED }}
|
||||
</div>
|
||||
<div
|
||||
class="flex items-center gap-0.5 text-xs text-slate-500"
|
||||
>
|
||||
<span class="font-semibold sm:hidden">DID:</span>
|
||||
<span
|
||||
class="w-[35vw] sm:w-auto truncate text-left"
|
||||
style="direction: rtl"
|
||||
>{{ member.did }}</span
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</label>
|
||||
|
||||
<!-- Contact indicator - only show if they are already a contact -->
|
||||
<font-awesome
|
||||
v-if="member.isContact"
|
||||
icon="user-circle"
|
||||
class="fa-fw ms-auto text-slate-400 cursor-pointer hover:text-slate-600"
|
||||
@click="showContactInfo"
|
||||
/>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="space-y-2">
|
||||
<button
|
||||
v-if="membersData && membersData.length > 0"
|
||||
:disabled="!hasSelectedMembers"
|
||||
:class="[
|
||||
'block w-full text-center text-md font-bold uppercase px-2 py-2 rounded-md',
|
||||
hasSelectedMembers
|
||||
? 'bg-green-600 text-white cursor-pointer'
|
||||
: 'bg-slate-400 text-slate-200 cursor-not-allowed',
|
||||
]"
|
||||
@click="admitWithVisibility"
|
||||
>
|
||||
Admit + Add to Contacts
|
||||
</button>
|
||||
<button
|
||||
class="block w-full text-center text-md font-bold uppercase bg-slate-600 text-white px-2 py-2 rounded-md"
|
||||
@click="cancel"
|
||||
>
|
||||
Maybe Later
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { Vue, Component, Prop } from "vue-facing-decorator";
|
||||
|
||||
import { PlatformServiceMixin } from "@/utils/PlatformServiceMixin";
|
||||
import { SOMEONE_UNNAMED } from "@/constants/entities";
|
||||
import { MemberData } from "@/interfaces";
|
||||
import { setVisibilityUtil, getHeaders } from "@/libs/endorserServer";
|
||||
import { createNotifyHelpers } from "@/utils/notify";
|
||||
|
||||
@Component({
|
||||
mixins: [PlatformServiceMixin],
|
||||
emits: ["close"],
|
||||
})
|
||||
export default class AdmitPendingMembersDialog extends Vue {
|
||||
@Prop({ default: "" }) activeDid!: string;
|
||||
@Prop({ default: "" }) apiServer!: string;
|
||||
|
||||
// Vue notification system
|
||||
$notify!: (
|
||||
notification: { group: string; type: string; title: string; text: string },
|
||||
timeout?: number,
|
||||
) => void;
|
||||
|
||||
// Notification system
|
||||
notify!: ReturnType<typeof createNotifyHelpers>;
|
||||
|
||||
// Component state
|
||||
membersData: MemberData[] = [];
|
||||
selectedMembers: string[] = [];
|
||||
visible = false;
|
||||
|
||||
// Constants
|
||||
// In Vue templates, imported constants need to be explicitly made available to the template
|
||||
readonly SOMEONE_UNNAMED = SOMEONE_UNNAMED;
|
||||
|
||||
get hasSelectedMembers() {
|
||||
return this.selectedMembers.length > 0;
|
||||
}
|
||||
|
||||
get isAllSelected() {
|
||||
if (!this.membersData || this.membersData.length === 0) return false;
|
||||
return this.membersData.every((member) =>
|
||||
this.selectedMembers.includes(member.did),
|
||||
);
|
||||
}
|
||||
|
||||
get isIndeterminate() {
|
||||
if (!this.membersData || this.membersData.length === 0) return false;
|
||||
const selectedCount = this.membersData.filter((member) =>
|
||||
this.selectedMembers.includes(member.did),
|
||||
).length;
|
||||
return selectedCount > 0 && selectedCount < this.membersData.length;
|
||||
}
|
||||
|
||||
created() {
|
||||
this.notify = createNotifyHelpers(this.$notify);
|
||||
}
|
||||
|
||||
open(members: MemberData[]) {
|
||||
this.visible = true;
|
||||
this.membersData = members;
|
||||
// Select all by default
|
||||
this.selectedMembers = this.membersData.map((member) => member.did);
|
||||
}
|
||||
|
||||
close(notSelectedMemberDids: string[]) {
|
||||
this.visible = false;
|
||||
this.$emit("close", { notSelectedMemberDids: notSelectedMemberDids });
|
||||
}
|
||||
|
||||
cancel() {
|
||||
this.close(this.membersData.map((member) => member.did));
|
||||
}
|
||||
|
||||
toggleSelectAll() {
|
||||
if (!this.membersData || this.membersData.length === 0) return;
|
||||
|
||||
if (this.isAllSelected) {
|
||||
// Deselect all
|
||||
this.selectedMembers = [];
|
||||
} else {
|
||||
// Select all
|
||||
this.selectedMembers = this.membersData.map((member) => member.did);
|
||||
}
|
||||
}
|
||||
|
||||
toggleMemberSelection(memberDid: string) {
|
||||
const index = this.selectedMembers.indexOf(memberDid);
|
||||
if (index > -1) {
|
||||
this.selectedMembers.splice(index, 1);
|
||||
} else {
|
||||
this.selectedMembers.push(memberDid);
|
||||
}
|
||||
}
|
||||
|
||||
isMemberSelected(memberDid: string) {
|
||||
return this.selectedMembers.includes(memberDid);
|
||||
}
|
||||
|
||||
async admitWithVisibility() {
|
||||
try {
|
||||
const selectedMembers = this.membersData.filter((member) =>
|
||||
this.selectedMembers.includes(member.did),
|
||||
);
|
||||
const notSelectedMembers = this.membersData.filter(
|
||||
(member) => !this.selectedMembers.includes(member.did),
|
||||
);
|
||||
|
||||
let admittedCount = 0;
|
||||
let contactAddedCount = 0;
|
||||
let visibilitySetCount = 0;
|
||||
|
||||
for (const member of selectedMembers) {
|
||||
try {
|
||||
// First, admit the member
|
||||
await this.admitMember(member);
|
||||
admittedCount++;
|
||||
|
||||
// If they're not a contact yet, add them as a contact
|
||||
if (!member.isContact) {
|
||||
await this.addAsContact(member);
|
||||
contactAddedCount++;
|
||||
}
|
||||
|
||||
// Set their seesMe to true
|
||||
await this.updateContactVisibility(member.did, true);
|
||||
visibilitySetCount++;
|
||||
} catch (error) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(`Error processing member ${member.did}:`, error);
|
||||
// Continue with other members even if one fails
|
||||
}
|
||||
}
|
||||
|
||||
// Show success notification
|
||||
this.$notify(
|
||||
{
|
||||
group: "alert",
|
||||
type: "success",
|
||||
title: "Members Admitted Successfully",
|
||||
text: `Admitted ${admittedCount} member${admittedCount === 1 ? "" : "s"}, added ${contactAddedCount} as contact${contactAddedCount === 1 ? "" : "s"}, and set visibility for ${visibilitySetCount} member${visibilitySetCount === 1 ? "" : "s"}.`,
|
||||
},
|
||||
10000,
|
||||
);
|
||||
|
||||
this.close(notSelectedMembers.map((member) => member.did));
|
||||
} catch (error) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error("Error admitting members:", error);
|
||||
this.$notify(
|
||||
{
|
||||
group: "alert",
|
||||
type: "danger",
|
||||
title: "Error",
|
||||
text: "Failed to admit some members. Please try again.",
|
||||
},
|
||||
5000,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async admitMember(member: {
|
||||
did: string;
|
||||
name: string;
|
||||
member: { memberId: string };
|
||||
}) {
|
||||
try {
|
||||
const headers = await getHeaders(this.activeDid);
|
||||
await this.axios.put(
|
||||
`${this.apiServer}/api/partner/groupOnboardMember/${member.member.memberId}`,
|
||||
{ admitted: true },
|
||||
{ headers },
|
||||
);
|
||||
} catch (err) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error("Error admitting member:", err);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
async addAsContact(member: { did: string; name: string }) {
|
||||
try {
|
||||
const newContact = {
|
||||
did: member.did,
|
||||
name: member.name,
|
||||
};
|
||||
|
||||
await this.$insertContact(newContact);
|
||||
} catch (err) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error("Error adding contact:", err);
|
||||
if (err instanceof Error && err.message?.indexOf("already exists") > -1) {
|
||||
// Contact already exists, continue
|
||||
} else {
|
||||
throw err; // Re-throw if it's not a duplicate error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async updateContactVisibility(did: string, seesMe: boolean) {
|
||||
try {
|
||||
// Get the contact object
|
||||
const contact = await this.$getContact(did);
|
||||
if (!contact) {
|
||||
throw new Error(`Contact not found for DID: ${did}`);
|
||||
}
|
||||
|
||||
// Use the proper API to set visibility on the server
|
||||
const result = await setVisibilityUtil(
|
||||
this.activeDid,
|
||||
this.apiServer,
|
||||
this.axios,
|
||||
contact,
|
||||
seesMe,
|
||||
);
|
||||
|
||||
if (!result.success) {
|
||||
throw new Error(result.error || "Failed to set visibility");
|
||||
}
|
||||
} catch (err) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error("Error updating contact visibility:", err);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
showContactInfo() {
|
||||
this.$notify(
|
||||
{
|
||||
group: "alert",
|
||||
type: "info",
|
||||
title: "Contact Info",
|
||||
text: "This user is already your contact, but they are not yet admitted to the meeting.",
|
||||
},
|
||||
5000,
|
||||
);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.dialog-overlay {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.dialog {
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
padding: 24px;
|
||||
max-width: 500px;
|
||||
width: 90%;
|
||||
max-height: 80vh;
|
||||
overflow-y: auto;
|
||||
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
</style>
|
||||
@@ -25,46 +25,33 @@ messages * - Conditional UI based on platform capabilities * * @component *
|
||||
Backup Identifier Seed
|
||||
</router-link>
|
||||
|
||||
<div class="flex flex-col gap-2 mt-2">
|
||||
<button
|
||||
:disabled="isExporting"
|
||||
:class="shareButtonClasses"
|
||||
@click="shareContacts()"
|
||||
>
|
||||
{{ isExporting ? "Exporting..." : "Share Contacts" }}
|
||||
</button>
|
||||
|
||||
<button
|
||||
:disabled="isExporting"
|
||||
:class="saveButtonClasses"
|
||||
@click="saveContactsToDevice()"
|
||||
>
|
||||
{{ isExporting ? "Exporting..." : "Save to Device" }}
|
||||
</button>
|
||||
</div>
|
||||
<button
|
||||
:disabled="isExporting"
|
||||
:class="exportButtonClasses"
|
||||
@click="exportDatabase()"
|
||||
>
|
||||
{{ isExporting ? "Exporting..." : "Download Contacts" }}
|
||||
</button>
|
||||
|
||||
<div
|
||||
v-if="capabilities.needsFileHandlingInstructions"
|
||||
:class="instructionsContainerClasses"
|
||||
>
|
||||
<p>Choose how you want to export your contacts:</p>
|
||||
<p>
|
||||
After the export, you can save the file in your preferred storage
|
||||
location.
|
||||
</p>
|
||||
<ul>
|
||||
<li :class="listItemClasses">
|
||||
<strong>Share Contacts:</strong> Opens the system share dialog to send
|
||||
to apps like Gmail, Drive, or messaging apps.
|
||||
</li>
|
||||
<li :class="listItemClasses">
|
||||
<strong>Save to Device:</strong> Saves directly to your device's
|
||||
Downloads folder (Android) or Documents folder (iOS).
|
||||
</li>
|
||||
<li v-if="capabilities.isIOS" :class="listItemClasses">
|
||||
On iOS: Files are saved to the Files app in your Documents folder.
|
||||
On iOS: You will be prompted to choose a location to save your backup
|
||||
file.
|
||||
</li>
|
||||
<li
|
||||
v-if="capabilities.isMobile && !capabilities.isIOS"
|
||||
:class="listItemClasses"
|
||||
>
|
||||
On Android: Files are saved directly to your Downloads folder.
|
||||
On Android: You will be prompted to choose a location to save your
|
||||
backup file.
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -164,20 +151,6 @@ export default class DataExportSection extends Vue {
|
||||
return "block w-full text-center text-md bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-1.5 py-2 rounded-md disabled:opacity-50 disabled:cursor-not-allowed";
|
||||
}
|
||||
|
||||
/**
|
||||
* CSS classes for the share button
|
||||
*/
|
||||
get shareButtonClasses(): string {
|
||||
return "block w-full text-center text-md bg-gradient-to-b from-green-400 to-green-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-1.5 py-2 rounded-md disabled:opacity-50 disabled:cursor-not-allowed";
|
||||
}
|
||||
|
||||
/**
|
||||
* CSS classes for the save to device button
|
||||
*/
|
||||
get saveButtonClasses(): string {
|
||||
return "block w-full text-center text-md bg-gradient-to-b from-purple-400 to-purple-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-1.5 py-2 rounded-md disabled:opacity-50 disabled:cursor-not-allowed";
|
||||
}
|
||||
|
||||
/**
|
||||
* CSS classes for the instructions container
|
||||
*/
|
||||
@@ -255,100 +228,6 @@ export default class DataExportSection extends Vue {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shares contacts data using the platform's share functionality
|
||||
* Opens the system share dialog for app-to-app handoff
|
||||
*
|
||||
* @throws {Error} If sharing fails
|
||||
*/
|
||||
public async shareContacts(): Promise<void> {
|
||||
if (this.isExporting) {
|
||||
return; // Prevent multiple simultaneous exports
|
||||
}
|
||||
|
||||
try {
|
||||
this.isExporting = true;
|
||||
|
||||
// Fetch contacts from database using mixin's cached method
|
||||
const allContacts = await this.$contacts();
|
||||
|
||||
// Convert contacts to export format
|
||||
const processedContacts: Contact[] = allContacts.map((contact) => {
|
||||
const exContact: Contact = R.omit(["contactMethods"], contact);
|
||||
exContact.contactMethods = contact.contactMethods
|
||||
? typeof contact.contactMethods === "string" &&
|
||||
contact.contactMethods.trim() !== ""
|
||||
? JSON.parse(contact.contactMethods)
|
||||
: []
|
||||
: [];
|
||||
return exContact;
|
||||
});
|
||||
|
||||
const exportData = contactsToExportJson(processedContacts);
|
||||
const jsonStr = JSON.stringify(exportData, null, 2);
|
||||
|
||||
// Use platform service to share the file
|
||||
await this.platformService.writeAndShareFile(this.fileName, jsonStr);
|
||||
|
||||
this.notify.success(
|
||||
"Contact sharing completed successfully. Use the share dialog to send to your preferred app.",
|
||||
);
|
||||
} catch (error) {
|
||||
logger.error("Share Error:", error);
|
||||
this.notify.error(
|
||||
`There was an error sharing the data: ${error instanceof Error ? error.message : "Unknown error"}`,
|
||||
);
|
||||
} finally {
|
||||
this.isExporting = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves contacts data directly to the device's storage
|
||||
* Uses platform-specific save methods (Downloads folder, Documents, etc.)
|
||||
*
|
||||
* @throws {Error} If saving fails
|
||||
*/
|
||||
public async saveContactsToDevice(): Promise<void> {
|
||||
if (this.isExporting) {
|
||||
return; // Prevent multiple simultaneous exports
|
||||
}
|
||||
|
||||
try {
|
||||
this.isExporting = true;
|
||||
|
||||
// Fetch contacts from database using mixin's cached method
|
||||
const allContacts = await this.$contacts();
|
||||
|
||||
// Convert contacts to export format
|
||||
const processedContacts: Contact[] = allContacts.map((contact) => {
|
||||
const exContact: Contact = R.omit(["contactMethods"], contact);
|
||||
exContact.contactMethods = contact.contactMethods
|
||||
? typeof contact.contactMethods === "string" &&
|
||||
contact.contactMethods.trim() !== ""
|
||||
? JSON.parse(contact.contactMethods)
|
||||
: []
|
||||
: [];
|
||||
return exContact;
|
||||
});
|
||||
|
||||
const exportData = contactsToExportJson(processedContacts);
|
||||
const jsonStr = JSON.stringify(exportData, null, 2);
|
||||
|
||||
// Use platform service to save directly to device
|
||||
await this.platformService.saveToDevice(this.fileName, jsonStr);
|
||||
|
||||
this.notify.success("Contact data saved successfully to your device.");
|
||||
} catch (error) {
|
||||
logger.error("Save Error:", error);
|
||||
this.notify.error(
|
||||
`There was an error saving the data: ${error instanceof Error ? error.message : "Unknown error"}`,
|
||||
);
|
||||
} finally {
|
||||
this.isExporting = false;
|
||||
}
|
||||
}
|
||||
|
||||
created() {
|
||||
this.notify = createNotifyHelpers(this.$notify);
|
||||
this.loadSeedBackupStatus();
|
||||
|
||||
@@ -1,196 +1,226 @@
|
||||
<template>
|
||||
<div class="space-y-4">
|
||||
<!-- Loading State -->
|
||||
<div
|
||||
v-if="isLoading"
|
||||
class="mt-16 text-center text-4xl bg-slate-400 text-white w-14 py-2.5 rounded-full mx-auto"
|
||||
>
|
||||
<font-awesome icon="spinner" class="fa-spin-pulse" />
|
||||
</div>
|
||||
|
||||
<!-- Members List -->
|
||||
|
||||
<div v-else>
|
||||
<div class="text-center text-red-600 my-4">
|
||||
{{ decryptionErrorMessage() }}
|
||||
</div>
|
||||
|
||||
<div v-if="missingMyself" class="py-4 text-red-600">
|
||||
You are not currently admitted by the organizer.
|
||||
</div>
|
||||
<div v-if="!firstName" class="py-4 text-red-600">
|
||||
Your name is not set, so others may not recognize you. Reload this page
|
||||
to set it.
|
||||
</div>
|
||||
|
||||
<ul class="list-disc text-sm ps-4 space-y-2 mb-4">
|
||||
<li
|
||||
v-if="membersToShow().length > 0 && showOrganizerTools && isOrganizer"
|
||||
>
|
||||
Click
|
||||
<span
|
||||
class="inline-block w-5 h-5 rounded-full bg-blue-100 text-blue-600 text-center"
|
||||
>
|
||||
<font-awesome icon="plus" class="text-sm" />
|
||||
</span>
|
||||
/
|
||||
<span
|
||||
class="inline-block w-5 h-5 rounded-full bg-blue-100 text-blue-600 text-center"
|
||||
>
|
||||
<font-awesome icon="minus" class="text-sm" />
|
||||
</span>
|
||||
to add/remove them to/from the meeting.
|
||||
</li>
|
||||
<li v-if="membersToShow().length > 0">
|
||||
Click
|
||||
<span
|
||||
class="inline-block w-5 h-5 rounded-full bg-green-100 text-green-600 text-center"
|
||||
>
|
||||
<font-awesome icon="circle-user" class="text-sm" />
|
||||
</span>
|
||||
to add them to your contacts.
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div class="flex justify-between">
|
||||
<!--
|
||||
always have at least one refresh button even without members in case the organizer
|
||||
changes the password
|
||||
-->
|
||||
<button
|
||||
class="text-sm bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-3 py-1.5 rounded-md"
|
||||
title="Refresh members list now"
|
||||
@click="manualRefresh"
|
||||
>
|
||||
<font-awesome icon="rotate" :class="{ 'fa-spin': isLoading }" />
|
||||
Refresh
|
||||
<span class="text-xs">({{ countdownTimer }}s)</span>
|
||||
</button>
|
||||
</div>
|
||||
<ul
|
||||
v-if="membersToShow().length > 0"
|
||||
class="border-t border-slate-300 my-2"
|
||||
<div>
|
||||
<div class="space-y-4">
|
||||
<!-- Loading State -->
|
||||
<div
|
||||
v-if="isLoading"
|
||||
class="mt-16 text-center text-4xl bg-slate-400 text-white w-14 py-2.5 rounded-full mx-auto"
|
||||
>
|
||||
<li
|
||||
v-for="member in membersToShow()"
|
||||
:key="member.member.memberId"
|
||||
class="border-b border-slate-300 py-1.5"
|
||||
>
|
||||
<div class="flex items-center gap-2 justify-between">
|
||||
<div class="flex items-center gap-1 overflow-hidden">
|
||||
<h3 class="font-semibold truncate">
|
||||
{{ member.name || unnamedMember }}
|
||||
</h3>
|
||||
<div
|
||||
v-if="!getContactFor(member.did) && member.did !== activeDid"
|
||||
class="flex items-center gap-1"
|
||||
>
|
||||
<button
|
||||
class="btn-add-contact"
|
||||
title="Add as contact"
|
||||
@click="addAsContact(member)"
|
||||
>
|
||||
<font-awesome icon="circle-user" />
|
||||
</button>
|
||||
<font-awesome icon="spinner" class="fa-spin-pulse" />
|
||||
</div>
|
||||
|
||||
<button
|
||||
class="btn-info-contact"
|
||||
title="Contact Info"
|
||||
@click="
|
||||
informAboutAddingContact(
|
||||
getContactFor(member.did) !== undefined,
|
||||
)
|
||||
"
|
||||
>
|
||||
<font-awesome icon="circle-info" class="text-sm" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<span
|
||||
v-if="
|
||||
showOrganizerTools && isOrganizer && member.did !== activeDid
|
||||
"
|
||||
class="flex items-center gap-1"
|
||||
>
|
||||
<button
|
||||
class="btn-admission"
|
||||
:title="
|
||||
member.member.admitted ? 'Remove member' : 'Admit member'
|
||||
"
|
||||
@click="checkWhetherContactBeforeAdmitting(member)"
|
||||
>
|
||||
<font-awesome
|
||||
:icon="member.member.admitted ? 'minus' : 'plus'"
|
||||
/>
|
||||
</button>
|
||||
<!-- Members List -->
|
||||
|
||||
<button
|
||||
class="btn-info-admission"
|
||||
title="Admission Info"
|
||||
@click="informAboutAdmission()"
|
||||
>
|
||||
<font-awesome icon="circle-info" class="text-sm" />
|
||||
</button>
|
||||
</span>
|
||||
</div>
|
||||
<p class="text-xs text-gray-600 truncate">
|
||||
{{ member.did }}
|
||||
</p>
|
||||
</li>
|
||||
</ul>
|
||||
<div v-else>
|
||||
<div class="text-center text-red-600 my-4">
|
||||
{{ decryptionErrorMessage() }}
|
||||
</div>
|
||||
|
||||
<div v-if="membersToShow().length > 0" class="flex justify-between">
|
||||
<!--
|
||||
<div v-if="missingMyself" class="py-4 text-red-600">
|
||||
You are not currently admitted by the organizer.
|
||||
</div>
|
||||
<div v-if="!firstName" class="py-4 text-red-600">
|
||||
Your name is not set, so others may not recognize you. Reload this
|
||||
page to set it.
|
||||
</div>
|
||||
|
||||
<ul class="list-disc text-sm ps-4 space-y-2 mb-4">
|
||||
<li
|
||||
v-if="
|
||||
membersToShow().length > 0 && showOrganizerTools && isOrganizer
|
||||
"
|
||||
>
|
||||
Click
|
||||
<font-awesome icon="circle-plus" class="text-blue-500 text-sm" />
|
||||
/
|
||||
<font-awesome icon="circle-minus" class="text-rose-500 text-sm" />
|
||||
to add/remove them to/from the meeting.
|
||||
</li>
|
||||
<li v-if="membersToShow().length > 0">
|
||||
Click
|
||||
<font-awesome icon="circle-user" class="text-green-600 text-sm" />
|
||||
to add them to your contacts.
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div class="flex justify-between">
|
||||
<!--
|
||||
always have at least one refresh button even without members in case the organizer
|
||||
changes the password
|
||||
-->
|
||||
<button
|
||||
class="text-sm bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-3 py-1.5 rounded-md"
|
||||
title="Refresh members list now"
|
||||
@click="manualRefresh"
|
||||
<button
|
||||
class="text-sm bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-3 py-1.5 rounded-md"
|
||||
title="Refresh members list now"
|
||||
@click="refreshData(false)"
|
||||
>
|
||||
<font-awesome icon="rotate" :class="{ 'fa-spin': isLoading }" />
|
||||
Refresh
|
||||
<span class="text-xs">({{ countdownTimer }}s)</span>
|
||||
</button>
|
||||
</div>
|
||||
<ul
|
||||
v-if="membersToShow().length > 0"
|
||||
class="border-t border-slate-300 my-2"
|
||||
>
|
||||
<font-awesome icon="rotate" :class="{ 'fa-spin': isLoading }" />
|
||||
Refresh
|
||||
<span class="text-xs">({{ countdownTimer }}s)</span>
|
||||
</button>
|
||||
<li
|
||||
v-for="member in membersToShow()"
|
||||
:key="member.member.memberId"
|
||||
:class="[
|
||||
'border-b px-2 sm:px-3 py-1.5',
|
||||
{
|
||||
'bg-blue-50 border-t border-blue-300 -mt-[1px]':
|
||||
!member.member.admitted && isOrganizer,
|
||||
},
|
||||
{ 'border-slate-300': member.member.admitted },
|
||||
]"
|
||||
>
|
||||
<div class="flex items-center gap-2 justify-between">
|
||||
<div class="flex items-center gap-1 overflow-hidden">
|
||||
<h3
|
||||
:class="[
|
||||
'font-semibold truncate',
|
||||
{
|
||||
'text-slate-500': !member.member.admitted && isOrganizer,
|
||||
},
|
||||
]"
|
||||
>
|
||||
<font-awesome
|
||||
v-if="member.member.memberId === members[0]?.memberId"
|
||||
icon="crown"
|
||||
class="fa-fw text-amber-400"
|
||||
/>
|
||||
<font-awesome
|
||||
v-if="!member.member.admitted && isOrganizer"
|
||||
icon="hourglass-half"
|
||||
class="fa-fw text-slate-400"
|
||||
/>
|
||||
{{ member.name || unnamedMember }}
|
||||
</h3>
|
||||
<div
|
||||
v-if="!getContactFor(member.did) && member.did !== activeDid"
|
||||
class="flex items-center gap-1.5 ms-1"
|
||||
>
|
||||
<button
|
||||
class="btn-add-contact"
|
||||
title="Add as contact"
|
||||
@click="addAsContact(member)"
|
||||
>
|
||||
<font-awesome icon="circle-user" />
|
||||
</button>
|
||||
|
||||
<button
|
||||
class="btn-info-contact"
|
||||
title="Contact Info"
|
||||
@click="
|
||||
informAboutAddingContact(
|
||||
getContactFor(member.did) !== undefined,
|
||||
)
|
||||
"
|
||||
>
|
||||
<font-awesome icon="circle-info" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<span
|
||||
v-if="
|
||||
showOrganizerTools && isOrganizer && member.did !== activeDid
|
||||
"
|
||||
class="flex items-center gap-1.5"
|
||||
>
|
||||
<button
|
||||
:class="
|
||||
member.member.admitted
|
||||
? 'btn-admission-remove'
|
||||
: 'btn-admission-add'
|
||||
"
|
||||
:title="
|
||||
member.member.admitted ? 'Remove member' : 'Admit member'
|
||||
"
|
||||
@click="checkWhetherContactBeforeAdmitting(member)"
|
||||
>
|
||||
<font-awesome
|
||||
:icon="
|
||||
member.member.admitted ? 'circle-minus' : 'circle-plus'
|
||||
"
|
||||
/>
|
||||
</button>
|
||||
|
||||
<button
|
||||
class="btn-info-admission"
|
||||
title="Admission Info"
|
||||
@click="informAboutAdmission()"
|
||||
>
|
||||
<font-awesome icon="circle-info" />
|
||||
</button>
|
||||
</span>
|
||||
</div>
|
||||
<p class="text-xs text-gray-600 truncate">
|
||||
{{ member.did }}
|
||||
</p>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div v-if="membersToShow().length > 0" class="flex justify-between">
|
||||
<!--
|
||||
always have at least one refresh button even without members in case the organizer
|
||||
changes the password
|
||||
-->
|
||||
<button
|
||||
class="text-sm bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-3 py-1.5 rounded-md"
|
||||
title="Refresh members list now"
|
||||
@click="refreshData(false)"
|
||||
>
|
||||
<font-awesome icon="rotate" :class="{ 'fa-spin': isLoading }" />
|
||||
Refresh
|
||||
<span class="text-xs">({{ countdownTimer }}s)</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<p v-if="members.length === 0" class="text-gray-500 py-4">
|
||||
No members have joined this meeting yet
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<p v-if="members.length === 0" class="text-gray-500 py-4">
|
||||
No members have joined this meeting yet
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Set Visibility Dialog Component -->
|
||||
<SetBulkVisibilityDialog
|
||||
:visible="showSetVisibilityDialog"
|
||||
:members-data="visibilityDialogMembers"
|
||||
:active-did="activeDid"
|
||||
:api-server="apiServer"
|
||||
@close="closeSetVisibilityDialog"
|
||||
/>
|
||||
<!-- This Admit component is for the organizer to admit pending members to the meeting -->
|
||||
<AdmitPendingMembersDialog
|
||||
ref="admitPendingMembersDialog"
|
||||
:active-did="activeDid"
|
||||
:api-server="apiServer"
|
||||
@close="closeMemberSelectionDialogCallback"
|
||||
/>
|
||||
<!-- This Bulk Visibility component is for non-organizer members to add other members to their contacts and set their visibility -->
|
||||
<SetBulkVisibilityDialog
|
||||
ref="setBulkVisibilityDialog"
|
||||
:active-did="activeDid"
|
||||
:api-server="apiServer"
|
||||
@close="closeMemberSelectionDialogCallback"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { Component, Vue, Prop, Emit } from "vue-facing-decorator";
|
||||
|
||||
import {
|
||||
errorStringForLog,
|
||||
getHeaders,
|
||||
register,
|
||||
serverMessageForUser,
|
||||
} from "../libs/endorserServer";
|
||||
import { decryptMessage } from "../libs/crypto";
|
||||
import { Contact } from "../db/tables/contacts";
|
||||
import * as libsUtil from "../libs/util";
|
||||
import { NotificationIface } from "../constants/app";
|
||||
import { PlatformServiceMixin } from "@/utils/PlatformServiceMixin";
|
||||
import { createNotifyHelpers, TIMEOUTS } from "@/utils/notify";
|
||||
import { NotificationIface } from "@/constants/app";
|
||||
import {
|
||||
NOTIFY_ADD_CONTACT_FIRST,
|
||||
NOTIFY_CONTINUE_WITHOUT_ADDING,
|
||||
} from "@/constants/notifications";
|
||||
import { SOMEONE_UNNAMED } from "@/constants/entities";
|
||||
import {
|
||||
errorStringForLog,
|
||||
getHeaders,
|
||||
register,
|
||||
serverMessageForUser,
|
||||
} from "@/libs/endorserServer";
|
||||
import { decryptMessage } from "@/libs/crypto";
|
||||
import { Contact } from "@/db/tables/contacts";
|
||||
import { MemberData } from "@/interfaces";
|
||||
import * as libsUtil from "@/libs/util";
|
||||
import { PlatformServiceMixin } from "@/utils/PlatformServiceMixin";
|
||||
import { createNotifyHelpers, TIMEOUTS } from "@/utils/notify";
|
||||
import AdmitPendingMembersDialog from "./AdmitPendingMembersDialog.vue";
|
||||
import SetBulkVisibilityDialog from "./SetBulkVisibilityDialog.vue";
|
||||
|
||||
interface Member {
|
||||
@@ -208,6 +238,7 @@ interface DecryptedMember {
|
||||
|
||||
@Component({
|
||||
components: {
|
||||
AdmitPendingMembersDialog,
|
||||
SetBulkVisibilityDialog,
|
||||
},
|
||||
mixins: [PlatformServiceMixin],
|
||||
@@ -227,6 +258,7 @@ export default class MembersList extends Vue {
|
||||
return message;
|
||||
}
|
||||
|
||||
contacts: Array<Contact> = [];
|
||||
decryptedMembers: DecryptedMember[] = [];
|
||||
firstName = "";
|
||||
isLoading = true;
|
||||
@@ -237,23 +269,11 @@ export default class MembersList extends Vue {
|
||||
activeDid = "";
|
||||
apiServer = "";
|
||||
|
||||
// Set Visibility Dialog state
|
||||
showSetVisibilityDialog = false;
|
||||
visibilityDialogMembers: Array<{
|
||||
did: string;
|
||||
name: string;
|
||||
isContact: boolean;
|
||||
member: { memberId: string };
|
||||
}> = [];
|
||||
contacts: Array<Contact> = [];
|
||||
|
||||
// Auto-refresh functionality
|
||||
countdownTimer = 10;
|
||||
autoRefreshInterval: NodeJS.Timeout | null = null;
|
||||
lastRefreshTime = 0;
|
||||
|
||||
// Track previous visibility members to detect changes
|
||||
previousVisibilityMembers: string[] = [];
|
||||
previousMemberDidsIgnored: string[] = [];
|
||||
|
||||
/**
|
||||
* Get the unnamed member constant
|
||||
@@ -274,23 +294,8 @@ export default class MembersList extends Vue {
|
||||
|
||||
this.apiServer = settings.apiServer || "";
|
||||
this.firstName = settings.firstName || "";
|
||||
await this.fetchMembers();
|
||||
await this.loadContacts();
|
||||
|
||||
// Start auto-refresh
|
||||
this.startAutoRefresh();
|
||||
|
||||
// Check if we should show the visibility dialog on initial load
|
||||
this.checkAndShowVisibilityDialog();
|
||||
}
|
||||
|
||||
async refreshData() {
|
||||
// Force refresh both contacts and members
|
||||
await this.loadContacts();
|
||||
await this.fetchMembers();
|
||||
|
||||
// Check if we should show the visibility dialog after refresh
|
||||
this.checkAndShowVisibilityDialog();
|
||||
this.refreshData();
|
||||
}
|
||||
|
||||
async fetchMembers() {
|
||||
@@ -378,17 +383,58 @@ export default class MembersList extends Vue {
|
||||
}
|
||||
|
||||
membersToShow(): DecryptedMember[] {
|
||||
let members: DecryptedMember[] = [];
|
||||
|
||||
if (this.isOrganizer) {
|
||||
if (this.showOrganizerTools) {
|
||||
return this.decryptedMembers;
|
||||
members = this.decryptedMembers;
|
||||
} else {
|
||||
return this.decryptedMembers.filter(
|
||||
members = this.decryptedMembers.filter(
|
||||
(member: DecryptedMember) => member.member.admitted,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// non-organizers only get visible members from server, plus themselves
|
||||
|
||||
// this is a stub for this user just in case they are waiting to get in
|
||||
// which is especially useful so they can see their own DID
|
||||
const currentUser: DecryptedMember = {
|
||||
member: {
|
||||
admitted: false,
|
||||
content: "{}",
|
||||
memberId: -1,
|
||||
},
|
||||
name: this.firstName,
|
||||
did: this.activeDid,
|
||||
isRegistered: false,
|
||||
};
|
||||
const otherMembersPlusUser = [currentUser, ...this.decryptedMembers];
|
||||
members = otherMembersPlusUser;
|
||||
}
|
||||
// non-organizers only get visible members from server
|
||||
return this.decryptedMembers;
|
||||
|
||||
// Sort members according to priority:
|
||||
// 1. Organizer at the top
|
||||
// 2. Non-admitted members next
|
||||
// 3. Everyone else after
|
||||
return members.sort((a, b) => {
|
||||
// Check if either member is the organizer (first member in original list)
|
||||
const aIsOrganizer = a.member.memberId === this.members[0]?.memberId;
|
||||
const bIsOrganizer = b.member.memberId === this.members[0]?.memberId;
|
||||
|
||||
// Organizer always comes first
|
||||
if (aIsOrganizer && !bIsOrganizer) return -1;
|
||||
if (!aIsOrganizer && bIsOrganizer) return 1;
|
||||
|
||||
// If both are organizers or neither are organizers, sort by admission status
|
||||
if (aIsOrganizer && bIsOrganizer) return 0; // Both organizers, maintain original order
|
||||
|
||||
// Non-admitted members come before admitted members
|
||||
if (!a.member.admitted && b.member.admitted) return -1;
|
||||
if (a.member.admitted && !b.member.admitted) return 1;
|
||||
|
||||
// If admission status is the same, maintain original order
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
informAboutAdmission() {
|
||||
@@ -412,86 +458,85 @@ export default class MembersList extends Vue {
|
||||
}
|
||||
}
|
||||
|
||||
async loadContacts() {
|
||||
this.contacts = await this.$getAllContacts();
|
||||
}
|
||||
|
||||
getContactFor(did: string): Contact | undefined {
|
||||
return this.contacts.find((contact) => contact.did === did);
|
||||
}
|
||||
|
||||
getMembersForVisibility() {
|
||||
getPendingMembersToAdmit(): MemberData[] {
|
||||
return this.decryptedMembers
|
||||
.filter((member) => {
|
||||
// Exclude the current user
|
||||
if (member.did === this.activeDid) {
|
||||
return false;
|
||||
}
|
||||
.filter(
|
||||
(member) => member.did !== this.activeDid && !member.member.admitted,
|
||||
)
|
||||
.map(this.convertDecryptedMemberToMemberData);
|
||||
}
|
||||
|
||||
const contact = this.getContactFor(member.did);
|
||||
getNonContactMembers(): MemberData[] {
|
||||
return this.decryptedMembers
|
||||
.filter(
|
||||
(member) =>
|
||||
member.did !== this.activeDid && !this.getContactFor(member.did),
|
||||
)
|
||||
.map(this.convertDecryptedMemberToMemberData);
|
||||
}
|
||||
|
||||
// Include members who:
|
||||
// 1. Haven't been added as contacts yet, OR
|
||||
// 2. Are contacts but don't have visibility set (seesMe property)
|
||||
return !contact || !contact.seesMe;
|
||||
})
|
||||
.map((member) => ({
|
||||
did: member.did,
|
||||
name: member.name,
|
||||
isContact: !!this.getContactFor(member.did),
|
||||
member: {
|
||||
memberId: member.member.memberId.toString(),
|
||||
},
|
||||
}));
|
||||
convertDecryptedMemberToMemberData(
|
||||
decryptedMember: DecryptedMember,
|
||||
): MemberData {
|
||||
return {
|
||||
did: decryptedMember.did,
|
||||
name: decryptedMember.name,
|
||||
isContact: !!this.getContactFor(decryptedMember.did),
|
||||
member: {
|
||||
memberId: decryptedMember.member.memberId.toString(),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if we should show the visibility dialog
|
||||
* Returns true if there are members for visibility and either:
|
||||
* - This is the first time (no previous members tracked), OR
|
||||
* - New members have been added since last check (not removed)
|
||||
* Show the admit pending members dialog if conditions are met
|
||||
*/
|
||||
shouldShowVisibilityDialog(): boolean {
|
||||
const currentMembers = this.getMembersForVisibility();
|
||||
async refreshData(bypassPromptIfAllWereIgnored = true) {
|
||||
// Force refresh both contacts and members
|
||||
this.contacts = await this.$getAllContacts();
|
||||
await this.fetchMembers();
|
||||
|
||||
if (currentMembers.length === 0) {
|
||||
return false;
|
||||
const pendingMembers = this.isOrganizer
|
||||
? this.getPendingMembersToAdmit()
|
||||
: this.getNonContactMembers();
|
||||
if (pendingMembers.length === 0) {
|
||||
this.startAutoRefresh();
|
||||
return;
|
||||
}
|
||||
|
||||
// If no previous members tracked, show dialog
|
||||
if (this.previousVisibilityMembers.length === 0) {
|
||||
return true;
|
||||
if (bypassPromptIfAllWereIgnored) {
|
||||
// only show if there are pending members that have not been ignored
|
||||
const pendingMembersNotIgnored = pendingMembers.filter(
|
||||
(member) => !this.previousMemberDidsIgnored.includes(member.did),
|
||||
);
|
||||
if (pendingMembersNotIgnored.length === 0) {
|
||||
this.startAutoRefresh();
|
||||
// everyone waiting has been ignored
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.stopAutoRefresh();
|
||||
if (this.isOrganizer) {
|
||||
(this.$refs.admitPendingMembersDialog as AdmitPendingMembersDialog).open(
|
||||
pendingMembers,
|
||||
);
|
||||
} else {
|
||||
(this.$refs.setBulkVisibilityDialog as SetBulkVisibilityDialog).open(
|
||||
pendingMembers,
|
||||
);
|
||||
}
|
||||
|
||||
// Check if new members have been added (not just any change)
|
||||
const currentMemberIds = currentMembers.map((m) => m.did);
|
||||
const previousMemberIds = this.previousVisibilityMembers;
|
||||
|
||||
// Find new members (members in current but not in previous)
|
||||
const newMembers = currentMemberIds.filter(
|
||||
(id) => !previousMemberIds.includes(id),
|
||||
);
|
||||
|
||||
// Only show dialog if there are new members added
|
||||
return newMembers.length > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the tracking of previous visibility members
|
||||
*/
|
||||
updatePreviousVisibilityMembers() {
|
||||
const currentMembers = this.getMembersForVisibility();
|
||||
this.previousVisibilityMembers = currentMembers.map((m) => m.did);
|
||||
}
|
||||
// Admit Pending Members Dialog methods
|
||||
async closeMemberSelectionDialogCallback(
|
||||
result: { notSelectedMemberDids: string[] } | undefined,
|
||||
) {
|
||||
this.previousMemberDidsIgnored = result?.notSelectedMemberDids || [];
|
||||
|
||||
/**
|
||||
* Show the visibility dialog if conditions are met
|
||||
*/
|
||||
checkAndShowVisibilityDialog() {
|
||||
if (this.shouldShowVisibilityDialog()) {
|
||||
this.showSetBulkVisibilityDialog();
|
||||
}
|
||||
this.updatePreviousVisibilityMembers();
|
||||
await this.refreshData();
|
||||
}
|
||||
|
||||
checkWhetherContactBeforeAdmitting(decrMember: DecryptedMember) {
|
||||
@@ -632,19 +677,8 @@ export default class MembersList extends Vue {
|
||||
}
|
||||
}
|
||||
|
||||
showSetBulkVisibilityDialog() {
|
||||
// Filter members to show only those who need visibility set
|
||||
const membersForVisibility = this.getMembersForVisibility();
|
||||
|
||||
// Pause auto-refresh when dialog opens
|
||||
this.stopAutoRefresh();
|
||||
|
||||
// Open the dialog directly
|
||||
this.visibilityDialogMembers = membersForVisibility;
|
||||
this.showSetVisibilityDialog = true;
|
||||
}
|
||||
|
||||
startAutoRefresh() {
|
||||
this.stopAutoRefresh();
|
||||
this.lastRefreshTime = Date.now();
|
||||
this.countdownTimer = 10;
|
||||
|
||||
@@ -674,33 +708,6 @@ export default class MembersList extends Vue {
|
||||
}
|
||||
}
|
||||
|
||||
manualRefresh() {
|
||||
// Clear existing auto-refresh interval
|
||||
if (this.autoRefreshInterval) {
|
||||
clearInterval(this.autoRefreshInterval);
|
||||
this.autoRefreshInterval = null;
|
||||
}
|
||||
|
||||
// Trigger immediate refresh and restart timer
|
||||
this.refreshData();
|
||||
this.startAutoRefresh();
|
||||
|
||||
// Always show dialog on manual refresh if there are members for visibility
|
||||
if (this.getMembersForVisibility().length > 0) {
|
||||
this.showSetBulkVisibilityDialog();
|
||||
}
|
||||
}
|
||||
|
||||
// Set Visibility Dialog methods
|
||||
closeSetVisibilityDialog() {
|
||||
this.showSetVisibilityDialog = false;
|
||||
this.visibilityDialogMembers = [];
|
||||
// Refresh data when dialog is closed
|
||||
this.refreshData();
|
||||
// Resume auto-refresh when dialog is closed
|
||||
this.startAutoRefresh();
|
||||
}
|
||||
|
||||
beforeDestroy() {
|
||||
this.stopAutoRefresh();
|
||||
}
|
||||
@@ -718,23 +725,26 @@ export default class MembersList extends Vue {
|
||||
|
||||
.btn-add-contact {
|
||||
/* stylelint-disable-next-line at-rule-no-unknown */
|
||||
@apply w-6 h-6 flex items-center justify-center rounded-full
|
||||
bg-green-100 text-green-600 hover:bg-green-200 hover:text-green-800
|
||||
@apply text-lg text-green-600 hover:text-green-800
|
||||
transition-colors;
|
||||
}
|
||||
|
||||
.btn-info-contact,
|
||||
.btn-info-admission {
|
||||
/* stylelint-disable-next-line at-rule-no-unknown */
|
||||
@apply w-6 h-6 flex items-center justify-center rounded-full
|
||||
bg-slate-100 text-slate-400 hover:text-slate-600
|
||||
@apply text-slate-400 hover:text-slate-600
|
||||
transition-colors;
|
||||
}
|
||||
|
||||
.btn-admission {
|
||||
.btn-admission-add {
|
||||
/* stylelint-disable-next-line at-rule-no-unknown */
|
||||
@apply w-6 h-6 flex items-center justify-center rounded-full
|
||||
bg-blue-100 text-blue-600 hover:bg-blue-200 hover:text-blue-800
|
||||
@apply text-lg text-blue-500 hover:text-blue-700
|
||||
transition-colors;
|
||||
}
|
||||
|
||||
.btn-admission-remove {
|
||||
/* stylelint-disable-next-line at-rule-no-unknown */
|
||||
@apply text-lg text-rose-500 hover:text-rose-700
|
||||
transition-colors;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -3,15 +3,14 @@
|
||||
<div class="dialog">
|
||||
<div class="text-slate-900 text-center">
|
||||
<h3 class="text-lg font-semibold leading-[1.25] mb-2">
|
||||
Set Visibility to Meeting Members
|
||||
Add Members to Contacts
|
||||
</h3>
|
||||
<p class="text-sm mb-4">
|
||||
Would you like to <b>make your activities visible</b> to the following
|
||||
members? (This will also add them as contacts if they aren't already.)
|
||||
Would you like to add these members to your contacts?
|
||||
</p>
|
||||
|
||||
<!-- Custom table area - you can customize this -->
|
||||
<div v-if="shouldInitializeSelection" class="mb-4">
|
||||
<div class="mb-4">
|
||||
<table
|
||||
class="w-full border-collapse border border-slate-300 text-sm text-start"
|
||||
>
|
||||
@@ -36,7 +35,7 @@
|
||||
<td
|
||||
class="border border-slate-300 px-3 py-2 text-center italic text-gray-500"
|
||||
>
|
||||
No members need visibility settings
|
||||
No members are not in your contacts
|
||||
</td>
|
||||
</tr>
|
||||
<tr
|
||||
@@ -80,15 +79,13 @@
|
||||
]"
|
||||
@click="setVisibilityForSelectedMembers"
|
||||
>
|
||||
Set Visibility
|
||||
Add to Contacts
|
||||
</button>
|
||||
<button
|
||||
class="block w-full text-center text-md font-bold uppercase bg-slate-600 text-white px-2 py-2 rounded-md"
|
||||
@click="cancel"
|
||||
>
|
||||
{{
|
||||
membersData && membersData.length > 0 ? "Maybe Later" : "Cancel"
|
||||
}}
|
||||
Maybe Later
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -101,24 +98,15 @@ import { Vue, Component, Prop } from "vue-facing-decorator";
|
||||
|
||||
import { PlatformServiceMixin } from "@/utils/PlatformServiceMixin";
|
||||
import { SOMEONE_UNNAMED } from "@/constants/entities";
|
||||
import { MemberData } from "@/interfaces";
|
||||
import { setVisibilityUtil } from "@/libs/endorserServer";
|
||||
import { createNotifyHelpers } from "@/utils/notify";
|
||||
|
||||
interface MemberData {
|
||||
did: string;
|
||||
name: string;
|
||||
isContact: boolean;
|
||||
member: {
|
||||
memberId: string;
|
||||
};
|
||||
}
|
||||
|
||||
@Component({
|
||||
mixins: [PlatformServiceMixin],
|
||||
emits: ["close"],
|
||||
})
|
||||
export default class SetBulkVisibilityDialog extends Vue {
|
||||
@Prop({ default: false }) visible!: boolean;
|
||||
@Prop({ default: () => [] }) membersData!: MemberData[];
|
||||
@Prop({ default: "" }) activeDid!: string;
|
||||
@Prop({ default: "" }) apiServer!: string;
|
||||
|
||||
@@ -132,8 +120,9 @@ export default class SetBulkVisibilityDialog extends Vue {
|
||||
notify!: ReturnType<typeof createNotifyHelpers>;
|
||||
|
||||
// Component state
|
||||
membersData: MemberData[] = [];
|
||||
selectedMembers: string[] = [];
|
||||
selectionInitialized = false;
|
||||
visible = false;
|
||||
|
||||
// Constants
|
||||
// In Vue templates, imported constants need to be explicitly made available to the template
|
||||
@@ -158,29 +147,24 @@ export default class SetBulkVisibilityDialog extends Vue {
|
||||
return selectedCount > 0 && selectedCount < this.membersData.length;
|
||||
}
|
||||
|
||||
get shouldInitializeSelection() {
|
||||
// This method will initialize selection when the dialog opens
|
||||
if (!this.selectionInitialized) {
|
||||
this.initializeSelection();
|
||||
this.selectionInitialized = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
created() {
|
||||
this.notify = createNotifyHelpers(this.$notify);
|
||||
}
|
||||
|
||||
initializeSelection() {
|
||||
// Reset selection when dialog opens
|
||||
this.selectedMembers = [];
|
||||
open(members: MemberData[]) {
|
||||
this.visible = true;
|
||||
this.membersData = members;
|
||||
// Select all by default
|
||||
this.selectedMembers = this.membersData.map((member) => member.did);
|
||||
}
|
||||
|
||||
resetSelection() {
|
||||
this.selectedMembers = [];
|
||||
this.selectionInitialized = false;
|
||||
close(notSelectedMemberDids: string[]) {
|
||||
this.visible = false;
|
||||
this.$emit("close", { notSelectedMemberDids: notSelectedMemberDids });
|
||||
}
|
||||
|
||||
cancel() {
|
||||
this.close(this.membersData.map((member) => member.did));
|
||||
}
|
||||
|
||||
toggleSelectAll() {
|
||||
@@ -213,6 +197,9 @@ export default class SetBulkVisibilityDialog extends Vue {
|
||||
const selectedMembers = this.membersData.filter((member) =>
|
||||
this.selectedMembers.includes(member.did),
|
||||
);
|
||||
const notSelectedMembers = this.membersData.filter(
|
||||
(member) => !this.selectedMembers.includes(member.did),
|
||||
);
|
||||
|
||||
let successCount = 0;
|
||||
|
||||
@@ -245,9 +232,7 @@ export default class SetBulkVisibilityDialog extends Vue {
|
||||
5000,
|
||||
);
|
||||
|
||||
// Emit success event
|
||||
this.$emit("success", successCount);
|
||||
this.close();
|
||||
this.close(notSelectedMembers.map((member) => member.did));
|
||||
} catch (error) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error("Error setting visibility:", error);
|
||||
@@ -320,14 +305,5 @@ export default class SetBulkVisibilityDialog extends Vue {
|
||||
5000,
|
||||
);
|
||||
}
|
||||
|
||||
close() {
|
||||
this.resetSelection();
|
||||
this.$emit("close");
|
||||
}
|
||||
|
||||
cancel() {
|
||||
this.close();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -27,6 +27,7 @@ export type {
|
||||
export type {
|
||||
// From user.ts
|
||||
UserInfo,
|
||||
MemberData,
|
||||
} from "./user";
|
||||
|
||||
export * from "./limits";
|
||||
|
||||
@@ -6,3 +6,12 @@ export interface UserInfo {
|
||||
profileImageUrl?: string;
|
||||
nextPublicEncKeyHash?: string;
|
||||
}
|
||||
|
||||
export interface MemberData {
|
||||
did: string;
|
||||
name: string;
|
||||
isContact: boolean;
|
||||
member: {
|
||||
memberId: string;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import {
|
||||
faCircle,
|
||||
faCircleCheck,
|
||||
faCircleInfo,
|
||||
faCircleMinus,
|
||||
faCirclePlus,
|
||||
faCircleQuestion,
|
||||
faCircleRight,
|
||||
@@ -37,6 +38,7 @@ import {
|
||||
faCoins,
|
||||
faComment,
|
||||
faCopy,
|
||||
faCrown,
|
||||
faDollar,
|
||||
faDownload,
|
||||
faEllipsis,
|
||||
@@ -58,6 +60,7 @@ import {
|
||||
faHand,
|
||||
faHandHoldingDollar,
|
||||
faHandHoldingHeart,
|
||||
faHourglassHalf,
|
||||
faHouseChimney,
|
||||
faImage,
|
||||
faImagePortrait,
|
||||
@@ -123,6 +126,7 @@ library.add(
|
||||
faCircle,
|
||||
faCircleCheck,
|
||||
faCircleInfo,
|
||||
faCircleMinus,
|
||||
faCirclePlus,
|
||||
faCircleQuestion,
|
||||
faCircleRight,
|
||||
@@ -131,6 +135,7 @@ library.add(
|
||||
faCoins,
|
||||
faComment,
|
||||
faCopy,
|
||||
faCrown,
|
||||
faDollar,
|
||||
faDownload,
|
||||
faEllipsis,
|
||||
@@ -152,6 +157,7 @@ library.add(
|
||||
faHand,
|
||||
faHandHoldingDollar,
|
||||
faHandHoldingHeart,
|
||||
faHourglassHalf,
|
||||
faHouseChimney,
|
||||
faImage,
|
||||
faImagePortrait,
|
||||
|
||||
@@ -88,24 +88,6 @@ export interface PlatformService {
|
||||
*/
|
||||
writeAndShareFile(fileName: string, content: string): Promise<void>;
|
||||
|
||||
/**
|
||||
* Saves content directly to the device's Downloads folder (Android) or Documents folder (iOS).
|
||||
* Uses MediaStore on Android API 29+ and falls back to SAF on older versions.
|
||||
* @param fileName - The filename of the file to save
|
||||
* @param content - The content to write to the file
|
||||
* @returns Promise that resolves when the file is saved
|
||||
*/
|
||||
saveToDevice(fileName: string, content: string): Promise<void>;
|
||||
|
||||
/**
|
||||
* Opens the system file picker to let the user choose where to save a file.
|
||||
* Uses Storage Access Framework (SAF) on Android and appropriate APIs on other platforms.
|
||||
* @param fileName - The suggested filename for the file
|
||||
* @param content - The content to write to the file
|
||||
* @returns Promise that resolves when the file is saved
|
||||
*/
|
||||
saveAs(fileName: string, content: string): Promise<void>;
|
||||
|
||||
/**
|
||||
* Deletes a file at the specified path.
|
||||
* @param path - The path to the file to delete
|
||||
|
||||
@@ -14,65 +14,6 @@ import {
|
||||
DBSQLiteValues,
|
||||
} from "@capacitor-community/sqlite";
|
||||
|
||||
// Android-specific imports for SAF and MediaStore
|
||||
import { registerPlugin } from "@capacitor/core";
|
||||
|
||||
// Define interfaces for Android-specific functionality
|
||||
interface AndroidFileSaverPlugin {
|
||||
saveToDownloads(options: {
|
||||
fileName: string;
|
||||
content: string;
|
||||
mimeType: string;
|
||||
}): Promise<{ success: boolean; path?: string; error?: string }>;
|
||||
saveAs(options: {
|
||||
fileName: string;
|
||||
content: string;
|
||||
mimeType: string;
|
||||
}): Promise<{ success: boolean; path?: string; error?: string }>;
|
||||
}
|
||||
|
||||
// Register the plugin (will be undefined if not available)
|
||||
const AndroidFileSaver =
|
||||
registerPlugin<AndroidFileSaverPlugin>("AndroidFileSaver");
|
||||
|
||||
// Fallback implementation for when the plugin is not available
|
||||
class AndroidFileSaverFallback implements AndroidFileSaverPlugin {
|
||||
async saveToDownloads(options: {
|
||||
fileName: string;
|
||||
content: string;
|
||||
mimeType: string;
|
||||
}): Promise<{ success: boolean; path?: string; error?: string }> {
|
||||
logger.warn(
|
||||
"[CapacitorPlatformService] AndroidFileSaver plugin not available, using fallback",
|
||||
{
|
||||
fileName: options.fileName,
|
||||
mimeType: options.mimeType,
|
||||
contentLength: options.content.length,
|
||||
},
|
||||
);
|
||||
return { success: false, error: "AndroidFileSaver plugin not available" };
|
||||
}
|
||||
|
||||
async saveAs(options: {
|
||||
fileName: string;
|
||||
content: string;
|
||||
mimeType: string;
|
||||
}): Promise<{ success: boolean; path?: string; error?: string }> {
|
||||
logger.warn(
|
||||
"[CapacitorPlatformService] AndroidFileSaver plugin not available, using fallback",
|
||||
{
|
||||
fileName: options.fileName,
|
||||
mimeType: options.mimeType,
|
||||
contentLength: options.content.length,
|
||||
},
|
||||
);
|
||||
return { success: false, error: "AndroidFileSaver plugin not available" };
|
||||
}
|
||||
}
|
||||
|
||||
// Use fallback if plugin is not available
|
||||
const AndroidFileSaverImpl = AndroidFileSaver || new AndroidFileSaverFallback();
|
||||
|
||||
import { runMigrations } from "@/db-sql/migration";
|
||||
import { QueryExecResult } from "@/interfaces/database";
|
||||
import {
|
||||
@@ -527,7 +468,7 @@ export class CapacitorPlatformService implements PlatformService {
|
||||
* ## Logging:
|
||||
*
|
||||
* Detailed logging is provided throughout the process using emoji-tagged
|
||||
* log messages that appear in the Electron DevTools. This
|
||||
* console messages that appear in the Electron DevTools console. This
|
||||
* includes:
|
||||
* - SQL statement execution details
|
||||
* - Parameter values for debugging
|
||||
@@ -1178,280 +1119,6 @@ export class CapacitorPlatformService implements PlatformService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves content directly to the device's Downloads folder (Android) or Documents folder (iOS).
|
||||
* Uses MediaStore on Android API 29+ and falls back to SAF on older versions.
|
||||
*
|
||||
* @param fileName - The filename of the file to save
|
||||
* @param content - The content to write to the file
|
||||
* @returns Promise that resolves when the file is saved
|
||||
*/
|
||||
async saveToDevice(fileName: string, content: string): Promise<void> {
|
||||
const timestamp = new Date().toISOString();
|
||||
const logData = {
|
||||
action: "saveToDevice",
|
||||
fileName,
|
||||
contentLength: content.length,
|
||||
platform: this.getCapabilities().isIOS ? "iOS" : "Android",
|
||||
timestamp,
|
||||
};
|
||||
logger.log("[CapacitorPlatformService]", JSON.stringify(logData, null, 2));
|
||||
|
||||
try {
|
||||
// Validate JSON content
|
||||
try {
|
||||
JSON.parse(content);
|
||||
} catch {
|
||||
throw new Error('Content must be valid JSON');
|
||||
}
|
||||
|
||||
// Generate unique filename
|
||||
const uniqueFileName = this.generateUniqueFileName(fileName);
|
||||
|
||||
if (this.getCapabilities().isIOS) {
|
||||
// iOS: Use Filesystem to save to Documents directory
|
||||
const { uri } = await Filesystem.writeFile({
|
||||
path: uniqueFileName,
|
||||
data: content,
|
||||
directory: Directory.Documents,
|
||||
encoding: Encoding.UTF8,
|
||||
recursive: true,
|
||||
});
|
||||
|
||||
logger.log("[CapacitorPlatformService] File saved to iOS Documents:", {
|
||||
uri,
|
||||
fileName: uniqueFileName,
|
||||
timestamp: new Date().toISOString(),
|
||||
});
|
||||
} else {
|
||||
// Android: Try to use native MediaStore/SAF implementation
|
||||
const result = await AndroidFileSaverImpl.saveToDownloads({
|
||||
fileName: uniqueFileName,
|
||||
content,
|
||||
mimeType: this.getMimeType(uniqueFileName),
|
||||
});
|
||||
|
||||
if (result.success) {
|
||||
logger.log(
|
||||
"[CapacitorPlatformService] File saved to Android Downloads:",
|
||||
{
|
||||
path: result.path,
|
||||
fileName: uniqueFileName,
|
||||
timestamp: new Date().toISOString(),
|
||||
},
|
||||
);
|
||||
} else {
|
||||
throw new Error(`Failed to save to Downloads: ${result.error}`);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
const err = error as Error;
|
||||
const errLog = {
|
||||
message: err.message,
|
||||
stack: err.stack,
|
||||
timestamp: new Date().toISOString(),
|
||||
};
|
||||
logger.error(
|
||||
"[CapacitorPlatformService] Error saving file to device:",
|
||||
JSON.stringify(errLog, null, 2),
|
||||
);
|
||||
throw new Error(`Failed to save file to device: ${err.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the system file picker to let the user choose where to save a file.
|
||||
* Uses Storage Access Framework (SAF) on Android and appropriate APIs on other platforms.
|
||||
*
|
||||
* @param fileName - The suggested filename for the file
|
||||
* @param content - The content to write to the file
|
||||
* @returns Promise that resolves when the file is saved
|
||||
*/
|
||||
async saveAs(fileName: string, content: string): Promise<void> {
|
||||
const timestamp = new Date().toISOString();
|
||||
const logData = {
|
||||
action: "saveAs",
|
||||
fileName,
|
||||
contentLength: content.length,
|
||||
platform: this.getCapabilities().isIOS ? "iOS" : "Android",
|
||||
timestamp,
|
||||
};
|
||||
logger.log("[CapacitorPlatformService]", JSON.stringify(logData, null, 2));
|
||||
|
||||
try {
|
||||
// Validate JSON content
|
||||
try {
|
||||
JSON.parse(content);
|
||||
} catch {
|
||||
throw new Error('Content must be valid JSON');
|
||||
}
|
||||
|
||||
// Generate unique filename
|
||||
const uniqueFileName = this.generateUniqueFileName(fileName);
|
||||
|
||||
if (this.getCapabilities().isIOS) {
|
||||
// iOS: Use Filesystem to save to Documents directory with user choice
|
||||
const { uri } = await Filesystem.writeFile({
|
||||
path: uniqueFileName,
|
||||
data: content,
|
||||
directory: Directory.Documents,
|
||||
encoding: Encoding.UTF8,
|
||||
recursive: true,
|
||||
});
|
||||
|
||||
logger.log("[CapacitorPlatformService] File saved to iOS Documents:", {
|
||||
uri,
|
||||
fileName: uniqueFileName,
|
||||
timestamp: new Date().toISOString(),
|
||||
});
|
||||
} else {
|
||||
// Android: Use SAF for user-chosen location
|
||||
const result = await AndroidFileSaverImpl.saveAs({
|
||||
fileName: uniqueFileName,
|
||||
content,
|
||||
mimeType: this.getMimeType(uniqueFileName),
|
||||
});
|
||||
|
||||
if (result.success) {
|
||||
logger.log(
|
||||
"[CapacitorPlatformService] File saved via Android SAF:",
|
||||
{
|
||||
path: result.path,
|
||||
fileName: uniqueFileName,
|
||||
timestamp: new Date().toISOString(),
|
||||
},
|
||||
);
|
||||
} else {
|
||||
throw new Error(`Failed to save via SAF: ${result.error}`);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
const err = error as Error;
|
||||
const errLog = {
|
||||
message: err.message,
|
||||
stack: err.stack,
|
||||
timestamp: new Date().toISOString(),
|
||||
};
|
||||
logger.error(
|
||||
"[CapacitorPlatformService] Error in saveAs:",
|
||||
JSON.stringify(errLog, null, 2),
|
||||
);
|
||||
throw new Error(`Failed to save file: ${err.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates unique filename with timestamp, hashed device ID, and counter
|
||||
*/
|
||||
private generateUniqueFileName(baseName: string, counter = 0): string {
|
||||
const now = new Date();
|
||||
const timestamp = now.toISOString()
|
||||
.replace(/[:.]/g, '-')
|
||||
.replace('T', '_')
|
||||
.replace('Z', '');
|
||||
|
||||
const deviceIdHash = this.getHashedDeviceIdentifier();
|
||||
const counterSuffix = counter > 0 ? `_${counter}` : '';
|
||||
|
||||
const maxBaseLength = 45;
|
||||
const truncatedBase = baseName.length > maxBaseLength
|
||||
? baseName.substring(0, maxBaseLength)
|
||||
: baseName;
|
||||
|
||||
const nameWithoutExt = truncatedBase.replace(/\.json$/i, '');
|
||||
const extension = '.json';
|
||||
const devicePart = `_${deviceIdHash}`;
|
||||
const timestampPart = `_${timestamp}${counterSuffix}`;
|
||||
|
||||
const totalLength = nameWithoutExt.length + devicePart.length + timestampPart.length + extension.length;
|
||||
|
||||
if (totalLength > 200) {
|
||||
const availableLength = 200 - devicePart.length - timestampPart.length - extension.length;
|
||||
const finalBase = nameWithoutExt.substring(0, Math.max(10, availableLength));
|
||||
return `${finalBase}${devicePart}${timestampPart}${extension}`;
|
||||
}
|
||||
|
||||
return `${nameWithoutExt}${devicePart}${timestampPart}${extension}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets hashed device identifier
|
||||
*/
|
||||
private getHashedDeviceIdentifier(): string {
|
||||
try {
|
||||
const deviceInfo = this.getDeviceInfo();
|
||||
return this.hashString(deviceInfo);
|
||||
} catch (error) {
|
||||
return 'mobile';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets device info string
|
||||
*/
|
||||
private getDeviceInfo(): string {
|
||||
try {
|
||||
// For mobile platforms, use device info
|
||||
const capabilities = this.getCapabilities();
|
||||
if (capabilities.isIOS) {
|
||||
return 'ios_mobile';
|
||||
} else if (capabilities.isAndroid) {
|
||||
return 'android_mobile';
|
||||
} else {
|
||||
return 'mobile';
|
||||
}
|
||||
} catch (error) {
|
||||
return 'mobile';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple hash function for device ID
|
||||
*/
|
||||
private hashString(str: string): string {
|
||||
let hash = 0;
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
const char = str.charCodeAt(i);
|
||||
hash = ((hash << 5) - hash) + char;
|
||||
hash = hash & hash;
|
||||
}
|
||||
return Math.abs(hash).toString(16).padStart(4, '0').substring(0, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the MIME type for a given filename based on its extension.
|
||||
*
|
||||
* @param fileName - The filename to determine MIME type for
|
||||
* @returns The MIME type string
|
||||
*/
|
||||
private getMimeType(fileName: string): string {
|
||||
const extension = fileName.split(".").pop()?.toLowerCase();
|
||||
|
||||
switch (extension) {
|
||||
case "json":
|
||||
return "application/json";
|
||||
case "txt":
|
||||
return "text/plain";
|
||||
case "csv":
|
||||
return "text/csv";
|
||||
case "pdf":
|
||||
return "application/pdf";
|
||||
case "xml":
|
||||
return "application/xml";
|
||||
case "html":
|
||||
return "text/html";
|
||||
case "jpg":
|
||||
case "jpeg":
|
||||
return "image/jpeg";
|
||||
case "png":
|
||||
return "image/png";
|
||||
case "gif":
|
||||
return "image/gif";
|
||||
default:
|
||||
return "application/octet-stream";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a file from the app's data directory.
|
||||
* @param path - Relative path to the file to delete
|
||||
|
||||
@@ -146,236 +146,6 @@ export class ElectronPlatformService extends CapacitorPlatformService {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves content directly to the device's Downloads folder (Electron platform).
|
||||
* Uses Electron's IPC to save files directly to the Downloads directory.
|
||||
*
|
||||
* @param fileName - The filename of the file to save
|
||||
* @param content - The content to write to the file
|
||||
* @returns Promise that resolves when the file is saved
|
||||
*/
|
||||
async saveToDevice(fileName: string, content: string): Promise<void> {
|
||||
try {
|
||||
// Ensure content is valid JSON
|
||||
try {
|
||||
JSON.parse(content);
|
||||
} catch {
|
||||
throw new Error('Content must be valid JSON');
|
||||
}
|
||||
|
||||
// Generate unique filename
|
||||
const uniqueFileName = this.generateUniqueFileNameElectron(fileName);
|
||||
|
||||
logger.info(
|
||||
`[ElectronPlatformService] Using native IPC for direct file save`,
|
||||
uniqueFileName,
|
||||
);
|
||||
|
||||
// Check if we're running in Electron with the API available
|
||||
if (typeof window !== "undefined" && window.electronAPI) {
|
||||
// Use the native Electron IPC API for file exports
|
||||
const result = await window.electronAPI.exportData(uniqueFileName, content);
|
||||
|
||||
if (result.success) {
|
||||
logger.info(
|
||||
`[ElectronPlatformService] File saved successfully to`,
|
||||
result.path,
|
||||
);
|
||||
logger.info(
|
||||
`[ElectronPlatformService] File saved to Downloads folder`,
|
||||
uniqueFileName,
|
||||
);
|
||||
} else {
|
||||
logger.error(
|
||||
`[ElectronPlatformService] Native save failed`,
|
||||
result.error,
|
||||
);
|
||||
throw new Error(`Native file save failed: ${result.error}`);
|
||||
}
|
||||
} else {
|
||||
// Fallback to web-style download if Electron API is not available
|
||||
logger.warn(
|
||||
"[ElectronPlatformService] Electron API not available, falling back to web download",
|
||||
);
|
||||
|
||||
const blob = new Blob([content], { type: "application/json" });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const downloadLink = document.createElement("a");
|
||||
downloadLink.href = url;
|
||||
downloadLink.download = uniqueFileName;
|
||||
downloadLink.style.display = "none";
|
||||
|
||||
document.body.appendChild(downloadLink);
|
||||
downloadLink.click();
|
||||
document.body.removeChild(downloadLink);
|
||||
|
||||
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
||||
|
||||
logger.info(
|
||||
`[ElectronPlatformService] Fallback download initiated`,
|
||||
uniqueFileName,
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error("[ElectronPlatformService] File save failed", error);
|
||||
throw new Error(`Failed to save file: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the system file picker to let the user choose where to save a file (Electron platform).
|
||||
* Uses Electron's IPC to show the native save dialog.
|
||||
*
|
||||
* @param fileName - The suggested filename for the file
|
||||
* @param content - The content to write to the file
|
||||
* @returns Promise that resolves when the file is saved
|
||||
*/
|
||||
async saveAs(fileName: string, content: string): Promise<void> {
|
||||
try {
|
||||
// Ensure content is valid JSON
|
||||
try {
|
||||
JSON.parse(content);
|
||||
} catch {
|
||||
throw new Error('Content must be valid JSON');
|
||||
}
|
||||
|
||||
// Generate unique filename
|
||||
const uniqueFileName = this.generateUniqueFileNameElectron(fileName);
|
||||
|
||||
logger.info(
|
||||
`[ElectronPlatformService] Using native IPC for save as dialog`,
|
||||
uniqueFileName,
|
||||
);
|
||||
|
||||
// Check if we're running in Electron with the API available
|
||||
if (typeof window !== "undefined" && window.electronAPI) {
|
||||
// Use the native Electron IPC API for file exports (same as saveToDevice for now)
|
||||
// TODO: Implement native save dialog when available
|
||||
const result = await window.electronAPI.exportData(uniqueFileName, content);
|
||||
|
||||
if (result.success) {
|
||||
logger.info(
|
||||
`[ElectronPlatformService] File saved successfully to`,
|
||||
result.path,
|
||||
);
|
||||
logger.info(
|
||||
`[ElectronPlatformService] File saved via save as`,
|
||||
uniqueFileName,
|
||||
);
|
||||
} else {
|
||||
logger.error(
|
||||
`[ElectronPlatformService] Native save as failed`,
|
||||
result.error,
|
||||
);
|
||||
throw new Error(`Native file save as failed: ${result.error}`);
|
||||
}
|
||||
} else {
|
||||
// Fallback to web-style download if Electron API is not available
|
||||
logger.warn(
|
||||
"[ElectronPlatformService] Electron API not available, falling back to web download",
|
||||
);
|
||||
|
||||
const blob = new Blob([content], { type: "application/json" });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const downloadLink = document.createElement("a");
|
||||
downloadLink.href = url;
|
||||
downloadLink.download = uniqueFileName;
|
||||
downloadLink.style.display = "none";
|
||||
|
||||
document.body.appendChild(downloadLink);
|
||||
downloadLink.click();
|
||||
document.body.removeChild(downloadLink);
|
||||
|
||||
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
||||
|
||||
logger.info(
|
||||
`[ElectronPlatformService] Fallback download initiated`,
|
||||
uniqueFileName,
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error("[ElectronPlatformService] File save as failed", error);
|
||||
throw new Error(`Failed to save file as: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates unique filename with timestamp, hashed device ID, and counter
|
||||
*/
|
||||
private generateUniqueFileNameElectron(baseName: string, counter = 0): string {
|
||||
const now = new Date();
|
||||
const timestamp = now.toISOString()
|
||||
.replace(/[:.]/g, '-')
|
||||
.replace('T', '_')
|
||||
.replace('Z', '');
|
||||
|
||||
const deviceIdHash = this.getHashedDeviceIdentifierElectron();
|
||||
const counterSuffix = counter > 0 ? `_${counter}` : '';
|
||||
|
||||
const maxBaseLength = 45;
|
||||
const truncatedBase = baseName.length > maxBaseLength
|
||||
? baseName.substring(0, maxBaseLength)
|
||||
: baseName;
|
||||
|
||||
const nameWithoutExt = truncatedBase.replace(/\.json$/i, '');
|
||||
const extension = '.json';
|
||||
const devicePart = `_${deviceIdHash}`;
|
||||
const timestampPart = `_${timestamp}${counterSuffix}`;
|
||||
|
||||
const totalLength = nameWithoutExt.length + devicePart.length + timestampPart.length + extension.length;
|
||||
|
||||
if (totalLength > 200) {
|
||||
const availableLength = 200 - devicePart.length - timestampPart.length - extension.length;
|
||||
const finalBase = nameWithoutExt.substring(0, Math.max(10, availableLength));
|
||||
return `${finalBase}${devicePart}${timestampPart}${extension}`;
|
||||
}
|
||||
|
||||
return `${nameWithoutExt}${devicePart}${timestampPart}${extension}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets hashed device identifier
|
||||
*/
|
||||
private getHashedDeviceIdentifierElectron(): string {
|
||||
try {
|
||||
const deviceInfo = this.getDeviceInfoElectron();
|
||||
return this.hashStringElectron(deviceInfo);
|
||||
} catch (error) {
|
||||
return 'electron';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets device info string
|
||||
*/
|
||||
private getDeviceInfoElectron(): string {
|
||||
try {
|
||||
// Use machine-specific information
|
||||
const os = require('os');
|
||||
const hostname = os.hostname() || 'unknown';
|
||||
const platform = os.platform() || 'unknown';
|
||||
const arch = os.arch() || 'unknown';
|
||||
|
||||
// Create device info string
|
||||
return `${platform}_${hostname}_${arch}`;
|
||||
} catch (error) {
|
||||
return 'electron';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple hash function for device ID
|
||||
*/
|
||||
private hashStringElectron(str: string): string {
|
||||
let hash = 0;
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
const char = str.charCodeAt(i);
|
||||
hash = ((hash << 5) - hash) + char;
|
||||
hash = hash & hash;
|
||||
}
|
||||
return Math.abs(hash).toString(16).padStart(4, '0').substring(0, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if running on Capacitor platform.
|
||||
*
|
||||
|
||||
@@ -97,7 +97,9 @@ export class WebPlatformService implements PlatformService {
|
||||
}
|
||||
} else {
|
||||
// We're in a worker context - skip initBackend call
|
||||
logger.info(
|
||||
// Use console for critical startup message to avoid circular dependency
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(
|
||||
"[WebPlatformService] Skipping initBackend call in worker context",
|
||||
);
|
||||
}
|
||||
@@ -592,157 +594,6 @@ export class WebPlatformService implements PlatformService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves content directly to the device's Downloads folder (Android) or Documents folder (iOS).
|
||||
* Uses MediaStore on Android API 29+ and falls back to SAF on older versions.
|
||||
*
|
||||
* @param fileName - The filename of the file to save
|
||||
* @param content - The content to write to the file
|
||||
* @returns Promise that resolves when the file is saved
|
||||
*/
|
||||
async saveToDevice(fileName: string, content: string): Promise<void> {
|
||||
try {
|
||||
// Ensure content is valid JSON
|
||||
try {
|
||||
JSON.parse(content);
|
||||
} catch {
|
||||
throw new Error('Content must be valid JSON');
|
||||
}
|
||||
|
||||
// Generate unique filename
|
||||
const uniqueFileName = this.generateUniqueFileName(fileName);
|
||||
|
||||
// Web platform: Use the same download mechanism as writeAndShareFile
|
||||
await this.writeAndShareFile(uniqueFileName, content);
|
||||
logger.log("[WebPlatformService] File saved to device", uniqueFileName);
|
||||
} catch (error) {
|
||||
logger.error("[WebPlatformService] Error saving file to device", error);
|
||||
throw new Error(
|
||||
`Failed to save file to device: ${error instanceof Error ? error.message : "Unknown error"}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the system file picker to let the user choose where to save a file (web platform).
|
||||
* Uses the browser's download mechanism with a suggested filename.
|
||||
*
|
||||
* @param fileName - The suggested filename for the file
|
||||
* @param content - The content to write to the file
|
||||
* @returns Promise that resolves when the file is saved
|
||||
*/
|
||||
async saveAs(fileName: string, content: string): Promise<void> {
|
||||
try {
|
||||
// Ensure content is valid JSON
|
||||
try {
|
||||
JSON.parse(content);
|
||||
} catch {
|
||||
throw new Error('Content must be valid JSON');
|
||||
}
|
||||
|
||||
// Generate unique filename
|
||||
const uniqueFileName = this.generateUniqueFileName(fileName);
|
||||
|
||||
// Web platform: Use the same download mechanism as writeAndShareFile
|
||||
await this.writeAndShareFile(uniqueFileName, content);
|
||||
logger.log("[WebPlatformService] File saved as", uniqueFileName);
|
||||
} catch (error) {
|
||||
logger.error("[WebPlatformService] Error saving file as", error);
|
||||
throw new Error(
|
||||
`Failed to save file as: ${error instanceof Error ? error.message : "Unknown error"}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates unique filename with timestamp, hashed device ID, and counter
|
||||
*/
|
||||
private generateUniqueFileName(baseName: string, counter = 0): string {
|
||||
const now = new Date();
|
||||
const timestamp = now.toISOString()
|
||||
.replace(/[:.]/g, '-')
|
||||
.replace('T', '_')
|
||||
.replace('Z', '');
|
||||
|
||||
const deviceIdHash = this.getHashedDeviceIdentifier();
|
||||
const counterSuffix = counter > 0 ? `_${counter}` : '';
|
||||
|
||||
const maxBaseLength = 45;
|
||||
const truncatedBase = baseName.length > maxBaseLength
|
||||
? baseName.substring(0, maxBaseLength)
|
||||
: baseName;
|
||||
|
||||
const nameWithoutExt = truncatedBase.replace(/\.json$/i, '');
|
||||
const extension = '.json';
|
||||
const devicePart = `_${deviceIdHash}`;
|
||||
const timestampPart = `_${timestamp}${counterSuffix}`;
|
||||
|
||||
const totalLength = nameWithoutExt.length + devicePart.length + timestampPart.length + extension.length;
|
||||
|
||||
if (totalLength > 200) {
|
||||
const availableLength = 200 - devicePart.length - timestampPart.length - extension.length;
|
||||
const finalBase = nameWithoutExt.substring(0, Math.max(10, availableLength));
|
||||
return `${finalBase}${devicePart}${timestampPart}${extension}`;
|
||||
}
|
||||
|
||||
return `${nameWithoutExt}${devicePart}${timestampPart}${extension}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets hashed device identifier
|
||||
*/
|
||||
private getHashedDeviceIdentifier(): string {
|
||||
try {
|
||||
const deviceInfo = this.getDeviceInfo();
|
||||
return this.hashString(deviceInfo);
|
||||
} catch (error) {
|
||||
return 'web';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets device info string
|
||||
*/
|
||||
private getDeviceInfo(): string {
|
||||
try {
|
||||
// Use browser fingerprint or fallback
|
||||
const userAgent = navigator.userAgent;
|
||||
const language = navigator.language || 'unknown';
|
||||
const platform = navigator.platform || 'unknown';
|
||||
|
||||
let browser = 'unknown';
|
||||
let os = 'unknown';
|
||||
|
||||
if (userAgent.includes('Chrome')) browser = 'chrome';
|
||||
else if (userAgent.includes('Firefox')) browser = 'firefox';
|
||||
else if (userAgent.includes('Safari')) browser = 'safari';
|
||||
else if (userAgent.includes('Edge')) browser = 'edge';
|
||||
|
||||
if (userAgent.includes('Windows')) os = 'win';
|
||||
else if (userAgent.includes('Mac')) os = 'mac';
|
||||
else if (userAgent.includes('Linux')) os = 'linux';
|
||||
else if (userAgent.includes('Android')) os = 'android';
|
||||
else if (userAgent.includes('iOS')) os = 'ios';
|
||||
|
||||
return `${browser}_${os}_${platform}_${language}`;
|
||||
} catch (error) {
|
||||
return 'web';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple hash function for device ID
|
||||
*/
|
||||
private hashString(str: string): string {
|
||||
let hash = 0;
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
const char = str.charCodeAt(i);
|
||||
hash = ((hash << 5) - hash) + char;
|
||||
hash = hash & hash;
|
||||
}
|
||||
return Math.abs(hash).toString(16).padStart(4, '0').substring(0, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see PlatformService.dbQuery
|
||||
*/
|
||||
|
||||
@@ -77,7 +77,7 @@
|
||||
v-if="meetings.length === 0 && !isRegistered"
|
||||
class="text-center text-gray-500 py-8"
|
||||
>
|
||||
No onboarding meetings available
|
||||
No onboarding meetings are available
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user