Skip to content

feat: add WebDAV sync of subscriptions from Clash Verge Rev backups - #886

Open
chen-xiaochen wants to merge 4 commits into
MetaCubeX:mainfrom
chen-xiaochen:feat/webdav-sync
Open

chen-xiaochen wants to merge 4 commits into
MetaCubeX:mainfrom
chen-xiaochen:feat/webdav-sync

Conversation

@chen-xiaochen

Copy link
Copy Markdown

Summary

Adds an opt-in WebDAV sync feature that imports subscriptions (remote profiles) from Clash Verge Rev desktop backups stored on a WebDAV server.

Motivation

Many users run Clash Verge (Rev) on desktop and CMFA on Android with the same subscriptions. Today, keeping the phone in sync means re-copying subscription links through chat apps every time a subscription changes. Clash Verge Rev already supports automatic WebDAV backups, so CMFA can consume those backups directly and sync with one tap.

What it does

  • New entry WebDAV Sync under Settings
  • User configures server address / username / password, then taps "Sync Now"
  • The sync flow:
    1. PROPFIND the WebDAV directory, pick the newest *-backup-*.zip (Verge Rev's automatic backup naming)
    2. Parse profiles.yaml inside the zip, keep type: remote entries (name + subscription URL)
    3. Match against existing profiles by name: existing profiles are patched with the subscription URL and re-fetched; new ones are created as Url profiles and fetched
    4. Per-profile failures are counted and reported without aborting the whole sync

Implementation notes

  • WebDavClient (common): minimal PROPFIND/GET client with basic auth on HttpURLConnection — no new dependencies
  • VergeBackup (common): line-based profiles.yaml parser; only reads the metadata file, does not import Verge-specific merge/script/rules files
  • Reuses the existing preferenceScreen DSL, UiStore storage, withProfile IPC and ProfileManager create/patch/commit APIs — no new architecture
  • Settings are stored in UiStore (SharedPreferences), same as other UI settings
  • Translations included for en / zh-rCN / zh-rHK / zh-rTW / ja-rJP / ko-rKR / ru / vi

Testing

  • assembleAlphaDebug builds successfully for all flavors/ABIs
  • Parser verified against a real Clash Verge Rev WebDAV backup (7 remote profiles extracted correctly)
  • On-device sync flow not yet exercised — reviews/testing welcome

Out of scope (intentionally)

  • Upload/backup from CMFA to WebDAV (CMFA has a different data model than Verge's backup format)
  • Scheduled automatic sync (can be added later if there's demand)

Add a WebDAV sync option under Settings that imports subscriptions
from Clash Verge Rev desktop backups stored on a WebDAV server:

- WebDavClient: minimal PROPFIND/GET client with basic auth on
  HttpURLConnection, no new dependencies
- VergeBackup: parse profiles.yaml inside the backup zip and extract
  remote (subscription) entries
- Settings entry + WebDavSettingsActivity/Design: configure server
  address/username/password, sync on demand
- Profiles are matched by name: existing ones are updated with the
  new subscription URL, missing ones are created; per-profile failures
  are counted and reported without aborting the rest
- Translations for en/zh/zh-rHK/zh-rTW/ja/ko/ru/vi
- Bind surface in WebDavSettingsDesign: the shared settings layout
  references surface.insets in padding expressions, a null surface
  throws NPE on inflation
- Replace java.util.Base64 with android.util.Base64: the former
  requires API 26 and the project targets minSdk 21 without
  desugaring, so tapping Sync crashed on Android < 8.0
preferenceScreen builds its own view hierarchy; without
binding.content.addView(screen.root) the page rendered empty
(title bar only)
- Send PROPFIND over a raw socket: HttpURLConnection cannot carry
  WebDAV extension methods and the method-field reflection hack does
  not survive OEM implementations (request went out as GET on
  ColorOS 15, answered 403/501)
- Strip whitespace from stored credentials (trailing newline in the
  username produced HTTP 401)
- Fall back to Verge's 'clash-verge-rev-backup' subdirectory: Verge
  always creates and uploads under it (clash-verge-rev
  src-tauri/src/utils/dirs.rs BACKUP_DIR), so the configured URL is
  typically the bare server address
- Return directory-relative paths from listBackupFiles so downloads
  resolve against the listed directory
- Include the response body in HTTP error messages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant