Skip to content
This repository has been archived by the owner on Mar 21, 2023. It is now read-only.

feat: add support for web #36

Merged
merged 5 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ jobs:
with:
name: eludris-windows
path: ./build/windows/runner/Release/

build-ubuntu:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -119,3 +118,38 @@ jobs:
with:
name: eludris-linux
path: ./build/linux/x64/release/bundle
build-web:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install dependencies
run: |
sudo apt-get install \
cmake \
clang \
ninja-build \
libgtk-3-dev \
liblzma-dev

- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
cache: true
cache-key: 'flutter-:os:-:channel:-:version:-:arch:-:hash:'
cache-path: '${{ runner.tool_cache }}/flutter/:channel:-:version:-:arch:'

- name: Cache Flutter Dependencies
id: cache-flutter-dependencies
uses: actions/cache@v2
with:
path: ${{ env.PUB_CACHE }}
key: ${{ runner.os }}-${{ hashFiles('**/pubspec.lock') }}-pub-cache-web

- name: Install Packages
if: steps.cache-flutter-dependencies.outputs.cache-hit != 'true'
run: flutter pub get

- name: Build Web Files
run: flutter build web
93 changes: 46 additions & 47 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,47 +1,46 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
/build/

# Web related
lib/generated_plugin_registrant.dart

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json

# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
/build/

# Web related

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json

# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release
14 changes: 7 additions & 7 deletions .metadata
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
# This file should be version controlled.

version:
revision: c07af53b3cb2182d7735f022969efb00f2ddbd27
channel: master
revision: 18a827f3933c19f51862dde3fa472197683249d6
channel: stable

project_type: app

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: c07af53b3cb2182d7735f022969efb00f2ddbd27
base_revision: c07af53b3cb2182d7735f022969efb00f2ddbd27
- platform: linux
create_revision: c07af53b3cb2182d7735f022969efb00f2ddbd27
base_revision: c07af53b3cb2182d7735f022969efb00f2ddbd27
create_revision: 18a827f3933c19f51862dde3fa472197683249d6
base_revision: 18a827f3933c19f51862dde3fa472197683249d6
- platform: web
create_revision: 18a827f3933c19f51862dde3fa472197683249d6
base_revision: 18a827f3933c19f51862dde3fa472197683249d6

# User provided section

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ A cross-platform Eludris client with full feature support.

| Windows | Linux | Android | Web | IOS | MacOS |
|---------|-------|---------|-----------|------------|----------------------------------|
| ✅ | ✅ | ✅ | 🟧 Planned | 🟥 Unknown | 🟨 Compilable (but not supported) |
| ✅ | ✅ | ✅ | | 🟥 Unknown | 🟨 Compilable (but not supported) |
5 changes: 5 additions & 0 deletions build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
targets:
web:
sources:
exclude:
- lib/lua/*
16 changes: 16 additions & 0 deletions lib/lua/web.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:flutter/cupertino.dart';

class PluginManager {
final List<dynamic> plugins = [];

dynamic loadPlugins() {}
}

class Plugins extends StatelessWidget {
const Plugins({super.key});

@override
Widget build(BuildContext context) {
return const Text('Plugins are not supported on the web.');
}
}
8 changes: 6 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:eludris/common.dart';
import 'package:eludris/lua/manager.dart';
import 'package:eludris/lua/manager.dart'
if (dart.library.html) 'package:eludris/lua/web.dart';
import 'package:eludris/routes/home.dart';
import 'package:eludris/routes/settings.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:yaru/yaru.dart';
Expand All @@ -10,7 +12,9 @@ import 'package:get_it/get_it.dart';
final getIt = GetIt.instance;

Future<void> main() async {
getIt.registerSingleton<PluginManager>(PluginManager());
if (!kIsWeb) {
getIt.registerSingleton<PluginManager>(PluginManager());
}
getIt.registerSingleton<APIConfig>(APIConfig());
getIt.registerSingleton<SharedPreferences>(
await SharedPreferences.getInstance());
Expand Down
89 changes: 54 additions & 35 deletions lib/routes/loggedin.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:websocket_universal/websocket_universal.dart';

import 'package:eludris/common.dart';
import 'package:eludris/lua/manager.dart';
import 'package:eludris/lua/manager.dart'
if (dart.library.html) 'package:eludris/lua/web.dart';
import 'package:eludris/models/gateway/message.dart';
import 'package:eludris/widgets/message.dart';
import 'package:file_picker/file_picker.dart';
import 'package:get_it/get_it.dart';
import 'package:http/http.dart' show post, MultipartRequest, MultipartFile;
import 'package:http/http.dart' show MultipartRequest, MultipartFile, Request;
import 'package:flutter/material.dart';
import 'package:yaru/yaru.dart';

Expand Down Expand Up @@ -50,15 +53,17 @@ class _LoggedInState extends State<LoggedIn> {
final FocusNode _focusNode = FocusNode();
final _scrollController = ScrollController();

IWebSocketHandler<String, String>? _textSocketHandler;
bool _textEnabled = true;

get _config => getIt<APIConfig>();
APIConfig get _config => getIt<APIConfig>();

@override
void dispose() {
// Clean up the controller when the widget is disposed.
_textController.dispose();
_scrollController.dispose();
_textSocketHandler?.close();
_stream?.cancel();
super.dispose();
}
Expand All @@ -68,37 +73,46 @@ class _LoggedInState extends State<LoggedIn> {
_textController.clear();

final message = MessageData(widget.name, text, true);
for (final plugin in getIt<PluginManager>().plugins) {
final messages =
plugin.runPreSendMessage(http: _config.httpUrl, message: message);
setState(() {
_messages.addAll(messages);
});
if (!kIsWeb) {
for (final plugin in getIt<PluginManager>().plugins) {
final messages =
plugin.runPreSendMessage(http: _config.httpUrl, message: message);
setState(() {
_messages.addAll(messages);
});
}
}

setState(() {
_messages.add(message);
});
await post(
Uri.parse('${_config.httpUrl}/messages'),
body: jsonEncode({

Request("POST", Uri.parse(_config.httpUrl + '/messages'))
..body = jsonEncode({
'author': message.author,
'content': message.content,
}),
headers: {
'Content-Type': 'application/json',
},
);
})
..send();
}

_initState() async {
final config = getIt<APIConfig>();
const connectionOptions = SocketConnectionOptions(
pingIntervalMs: 10000,
);

final ws = await WebSocket.connect(config.wsUrl);
ws.pingInterval = const Duration(seconds: 10);
getIt<PluginManager>().loadPlugins();
final IMessageProcessor<String, String> textSocketProcessor =
SocketSimpleTextProcessor();
final textSocketHandler = IWebSocketHandler<String, String>.createClient(
_config.wsUrl, // Postman echo ws server
textSocketProcessor,
connectionOptions: connectionOptions,
);

_stream = ws.listen(_wsListen);
if (!kIsWeb) {
getIt<PluginManager>().loadPlugins();
}
_stream = textSocketHandler.incomingMessagesStream.listen(_wsListen);
await textSocketHandler.connect();
}

void _wsListen(event) {
Expand All @@ -119,14 +133,16 @@ class _LoggedInState extends State<LoggedIn> {
}
});

for (final plugin in getIt<PluginManager>().plugins) {
if (plugin.hooks.contains('postGotMessage') &&
plugin.manifest.permissions.contains('READ_MESSAGES')) {
final pMessages =
plugin.runPostGotMessage(http: _config.httpUrl, message: message);
setState(() {
_messages.addAll(pMessages);
});
if (!kIsWeb) {
for (final plugin in getIt<PluginManager>().plugins) {
if (plugin.hooks.contains('postGotMessage') &&
plugin.manifest.permissions.contains('READ_MESSAGES')) {
final pMessages =
plugin.runPostGotMessage(http: _config.httpUrl, message: message);
setState(() {
_messages.addAll(pMessages);
});
}
}
}
}
Expand Down Expand Up @@ -192,13 +208,16 @@ class _LoggedInState extends State<LoggedIn> {
setState(() {
_textEnabled = false;
});
final file = File(files.files.single.path!);
final file = files.files.first;

final request = MultipartRequest("POST",
Uri.parse("${_config.effisUrl}/upload"));
request.fields['name'] = file.path.split('/').last;
request.files.add(await MultipartFile.fromPath(
'file', file.path));
request.fields['name'] = file.name;
request.files.add(MultipartFile.fromBytes(
'file',
file.bytes!,
filename: file.name,
));

final result = await request.send();
final data = await result.stream.bytesToString();
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/plugins.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:eludris/common.dart';
import 'package:eludris/lua/manager.dart';
import 'package:eludris/lua/manager.dart'
if (dart.library.html) 'package:eludris/lua/web.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
Expand Down
Loading