Skip to content

Commit a6a95aa

Browse files
Replace Fletd server for desktop apps with a light-weight Python shim (#838)
* WebSocket client abstracted to a protocol * close() -> disconnect() * ws.pageEventFromWeb() -> server.sendPageEvent() * SocketConnection for desktop apps * Socket server/connection prototype * "add" command - buggy implementation * "add" command implemented * All commands supported * SyncLocalSocketConnection * Move common logic to LocalConnection * AsyncLocalSocketConnection - prototype * AsyncLocalSocketConnection complete * Poetry (#867) * Poetry files added * Run poetry in CI * Build with poetry * poetry install * New project structure with flet_core * Break everything into 2 packages * simplified init from flet_core * Fix CI * Remove beartype tests * get rid of beartype * All python tasks * Patch version * build wheels * Fix patching * Run all jobs * Add "assetsDir" to a client * support assets_dir in desktop apps * Fix Studio build * Fix Dart imports * Update README.md * Update __init__.py * Support assets dir in `flet run` * Fix _SyncLocalSocketConnection__uds_path error * Update sync_local_socket_connection.py * Support assets dir in markdown control * Adding missing imports * Use FLET_VIEW_PATH on Windows * Faster scrolling with mouse wheel on Windows Fix #872 * Fixed exception on `page.window_maximizable` Fixed #870 * Custom port for TCP connections * Bump file_picker to fix blocking UI thread on Windows * Bump audioplayers to 2.0.0 * Remove fletd from installer package * added pre-commit * Fix pyinstaller40 entry points * Add `flet pack` args: --onedir, multiple --add-data
1 parent bba864d commit a6a95aa

File tree

240 files changed

+3753
-2854
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

240 files changed

+3753
-2854
lines changed

.appveyor.yml

+24-13
Original file line numberDiff line numberDiff line change
@@ -407,13 +407,13 @@ for:
407407
install:
408408
- python --version
409409
- cd sdk/python
410-
- pip install pdm
411-
- pdm install
410+
- pip install poetry
411+
- poetry install
412412

413413
build: off
414414

415415
test_script:
416-
- pdm run pytest tests
416+
- poetry run pytest
417417

418418
######################
419419
# Python Build #
@@ -425,27 +425,38 @@ for:
425425
install:
426426
- python --version
427427
- cd sdk/python
428-
- pip install --upgrade setuptools wheel twine pdm
429-
- pdm install
428+
- pip install --upgrade setuptools wheel twine poetry tomlkit
429+
- poetry install
430430

431431
test: off
432432

433433
build_script:
434+
# patch version
434435
- ps: |
435436
$ErrorActionPreference = "Stop"
436-
$ver = $env:APPVEYOR_BUILD_VERSION.replace("+", ".dev")
437-
(Get-Content pyproject.toml).replace("version = `"0.1.0`"", "version = `"$ver`"") | Set-Content pyproject.toml
438-
(Get-Content flet/version.py).replace("version = `"`"", "version = `"$ver`"") | Set-Content flet/version.py
439-
440-
# build package
441-
- pdm build
437+
$env:PYPI_VER = $env:APPVEYOR_BUILD_VERSION.replace("+", ".dev")
438+
$vp = "packages/flet/src/flet/version.py"; (Get-Content $vp).replace("version = `"`"", "version = `"$env:PYPI_VER`"") | Set-Content $vp
439+
- python3 patch_toml.py packages/flet/pyproject.toml $PYPI_VER
440+
- python3 patch_toml.py packages/flet-core/pyproject.toml $PYPI_VER
441+
442+
# build "flet-core" package
443+
- pushd packages/flet-core
444+
- poetry build
445+
- popd
446+
447+
# build "flet" package
448+
- pushd packages/flet
449+
- poetry build
442450
- python3 build-wheels.py
451+
- popd
443452

444453
# publish package
445454
- sh: |
446455
if [[ ("$APPVEYOR_REPO_BRANCH" == "main" || "$APPVEYOR_REPO_TAG_NAME" != "") && "$APPVEYOR_PULL_REQUEST_NUMBER" == "" ]]; then
447-
twine upload dist/*
456+
twine upload packages/flet-core/dist/* packages/flet/dist/*
448457
fi
458+
449459
450460
artifacts:
451-
path: sdk/python/dist/*
461+
- path: sdk/python/packages/flet-core/dist/*
462+
- path: sdk/python/packages/flet/dist/*

client/lib/main.dart

+9-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ void main([List<String>? args]) async {
1616
await setupDesktop();
1717

1818
var pageUrl = Uri.base.toString();
19+
var assetsDir = "";
1920
//debugPrint("Uri.base: ${Uri.base}");
2021

2122
if (kDebugMode) {
@@ -38,9 +39,15 @@ void main([List<String>? args]) async {
3839
}
3940
pageUrl = args[0];
4041
if (args.length > 1) {
41-
var pidFile = await File(args[1]).create();
42+
var pidFilePath = args[1];
43+
debugPrint("Args contain a path to PID file: $pidFilePath}");
44+
var pidFile = await File(pidFilePath).create();
4245
await pidFile.writeAsString("$pid");
4346
}
47+
if (args.length > 2) {
48+
assetsDir = args[2];
49+
debugPrint("Args contain a path assets directory: $assetsDir}");
50+
}
4451
}
4552

4653
debugPrint("Page URL: $pageUrl");
@@ -61,6 +68,7 @@ void main([List<String>? args]) async {
6168
runApp(FletApp(
6269
title: 'Flet',
6370
pageUrl: pageUrl,
71+
assetsDir: assetsDir,
6472
errorsHandler: errorsHandler,
6573
));
6674
}

client/pubspec.lock

+11-11
Original file line numberDiff line numberDiff line change
@@ -28,49 +28,49 @@ packages:
2828
name: audioplayers
2929
url: "https://pub.dartlang.org"
3030
source: hosted
31-
version: "1.1.0"
31+
version: "2.0.0"
3232
audioplayers_android:
3333
dependency: transitive
3434
description:
3535
name: audioplayers_android
3636
url: "https://pub.dartlang.org"
3737
source: hosted
38-
version: "1.1.0"
38+
version: "1.1.4"
3939
audioplayers_darwin:
4040
dependency: transitive
4141
description:
4242
name: audioplayers_darwin
4343
url: "https://pub.dartlang.org"
4444
source: hosted
45-
version: "1.0.2"
45+
version: "2.0.0"
4646
audioplayers_linux:
4747
dependency: transitive
4848
description:
4949
name: audioplayers_linux
5050
url: "https://pub.dartlang.org"
5151
source: hosted
52-
version: "1.0.1"
52+
version: "1.0.3"
5353
audioplayers_platform_interface:
5454
dependency: transitive
5555
description:
5656
name: audioplayers_platform_interface
5757
url: "https://pub.dartlang.org"
5858
source: hosted
59-
version: "2.0.0"
59+
version: "3.0.0"
6060
audioplayers_web:
6161
dependency: transitive
6262
description:
6363
name: audioplayers_web
6464
url: "https://pub.dartlang.org"
6565
source: hosted
66-
version: "2.0.0"
66+
version: "2.1.1"
6767
audioplayers_windows:
6868
dependency: transitive
6969
description:
7070
name: audioplayers_windows
7171
url: "https://pub.dartlang.org"
7272
source: hosted
73-
version: "1.1.0"
73+
version: "1.1.2"
7474
boolean_selector:
7575
dependency: transitive
7676
description:
@@ -140,7 +140,7 @@ packages:
140140
name: file_picker
141141
url: "https://pub.dartlang.org"
142142
source: hosted
143-
version: "5.0.1"
143+
version: "5.2.5"
144144
flet:
145145
dependency: "direct main"
146146
description:
@@ -408,7 +408,7 @@ packages:
408408
name: screen_retriever
409409
url: "https://pub.dartlang.org"
410410
source: hosted
411-
version: "0.1.2"
411+
version: "0.1.5"
412412
sensors_plus:
413413
dependency: transitive
414414
description:
@@ -658,14 +658,14 @@ packages:
658658
name: win32
659659
url: "https://pub.dartlang.org"
660660
source: hosted
661-
version: "2.7.0"
661+
version: "3.1.3"
662662
window_manager:
663663
dependency: transitive
664664
description:
665665
name: window_manager
666666
url: "https://pub.dartlang.org"
667667
source: hosted
668-
version: "0.2.6"
668+
version: "0.3.0"
669669
window_to_front:
670670
dependency: transitive
671671
description:

package/lib/src/actions.dart

+14-13
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ import 'protocol/remove_control_payload.dart';
1313
import 'protocol/replace_page_controls_payload.dart';
1414
import 'protocol/session_crashed_payload.dart';
1515
import 'protocol/update_control_props_payload.dart';
16-
import 'web_socket_client.dart';
16+
import 'flet_server.dart';
1717

1818
class PageLoadAction {
1919
final Uri pageUri;
20-
final WebSocketClient ws;
21-
PageLoadAction(this.pageUri, this.ws);
20+
final String assetsDir;
21+
final FletServer server;
22+
PageLoadAction(this.pageUri, this.assetsDir, this.server);
2223
}
2324

2425
class PageReconnectingAction {
@@ -28,21 +29,21 @@ class PageReconnectingAction {
2829
class PageSizeChangeAction {
2930
final Size newPageSize;
3031
final WindowMediaData? wmd;
31-
final WebSocketClient ws;
32-
PageSizeChangeAction(this.newPageSize, this.wmd, this.ws);
32+
final FletServer server;
33+
PageSizeChangeAction(this.newPageSize, this.wmd, this.server);
3334
}
3435

3536
class SetPageRouteAction {
3637
final String route;
37-
final WebSocketClient ws;
38-
SetPageRouteAction(this.route, this.ws);
38+
final FletServer server;
39+
SetPageRouteAction(this.route, this.server);
3940
}
4041

4142
class WindowEventAction {
4243
final String eventName;
4344
final WindowMediaData wmd;
44-
final WebSocketClient ws;
45-
WindowEventAction(this.eventName, this.wmd, this.ws);
45+
final FletServer server;
46+
WindowEventAction(this.eventName, this.wmd, this.server);
4647
}
4748

4849
class PageBrightnessChangeAction {
@@ -56,9 +57,9 @@ class RegisterWebClientAction {
5657
}
5758

5859
class AppBecomeActiveAction {
59-
final WebSocketClient ws;
60+
final FletServer server;
6061
final AppBecomeActivePayload payload;
61-
AppBecomeActiveAction(this.ws, this.payload);
62+
AppBecomeActiveAction(this.server, this.payload);
6263
}
6364

6465
class AppBecomeInactiveAction {
@@ -73,8 +74,8 @@ class SessionCrashedAction {
7374

7475
class InvokeMethodAction {
7576
final InvokeMethodPayload payload;
76-
final WebSocketClient ws;
77-
InvokeMethodAction(this.payload, this.ws);
77+
final FletServer server;
78+
InvokeMethodAction(this.payload, this.server);
7879
}
7980

8081
class AddPageControlsAction {

package/lib/src/controls/alert_dialog.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ class _AlertDialogControlState extends State<AlertDialogControl> {
110110
dispatch(UpdateControlPropsAction(
111111
UpdateControlPropsPayload(props: props)));
112112
FletAppServices.of(context)
113-
.ws
113+
.server
114114
.updateControlProps(props: props);
115-
FletAppServices.of(context).ws.pageEventFromWeb(
115+
FletAppServices.of(context).server.sendPageEvent(
116116
eventTarget: widget.control.id,
117117
eventName: "dismiss",
118118
eventData: "");

0 commit comments

Comments
 (0)