Skip to content

Commit

Permalink
Add Windows support
Browse files Browse the repository at this point in the history
  • Loading branch information
神楽坂花火 committed Apr 15, 2021
1 parent 2565b14 commit ac57566
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 39 deletions.
5 changes: 5 additions & 0 deletions .idea/dictionaries/KagurazakaHanabi.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions android/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions lib/components/today.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,6 @@ import 'package:flutter/services.dart';
import 'package:flutter_ionicons/flutter_ionicons.dart';
import 'package:http/http.dart' as http;

class Hitokoto {
String source;
String content;

Hitokoto({this.source, this.hitokoto});

Hitokoto.fromJson(Map<String, dynamic> json) {
source = json['source'];
content = json['hitokoto'];
}
}

class TodayComponent extends StatefulWidget {
@override
_TodayComponentState createState() => _TodayComponentState();
Expand Down
16 changes: 16 additions & 0 deletions lib/misc/bean.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,22 @@ class Splash {
static DateTime _parseDateTime(String s) => DateTime.parse(s);
}

@JsonSerializable()
class Hitokoto {
Hitokoto({this.source, this.content});

factory Hitokoto.fromJson(Map<String, dynamic> json) {
return _$HitokotoFromJson(json);
}

String source;

@JsonKey(name: 'hitokoto')
String content;

String toJson() => jsonEncode(_$HitokotoToJson(this));
}

@JsonSerializable()
class Contributor {
Contributor({this.avatar, this.name, this.position, this.url});
Expand Down
12 changes: 12 additions & 0 deletions lib/misc/bean.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/pages/about.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class _AboutPageState extends State<AboutPage> {
member.position,
style: TextStyle(
fontSize: 14,
color: CupertinoDynamicColor.withBrightness(
color: const CupertinoDynamicColor.withBrightness(
color: Colors.black54,
darkColor: Colors.white70,
).resolveFrom(context),
Expand Down Expand Up @@ -187,7 +187,7 @@ class _AboutPageState extends State<AboutPage> {
Widget _buildAppInfo() {
final String version = packageInfo?.version ?? '0.0.0';
final String buildNumber = packageInfo?.buildNumber ?? '190000';
Color textColor = CupertinoDynamicColor.withBrightness(
Color textColor = const CupertinoDynamicColor.withBrightness(
color: Colors.black54,
darkColor: Colors.white70,
).resolveFrom(context);
Expand Down
16 changes: 5 additions & 11 deletions lib/pages/details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import 'package:dailypics/misc/bean.dart';
import 'package:dailypics/model/app.dart';
import 'package:dailypics/utils/api.dart';
import 'package:dailypics/utils/utils.dart';
import 'package:dailypics/utils/wallpaper.dart';
import 'package:dailypics/widget/adaptive_scaffold.dart';
import 'package:dailypics/widget/optimized_image.dart';
import 'package:dailypics/widget/photo_card.dart';
Expand Down Expand Up @@ -223,7 +222,7 @@ class _DetailsPageState extends State<DetailsPage> {
styleSheet: MarkdownStyleSheet(
a: const TextStyle(color: CupertinoColors.link),
p: textStyle.copyWith(
color: CupertinoDynamicColor.withBrightness(
color: const CupertinoDynamicColor.withBrightness(
color: Colors.black54,
darkColor: Colors.white70,
).resolveFrom(context),
Expand Down Expand Up @@ -291,7 +290,7 @@ class _DetailsPageState extends State<DetailsPage> {
}

Widget _buildDivider() {
Color dividerColor = CupertinoDynamicColor.withBrightness(
Color dividerColor = const CupertinoDynamicColor.withBrightness(
color: Colors.black38,
darkColor: Colors.white54,
).resolveFrom(context);
Expand All @@ -312,7 +311,7 @@ class _DetailsPageState extends State<DetailsPage> {
return DefaultTextStyle(
style: TextStyle(
fontSize: 14,
color: CupertinoDynamicColor.withBrightness(
color: const CupertinoDynamicColor.withBrightness(
color: Colors.black45,
darkColor: Colors.white60,
).resolveFrom(context),
Expand All @@ -337,7 +336,7 @@ class _DetailsPageState extends State<DetailsPage> {
}

Widget _buildShareButton() {
Color color = CupertinoDynamicColor.withBrightness(
Color color = const CupertinoDynamicColor.withBrightness(
color: CupertinoColors.systemBlue,
darkColor: Colors.white,
).resolveFrom(context);
Expand Down Expand Up @@ -516,12 +515,7 @@ class _DownloadButtonState extends State<_DownloadButton> {
SystemUtils.openAppSettings();
break;
case _DownloadState.successful:
if (Platform.isAndroid) {
SystemUtils.useAsWallpaper(file);
}
if (Platform.isWindows) {
Wallpaper.set(file);
}
SystemUtils.useAsWallpaper(file);
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class _HomePageState extends State<HomePage> {
}

BottomNavigationBarItem _buildNavigationItem(IconData icon, String title) {
return BottomNavigationBarItem(icon: Icon(icon), title: Text(title));
return BottomNavigationBarItem(icon: Icon(icon), label: title);
}

void _handleUniLink(Uri uri) {
Expand Down
10 changes: 6 additions & 4 deletions lib/pages/upload.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class _UploadPageState extends State<UploadPage> {
String type;
double progress = -1;

ImagePicker picker = ImagePicker();

@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
Expand Down Expand Up @@ -153,9 +155,9 @@ class _UploadPageState extends State<UploadPage> {
}
return GestureDetector(
onTap: () async {
File file = await ImagePicker.pickImage(source: ImageSource.gallery);
PickedFile file = await picker.getImage(source: ImageSource.gallery);
if (file != null) {
setState(() => imageFile = file);
setState(() => imageFile = File(file.path));
}
},
child: AspectRatio(
Expand Down Expand Up @@ -240,12 +242,12 @@ class _UploadPageState extends State<UploadPage> {
children: <Widget>[
CupertinoButton(
padding: EdgeInsets.zero,
child: Icon(Ionicons.ios_arrow_up),
child: const Icon(Ionicons.ios_arrow_up),
onPressed: () => FocusScope.of(context).previousFocus(),
),
CupertinoButton(
padding: EdgeInsets.zero,
child: Icon(Ionicons.ios_arrow_down),
child: const Icon(Ionicons.ios_arrow_down),
onPressed: () => FocusScope.of(context).nextFocus(),
),
Expanded(child: Container()),
Expand Down
4 changes: 3 additions & 1 deletion lib/pages/user_space.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class _UserSpacePageState extends State<UserSpacePage> {
ScrollController controller = ScrollController();
ScrollPosition position;

ImagePicker picker = ImagePicker();

@override
void initState() {
super.initState();
Expand Down Expand Up @@ -246,7 +248,7 @@ class _UserSpacePageState extends State<UserSpacePage> {
CupertinoActionSheetAction(
child: const Text('从相册选择'),
onPressed: () async => Navigator.of(context).pop(
await ImagePicker.pickImage(source: ImageSource.gallery),
await picker.getImage(source: ImageSource.gallery),
),
),
],
Expand Down
10 changes: 9 additions & 1 deletion lib/utils/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import 'dart:io';

import 'package:dailypics/misc/bean.dart';
import 'package:dailypics/utils/http.dart';
import 'package:dailypics/utils/windows.dart';
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';
Expand All @@ -39,7 +40,14 @@ class SystemUtils {
}

static Future<void> useAsWallpaper(File file) async {
await _channel.invokeMethod('useAsWallpaper', file.path);
switch (Platform.operatingSystem) {
case "android":
await _channel.invokeMethod('useAsWallpaper', file.path);
break;
case "windows":
Windows.useAsWallpaper(file);
break;
}
}

static Future<void> useAsWallpaperForWindows(File file) async {
Expand Down
6 changes: 3 additions & 3 deletions lib/utils/wallpaper.dart → lib/utils/windows.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import 'dart:io';
import 'package:ffi/ffi.dart';
import 'package:win32/win32.dart';

class Wallpaper {
static void set(File wallpaperFile) {
class Windows {
static void useAsWallpaper(File wallpaperFile) {
final hr = CoInitializeEx(
nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
if (FAILED(hr)) throw WindowsException(hr);
Expand All @@ -21,4 +21,4 @@ class Wallpaper {

CoUninitialize();
}
}
}
2 changes: 1 addition & 1 deletion lib/widget/error.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CustomErrorWidget extends StatelessWidget {
child: Text(
details.exceptionAsString(),
style: TextStyle(
color: CupertinoDynamicColor.withBrightness(
color: const CupertinoDynamicColor.withBrightness(
color: Colors.black54,
darkColor: Colors.white70,
).resolveFrom(context),
Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ packages:
description:
path: "."
ref: HEAD
resolved-ref: "055cc1942a142a40c3fafbc6e970cc5ecb682683"
resolved-ref: e3fb9a4b950b8006fea393561c14b1b695ca59bd
url: "https://github.com/KagurazakaHanabi/flutter_markdown.git"
source: git
version: "0.3.2"
Expand Down Expand Up @@ -797,4 +797,4 @@ packages:
version: "3.1.0"
sdks:
dart: ">=2.12.0 <3.0.0"
flutter: ">=1.24.0-10"
flutter: ">=2.0.0"
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name: dailypics
description: A new Flutter application.
version: 2.2.7+200325
publish_to: none

environment:
sdk: ">=2.6.0 <3.0.0"
flutter: ">=1.12.13 <2.0.0"
flutter: ">=2.0.0 <3.0.0"

dependencies:
flutter:
Expand Down

0 comments on commit ac57566

Please sign in to comment.