Skip to content

Commit

Permalink
Improve UI and startup launch
Browse files Browse the repository at this point in the history
  • Loading branch information
Vonarian committed Mar 16, 2022
1 parent a080835 commit c3f6af2
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 34 deletions.
3 changes: 1 addition & 2 deletions assets/install/installer.bat
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ SET MNIST_DIR=%CD%
taskkill /F /IM wtnews.exe
powershell.exe Add-AppPackage -Path '%MNIST_DIR%\out\WTNews.msix'
@echo Installation process complete

timeout 10
timeout 3
2 changes: 1 addition & 1 deletion assets/install/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.0.0
1.2.5.0
11 changes: 11 additions & 0 deletions assets/manifest/updateShortcut.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@echo off
SET currentDirectory=%~dp0
PUSHD %currentDirectory%
CD ..
CD ..
CD ..
CD ..
SET MNIST_DIR=%CD%
echo %MNIST_DIR%
SET appExeDir=%MNIST_DIR%
powershell "$s=(New-Object -COM WScript.Shell).CreateShortcut('%userprofile%\Start Menu\Programs\Startup\WTNews.lnk');$s.TargetPath='%appExeDir%\wtnews.exe';$s.Arguments='connect';$s.IconLocation='%appExeDir%\wtnews.exe';$s.WorkingDirectory='%appExeDir%';$s.WindowStyle=7;$s.Save()"
11 changes: 9 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:local_notifier/local_notifier.dart';
import 'package:path/path.dart' as p;
import 'package:shared_preferences/shared_preferences.dart';
import 'package:win32/win32.dart';
import 'package:window_manager/window_manager.dart';
import 'package:wtnews/pages/loading.dart';
Expand All @@ -11,14 +13,19 @@ final StateProvider<bool> isStartupEnabled = StateProvider((ref) => false);
final StateProvider<bool> playSound = StateProvider((ref) => true);

final localNotifier = LocalNotifier.instance;

String pathToUpdateShortcut =
'${p.dirname(Platform.resolvedExecutable)}/data/flutter_assets/assets/manifest/updateShortcut.bat';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await windowManager.ensureInitialized();
SharedPreferences prefs = await SharedPreferences.getInstance();
bool isStartupEnabled = prefs.getBool('startup') ?? false;
if (isStartupEnabled) {
await Process.run(pathToUpdateShortcut, []);
}
windowManager.waitUntilReadyToShow().then((_) async {
await windowManager.setTitleBarStyle('hidden');
await windowManager.setResizable(true);
await windowManager.setAspectRatio(1.777);
await windowManager.show();
});
runApp(const ProviderScope(
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/downloader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class _DownloaderState extends State<Downloader>
'install',
'installer.bat'
]));
await Process.run(installer, [], runInShell: true);
await Process.run(installer, []);
}).timeout(const Duration(minutes: 8));
} catch (e, st) {
String path = await AppUtil.createFolderInAppDocDir(errorLogPath);
Expand Down
23 changes: 19 additions & 4 deletions lib/pages/loading.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,28 @@ class _LoadingState extends State<Loading> {
body: Stack(
children: [
ImageFiltered(
child: Image.asset(
'assets/bg.png',
fit: BoxFit.cover,
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topRight,
end: Alignment.bottomLeft,
colors: [
Colors.black,
Colors.black,
Colors.black,
Colors.black87,
Colors.black87,
Colors.black87,
Colors.black87,
Colors.black,
Colors.black,
Colors.black,
],
)),
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
),
imageFilter: ImageFilter.blur(sigmaX: 7.0, sigmaY: 7.0)),
imageFilter: ImageFilter.blur(sigmaX: 14.0, sigmaY: 14.0)),
const Center(
child: SizedBox(
width: 150,
Expand Down
27 changes: 22 additions & 5 deletions lib/pages/rss_feed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,31 @@ class _RSSViewState extends ConsumerState<RSSView> {
body: Stack(
children: [
ImageFiltered(
child: Image.asset(
'assets/bg.png',
fit: BoxFit.cover,
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topRight,
end: Alignment.bottomLeft,
colors: [
Colors.black,
Colors.black,
Colors.black,
Colors.black87,
Colors.black87,
Colors.black87,
Colors.black87,
Colors.black,
Colors.black,
Colors.black,
],
)),
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
),
imageFilter: ImageFilter.blur(sigmaX: 14.0, sigmaY: 14.0)),
rssFeed != null
? Padding(
padding: const EdgeInsets.fromLTRB(0, 30, 0, 0),
padding: const EdgeInsets.fromLTRB(0, 45, 0, 0),
child: ListView.builder(
itemCount: rssFeed?.items?.length,
itemBuilder: (context, index) {
Expand Down Expand Up @@ -180,7 +195,9 @@ class _RSSViewState extends ConsumerState<RSSView> {
.replaceAll(' ', '') ??
'',
overflow: TextOverflow.ellipsis,
style: const TextStyle(color: Colors.white),
style: const TextStyle(
color: Colors.white,
),
),
onTap: () async {
await launch(
Expand Down
26 changes: 22 additions & 4 deletions lib/pages/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class _SettingsState extends ConsumerState<Settings> {
SharedPreferences prefs = await SharedPreferences.getInstance();
ref.read(isStartupEnabled.notifier).state =
prefs.getBool('startup') ?? false;
if (ref.read(isStartupEnabled.notifier).state) {
await Process.run(pathToUpdateShortcut, []);
}
ref.read(playSound.notifier).state = prefs.getBool('playSound') ?? false;
});
}
Expand All @@ -37,13 +40,28 @@ class _SettingsState extends ConsumerState<Settings> {
child: Stack(
children: [
ImageFiltered(
child: Image.asset(
'assets/bg.png',
fit: BoxFit.cover,
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topRight,
end: Alignment.bottomLeft,
colors: [
Colors.black,
Colors.black,
Colors.black,
Colors.black87,
Colors.black87,
Colors.black87,
Colors.black87,
Colors.black,
Colors.black,
Colors.black,
],
)),
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
),
imageFilter: ImageFilter.blur(sigmaX: 7.0, sigmaY: 7.0)),
imageFilter: ImageFilter.blur(sigmaX: 14.0, sigmaY: 14.0)),
Scaffold(
appBar: AppBar(
backgroundColor: Colors.transparent,
Expand Down
36 changes: 22 additions & 14 deletions lib/widgets/titlebar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ class _WindowTitleBarState extends ConsumerState<WindowTitleBar>
);
},
child: Container(
alignment: Alignment.center,
width: 15,
height: 15,
margin: const EdgeInsets.fromLTRB(12, 4, 12, 12),
margin: const EdgeInsets.fromLTRB(12, 2, 12, 12),
child: const Icon(Icons.settings, color: Colors.green),
),
hoverColor: Colors.green,
),
InkWell(
onTap: () {
Expand All @@ -86,22 +88,28 @@ class _WindowTitleBarState extends ConsumerState<WindowTitleBar>
child: Container(
width: 15,
height: 15,
margin: const EdgeInsets.fromLTRB(12, 0, 12, 18),
child: const Icon(Icons.minimize_rounded, color: Colors.blue),
margin: const EdgeInsets.fromLTRB(12, 0, 10, 25.5),
child: const Icon(Icons.minimize_outlined, color: Colors.blue),
),
hoverColor: Colors.blue,
),
InkWell(
onTap: () {
windowManager.close();
exit(0);
},
child: Container(
width: 15,
height: 15,
margin: const EdgeInsets.all(12),
child: const Icon(Icons.close, color: Colors.red),
),
),
onTap: () {
windowManager.close();
exit(0);
},
child: Container(
alignment: Alignment.center,
width: 15,
height: 15,
margin: const EdgeInsets.fromLTRB(12, 0, 14, 12),
child: const Icon(
Icons.close,
color: Colors.red,
size: 25,
),
),
hoverColor: Colors.red),
],
),
),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ flutter:

# To add assets to your application, add an assets section, like this:
assets:
- assets/bg.png
- assets/install/installer.bat
- assets/install/version.txt
- assets/app_icon.ico
- assets/sound/new.wav
- assets/manifest/addShortcut.bat
- assets/manifest/removeShortcut.bat
- assets/manifest/updateShortcut.bat
# - images/a_dot_ham.jpeg

# An image asset can refer to one or more resolution-specific "variants", see
Expand Down

0 comments on commit c3f6af2

Please sign in to comment.