Skip to content

Development Guide ​

Home playlist layouts and title initials ​

The menu beside each home section offers automatic, carousel, grid and vertical list layouts, saved on this device. Automatic keeps mobile carousels and wide grids; all modes display song counts. Settings → Appearance → Home playlist grid includes Show radio section, enabled by default. Turning it off hides the entire home radio section; the choice is stored locally and can be enabled again. This section also controls columns and rows, including phone grids. Narrow widths reduce columns. All rows and vertical lists fetch approximately 200 playlists; View all opens the complete collection.

Details retain song numbers and show an initial above the number at each contiguous group boundary. Chinese uses pinyin initials, Latin letters are uppercased, and digits, symbols and other scripts use #. Hints follow sorting and search without changing titles or playlist order. Dragging the scrollbar shows “initial · current title” and “position / total”, deriving the current row from the actual layout. Selection and manual sorting retain checkboxes and drag handles.

See the AI development workflow for continuous execution, validation evidence, cross-repository Issue triage, and retrospectives. Lessons live in root LESSONS.md. Commits, pushes, releases, and Issue writes follow explicit authorization.

The Built-in navigation section under Settings → Extensions → Navigation & plugins has switches for Home and Library, below the plugin list. The footer shows the tab count, explains that Settings is always visible, and describes mobile overflow.

Home is visible by default. With Home hidden, the app opens the first visible destination among Library, active plugin tabs in their configured order, and Settings. Both switches save through /settings/tab-config and preserve plugin preferences and ordering. Library and active plugin tabs share a limit of ten.

The Library switch in #501 passed flutter analyze, all 656 tests, and the embedded Web build. Docker Chromium exercised Chinese 1280px/390px and English wide layouts, with screenshots reviewed. The isolated backend confirmed that the switch changes Library visibility and preserves all plugin preferences and ordering. Appearance had one fewer control because the switch moved to Built-in navigation. The evidence from that run is in /tmp/issue-501-navigation-flutter-{zh,en}.json and matching PNGs.

Host playback UI for plugins ​

Add static/songloft-ui.json to the plugin package with {"ui":{"playerBar":"host"}}. Plugin tabs and standalone plugin pages reserve space for the host player bar when a song is loaded. Plugins without this explicit declaration retain their existing layout.

Check host.getInfo() capabilities for player.playerBar, player.openPlayer, and player.openQueue. Import player from @songloft/client-sdk or use the updated window.SongloftPlugin.player. Call player.openPlayer() to open the current song in the fullscreen player or player.openQueue() to open the host queue. Both calls are available independently of the bar declaration.

On November 27, 2026, flutter analyze, 187 related tests, and the embedded Web build passed on Linux with Flutter 3.44.8. Docker Chrome 121 exercised an ordinary plugin tab, an opt-in tab, and an opt-in standalone page. Both opt-in pages reserved 66 pixels and returned to the same iframe document after opening the queue or fullscreen player. Native device checks were not run. songloft-org/songloft#599

GitHub community plugin discovery ​

Entry: Settings → Extensions → Plugin Store → source menu → GitHub discovery. This separate page is not saved as a subscription source. Returning preserves the store source and search; source settings still manage subscriptions.

The client searches the public songloft-plugin topic and validates root plugin.json files, same-repository update chains, hash formats and matching stable Release .jsplugin.zip assets. Search, sorting, pagination, refresh, GitHub proxies and rate-limit messages are supported. Invalid and temporarily unverified repositories have separate counts. GitHub requests carry no server login credentials.

The GitHub Token entry at the top of discovery supports saving, replacing and clearing a token. Authenticated GET/PUT /settings/github-discovery-token stores it on the connected server; the client reads it on page entry and explicit refresh, and still sends discovery requests itself. With a token, search and Release APIs bypass GitHub acceleration proxies and connect directly to https://api.github.com with an Authorization header. Neither proxies nor public metadata requests receive this token, and authenticated failures do not fall back to a proxy. Without a token, the existing anonymous proxy flow remains. Saving or clearing cancels old requests and restarts discovery while preserving search and sort; rejected tokens have a specific message. Flutter debug logs omit this settings endpoint's request/response contents.

Token and store validation: all 682 tests pass. After the final empty-source state and cancellation assertion changes, flutter analyze reports no issues, and 15 store widget tests and the embedded Web build pass. Coverage includes hidden input, save/clear, preserving settings on failure, credential log isolation, progressive loading, credential precedence and cache boundaries. An isolated real Go backend verifies persistence after restart, clearing and no-store responses; the backend's full checks pass. Flutter native devices and browsers have not been tested for this batch; the 539-test and browser results below describe earlier discovery validation.

Client store requests and credential precedence ​

Pre-commit review fixes fallback after source removal/disablement, cancellation when all sources are deleted, update actions for higher versions arriving after an early install, anonymous-401 classification and cache replacement after valid empty refreshes. All 682 tests pass; after the final empty-source state and cancellation assertion changes, 15 store widget tests and analysis pass. Removing the protections in an isolated copy makes six regressions fail as expected; the copy is restored. The review stage remains uncommitted; native devices and the Flutter browser have not been exercised.

An independent public Dio fetches registries, includes and metadata, displaying each plugin as it resolves with at most eight concurrent requests. Complete catalogs have a five-minute client cache shared by search and pagination; explicit refresh reads source configuration again. Cancellation, search, source/server changes and unmount invalidate old progress; successful installation updates rows in place. Installed-plugin lists and installation still use the server, with compatible server fallback on Web CORS or connection failures.

Each source's token wins. The shared GitHub token is only used when a request has no source credential and targets https://api.github.com. Raw metadata, third-party sources, server fallback and installation never receive the shared token; authenticated requests bypass GitHub prefix proxies. Explicit plugin URLs inherit their source credential, includes only inherit on the same origin, and chained updateUrl metadata only inherits on the origin of the original manifest or configured source. Installation sends source_url so the server resolves the current source token rather than receiving an outdated credential from the client. The server's HTTP proxy only affects fallback and downloads. Earlier first results do not guarantee a shorter total load time.

URL validation rejects raw or encoded dot segments and backslashes before Dart URI normalization, matching native Lynx validation. Successful-install session markers bridge refreshes; authoritative server lists reconcile them so uninstalling or replacing plugins elsewhere does not retain stale installation state.

Release tags locate the actual Release referenced by the download URL; they need not equal manifest versions. For example, tag v0.17 can accompany manifest version 0.17.0. Download URLs, actual Release tags and uploaded assets are still checked, and update-manifest chain version consistency remains enforced.

Details show the version, permissions and minimum host version. Installation requires confirmation that Songloft has not reviewed the plugin; conflicting entry paths require replacement confirmation. Unknown or insufficient host versions and unavailable installed-plugin data disable installation. The existing server installation endpoint is reused; format validation is not a security review. Details use a bottom sheet on narrow screens and a dialog on wide screens.

When the server explicitly reports dev, all plugins bypass the minimum host version check. Stable servers still compare minimum versions; failed version requests and other unrecognized versions require a retry. dev does not bypass plugin validation, installed-plugin data checks or installation confirmation.

Validation: static analysis, all 539 tests and the Web build pass. Widget tests cover Chinese, English and Spanish at narrow/wide widths with large text. Docker Chromium exercises live GitHub discovery (seven repositories: three valid, four excluded), zero requests before confirmation, exactly one install after confirmation and return to the store. Queries against an isolated real Go backend confirm the installed version and Release URL. Native Flutter devices have not been tested.

Environment Setup ​

Prerequisites ​

  • Flutter >= 3.41.0
  • Dart SDK >= 3.7.0

Platform-Specific Dependencies ​

Linux:

bash
sudo apt-get install clang cmake ninja-build pkg-config libgtk-3-dev

Android:

bash
sdkmanager --licenses

Requires Android SDK, NDK, and JDK 17+.

macOS / iOS:

  • Xcode 15+
  • CocoaPods: sudo gem install cocoapods

Windows:

  • Visual Studio 2022 (with C++ Desktop Development workload)
  • Windows 10 SDK

First Run ​

bash
flutter pub get
flutter run -d chrome --no-web-resources-cdn   # Web standalone
flutter run -d macos                            # macOS

The backend must be started first: run make run in the parent repository (default http://localhost:58091, credentials admin/admin).


Adding a Feature Module ​

The project follows a Feature-First architecture. Each feature module has a three-layer structure:

features/<name>/
├── data/              # API classes (HTTP calls) + Repository
│   ├── <name>_api.dart
│   └── <name>_repository.dart  (optional)
├── domain/            # State models + business logic
│   └── <name>_state.dart
└── presentation/      # UI layer
    ├── <name>_page.dart
    ├── providers/
    │   └── <name>_provider.dart
    └── widgets/
        └── <name>_xxx.dart

Provider Naming Conventions ​

Providers are written by hand using Riverpod (no code generation / build_runner):

dart
// API instance (stateless)
final xxxApiProvider = Provider<XxxApi>((ref) {
  final dio = ref.watch(dioProvider);
  return XxxApi(dio);
});

// Async data loading
final xxxDetailProvider = FutureProvider.family<Xxx, int>((ref, id) async {
  final api = ref.watch(xxxApiProvider);
  return api.getDetail(id);
});

// Stateful business logic
final xxxProvider = NotifierProvider<XxxNotifier, XxxState>(XxxNotifier.new);

// Async stateful
final xxxListProvider = AsyncNotifierProvider<XxxListNotifier, XxxListState>(
  XxxListNotifier.new,
);

Adding Routes ​

Routes are configured in lib/core/router/app_router.dart:

  1. Add a path constant in the AppRoutes class:
dart
class AppRoutes {
  static const String myFeature = '/my-feature';
}
  1. Add the route to the GoRouter inside routerProvider (either within the Shell or as a standalone route):
dart
GoRoute(
  path: AppRoutes.myFeature,
  builder: (context, state) => const MyFeaturePage(),
),
  1. The auth guard works automatically: redirect checks authStateProvider and redirects to /login when unauthenticated. The /login path is not protected by the guard.

API Integration ​

HTTP Client ​

Dio is wrapped in lib/core/network/api_client.dart:

  • dioProvider — Dio instance with auth interceptor
  • publicDioProvider — Dio without auth (for public endpoints like login)
  • apiClientProvider — Higher-level wrapper (rarely used directly)

JWT Dual-Token ​

AuthInterceptor (lib/core/network/auth_interceptor.dart) handles automatically:

  • Injects Authorization: Bearer <accessToken> on each request
  • Refreshes the token using refreshToken on 401 responses
  • Concurrent refresh protection (multiple 401s trigger only one refresh)
  • Calls onTokenExpired callback to trigger logout on refresh failure

Resource URLs ​

UrlHelper (lib/core/utils/url_helper.dart) constructs cover image, audio, and other resource URLs by appending baseUrl + token automatically.

Adding an API Class ​

dart
class MyFeatureApi {
  final Dio _dio;
  MyFeatureApi(this._dio);

  Future<MyModel> getData(int id) async {
    final response = await _dio.get('/api/v1/my-feature/$id');
    return MyModel.fromJson(response.data);
  }
}

Conditional Imports ​

Web does not support certain native features (e.g. WebView). Use the conditional import stub pattern:

dart
// plugin_webview_page.dart (entry file)
export 'plugin_webview_page_stub.dart'
    if (dart.library.io) 'plugin_webview_page_native.dart';
dart
// plugin_webview_page_stub.dart (Web — show placeholder or alternative UI)
class PluginWebViewPage extends StatelessWidget { ... }

// plugin_webview_page_native.dart (native — use WebView)
class PluginWebViewPage extends StatelessWidget { ... }

Files in the project using this pattern:

  • plugin_webview_page.dart / _native.dart / _stub.dart
  • plugin_tab_page.dart / _native.dart / _stub.dart
  • web_cache_clearer.dart / _stub.dart

Lint Rules ​

Key rules in analysis_options.yaml:

RuleDescription
prefer_const_constructorsAdd const to widget instantiation where possible
prefer_const_declarationsDeclare variables as const when applicable
prefer_single_quotesUse single quotes consistently
avoid_printDisallow print(); use debugPrint() instead

Excluded: *.g.dart and *.freezed.dart files are not checked.


Testing ​

bash
flutter test                                    # Run all tests
flutter test test/core/env/tv_detector_test.dart # Run a specific file

Test files live under test/, mirroring the path structure of lib/.

GitHub discovery: cross-repository packages (2026-10-08) ​

Download URLs and public update metadata may belong to other GitHub repositories. Clients validate the target repository’s stable Release and actual nonempty asset, retaining version, entry-path, hash and URL checks. Details show the download URL and installation confirmation identifies the package repository. Installed and update status use the actual package repository.

GitHub discovery: empty root hashes (2026-10-08) ​

Root plugin.json entryHash and zipHash may be omitted or empty; nonempty values still undergo format validation. Discovery does not require build hashes to be written back to the source root manifest. The server continues validating the actual installation package.