Skip to content

Commit

Permalink
:feat: Added the function of recording the last usage configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgnefz committed Jun 6, 2023
1 parent 81fa23b commit 287cb2f
Show file tree
Hide file tree
Showing 19 changed files with 291 additions and 80 deletions.
17 changes: 13 additions & 4 deletions README-EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ OncePower is a tool for batch renaming files or folders. It integrates installat
This software supports English, in order to be lazy so use the Chinese interface of the demo gif.

## New features
Recording the last usage configuration

The retention mode can be named with a date, and the specified length can be truncated when naming the date.

Expand All @@ -20,8 +21,8 @@ Custom prefix and suffix start number
## Platform Support

- **Windows**
- **macOS**Need to pack yourself
- **Linux**
- **macOS** (Need to pack yourself)
- **Linux** (Pause packaging, pack or leave a message if needed)

## Quick Start

Expand Down Expand Up @@ -133,15 +134,23 @@ This project has only been tested in Win10 and Ubuntu. macOS needs to test itsel

Because use the [flutter_distributor](https://distributor.leanflutter.org/zh/docs/getting-started), packaging configuration file has been configured. If you want to pack, execute the following commands:

```
```shell
dart pub global activate flutter_distributor
```

**Ubuntu**

```shell
flutter_distributor package --platform linux --targets deb
```

**macOS**

```shell
npm install -g appdmg
```

```
```shell
flutter_distributor package --platform macos --targets dmg
```

Expand Down
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
OncePower 是一个批量重命名文件或文件夹的工具。集免安装、傻瓜式、快速上手于一身,功能清晰明了,学习成本低。

## 新功能
记录上一次的使用配置

保留模式可以以日期命名,并且日期命名时可以截取指定长度。

Expand All @@ -19,7 +20,7 @@ OncePower 是一个批量重命名文件或文件夹的工具。集免安装、

- **Windows**
- **macOS**(需要自己打包)
- **Linux**
- **Linux**(暂停打包,需要的自己打包或留言)

## 快速上手

Expand Down Expand Up @@ -131,15 +132,23 @@ April

因为使用了 [flutter_distributor](https://distributor.leanflutter.org/zh/docs/getting-started),打包的配置文件已经配置好了。想打包的要依次执行一下命令:

```
```shell
dart pub global activate flutter_distributor
```

**Ubuntu**

```shell
flutter_distributor package --platform linux --targets deb
```

**macOS**

```shell
npm install -g appdmg
```

```
```shell
flutter_distributor package --platform macos --targets dmg
```

Expand Down
9 changes: 5 additions & 4 deletions lib/language.dart → lib/config/language.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:once_power/model/values.dart';
import 'package:once_power/provider/other.dart';
import 'package:once_power/utils/storage.dart';
import 'package:provider/provider.dart';

import 'generated/l10n.dart';
import 'model/types.dart';
import '../generated/l10n.dart';
import '../model/types.dart';

class LanguageManager {
static Iterable<LocalizationsDelegate<dynamic>>? localizationsDelegates =
Expand All @@ -22,8 +23,8 @@ class LanguageManager {

static localeResolutionCallback(
BuildContext context, locale, supportedLocales) {
if (StorageUtil().getString('language') != null) {
if (StorageUtil().getString('language') == 'zh') {
if (StorageUtil().getString(AppValue.language) != null) {
if (StorageUtil().getString(AppValue.language) == 'zh') {
context.watch<OtherProvider>().toggleLanguage(LanguageType.chinese);
return const Locale('zh', 'CN');
}
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions lib/generated/intl/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class MessageLookup extends MessageLookupByLibrary {
MessageLookupByLibrary.simpleMessage("Rename Succeeded"),
"renameSucceededText": m1,
"reservedMode": MessageLookupByLibrary.simpleMessage("Reserved Mode"),
"save": MessageLookupByLibrary.simpleMessage("Save Config"),
"selectFile": MessageLookupByLibrary.simpleMessage("Select File"),
"selectFolder": MessageLookupByLibrary.simpleMessage("Select Folder"),
"setting": MessageLookupByLibrary.simpleMessage("Setting"),
Expand Down
1 change: 1 addition & 0 deletions lib/generated/intl/messages_zh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class MessageLookup extends MessageLookupByLibrary {
"renameSucceeded": MessageLookupByLibrary.simpleMessage("重命名成功"),
"renameSucceededText": m1,
"reservedMode": MessageLookupByLibrary.simpleMessage("保留模式"),
"save": MessageLookupByLibrary.simpleMessage("保存配置"),
"selectFile": MessageLookupByLibrary.simpleMessage("选择文件"),
"selectFolder": MessageLookupByLibrary.simpleMessage("选择文件夹"),
"setting": MessageLookupByLibrary.simpleMessage("设置"),
Expand Down
10 changes: 10 additions & 0 deletions lib/generated/l10n.dart

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

66 changes: 66 additions & 0 deletions lib/global.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import 'package:flutter/material.dart';
import 'package:once_power/model/types.dart';
import 'package:once_power/model/values.dart';
import 'package:once_power/utils/package_info.dart';
import 'package:once_power/utils/storage.dart';
import 'package:window_manager/window_manager.dart';

class Global {
static late bool save;
static ModeType? modeType;
static bool? caseSensitive;
static bool? dateRename;
static bool? exchangeSeat;
static bool? appendMode;
static bool? addFolder;
// static bool? lowercase;
// static bool? capital;
// static bool? digit;
// static bool? nonLetter;
// static bool? punctuation;
static bool? deleteLength;
static String? dateLength;
static String? prefixNum;
static String? suffixNum;
static String? startNum;

static Future init() async {
WidgetsFlutterBinding.ensureInitialized();
await windowManager.ensureInitialized();
await StorageUtil.init();
await PackageDesc.init();

WindowOptions options = const WindowOptions(
size: Size(1000, 600),
minimumSize: Size(1000, 600),
center: true,
title: 'OncePower',
);

windowManager.waitUntilReadyToShow(options, () async {
await windowManager.show();
await windowManager.focus();
});

save = StorageUtil().getBool(AppValue.save) ?? false;
if (save) {
int? index = StorageUtil().getInt(AppValue.modeType);
if (index != null) modeType = ModeType.values[index];
caseSensitive = StorageUtil().getBool(AppValue.caseSensitive);
dateRename = StorageUtil().getBool(AppValue.dateRename);
exchangeSeat = StorageUtil().getBool(AppValue.exchangeSeat);
appendMode = StorageUtil().getBool(AppValue.appendMode);
addFolder = StorageUtil().getBool(AppValue.addFolder);
// lowercase = StorageUtil().getBool(AppValue.lowercase);
// capital = StorageUtil().getBool(AppValue.capital);
// digit = StorageUtil().getBool(AppValue.digit);
// nonLetter = StorageUtil().getBool(AppValue.nonLetter);
// punctuation = StorageUtil().getBool(AppValue.punctuation);
deleteLength = StorageUtil().getBool(AppValue.deleteLength);
dateLength = StorageUtil().getString(AppValue.dateLength);
prefixNum = StorageUtil().getString(AppValue.prefixNum);
suffixNum = StorageUtil().getString(AppValue.suffixNum);
startNum = StorageUtil().getString(AppValue.startNum);
}
}
}
3 changes: 2 additions & 1 deletion lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,6 @@
"exifDate": "Exif Date",
"earliestDate": "Earliest Date",
"latestDate": "Latest Date",
"digits": "digits"
"digits": "digits",
"save": "Save Config"
}
3 changes: 2 additions & 1 deletion lib/l10n/intl_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,6 @@
"exifDate": "拍摄日期",
"earliestDate": "最早日期",
"latestDate": "最晚日期",
"digits": "位数"
"digits": "位数",
"save": "保存配置"
}
25 changes: 4 additions & 21 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,33 +1,16 @@
import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart';
import 'package:once_power/language.dart';
import 'package:once_power/config/language.dart';
import 'package:once_power/config/theme.dart';
import 'package:once_power/global.dart';
import 'package:once_power/pages/home/home.dart';
import 'package:once_power/provider/organize_file.dart';
import 'package:once_power/provider/other.dart';
import 'package:once_power/provider/rename.dart';
import 'package:once_power/theme.dart';
import 'package:once_power/utils/package_info.dart';
import 'package:once_power/utils/storage.dart';
import 'package:provider/provider.dart';
import 'package:window_manager/window_manager.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();
await windowManager.ensureInitialized();
await StorageUtil.init();
await PackageDesc.init();

WindowOptions options = const WindowOptions(
size: Size(1000, 600),
minimumSize: Size(1000, 600),
center: true,
title: 'OncePower',
);

windowManager.waitUntilReadyToShow(options, () async {
await windowManager.show();
await windowManager.focus();
});
await Global.init();
runApp(const MyApp());
}

Expand Down
20 changes: 20 additions & 0 deletions lib/model/values.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class AppValue {
static String language = 'language';
static String save = 'save';
static String modeType = 'modeType';
static String caseSensitive = 'caseSensitive';
static String dateRename = 'dateRename';
static String exchangeSeat = 'exchangeSeat';
static String appendMode = 'appendMode';
static String addFolder = 'addFolder';
// static String lowercase = 'lowercase';
// static String capital = 'capital';
// static String digit = 'digit';
// static String nonLetter = 'nonLetter';
// static String punctuation = 'punctuation';
static String deleteLength = 'deleteLength';
static String dateLength = 'dateLength';
static String prefixNum = 'prefixNum';
static String suffixNum = 'suffixNum';
static String startNum = 'startNum';
}
11 changes: 11 additions & 0 deletions lib/pages/other/setting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ class SettingMenu extends StatelessWidget {
title: S.of(context).about,
action: [MyText(S.of(context).desc)],
),
SettingItem(
title: S.of(context).save,
action: [
Transform.scale(
scale: .8,
child: Switch(
value: provider.save,
onChanged: (v) => provider.toggleSave()),
)
],
),
SettingItem(
title: S.of(context).projectUrl,
crossAxisAlignment: CrossAxisAlignment.start,
Expand Down
30 changes: 28 additions & 2 deletions lib/provider/other.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import 'dart:convert';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:once_power/generated/l10n.dart';
import 'package:once_power/global.dart';
import 'package:once_power/model/types.dart';
import 'package:once_power/model/values.dart';
import 'package:once_power/model/version.dart';
import 'package:once_power/utils/notification.dart';
import 'package:once_power/utils/storage.dart';
Expand Down Expand Up @@ -33,14 +35,38 @@ class OtherProvider extends ChangeNotifier {
_currentLanguage = type;
if (type == LanguageType.english) {
S.load(const Locale('en', 'US'));
await StorageUtil().setString('language', 'en');
await StorageUtil().setString(AppValue.language, 'en');
} else {
S.load(const Locale('zh', 'CN'));
await StorageUtil().setString('language', 'zh');
await StorageUtil().setString(AppValue.language, 'zh');
}
notifyListeners();
}

bool _save = Global.save;
bool get save => _save;
toggleSave() async {
_save = !_save;
// if (!_save) {
// StorageUtil().remove(AppValue.caseSensitive);
// StorageUtil().remove(AppValue.dateRename);
// StorageUtil().remove(AppValue.exchangeSeat);
// StorageUtil().remove(AppValue.appendMode);
// StorageUtil().remove(AppValue.addFolder);
// StorageUtil().remove(AppValue.lowercase);
// StorageUtil().remove(AppValue.capital);
// StorageUtil().remove(AppValue.digit);
// StorageUtil().remove(AppValue.nonLetter);
// StorageUtil().remove(AppValue.punctuation);
// StorageUtil().remove(AppValue.deleteLength);
// StorageUtil().remove(AppValue.prefixNum);
// StorageUtil().remove(AppValue.suffixNum);
// StorageUtil().remove(AppValue.startNum);
// }
await StorageUtil().setBool(AppValue.save, _save);
notifyListeners();
}

bool? _detect;
bool? get detect => _detect;

Expand Down
Loading

0 comments on commit 287cb2f

Please sign in to comment.