Skip to content
Closed
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
13 changes: 12 additions & 1 deletion .github/workflows/linux-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ jobs:
liblzma-dev \
libwebkit2gtk-4.1-dev \
libsecret-1-dev \
libjsoncpp-dev
libjsoncpp-dev \
libjson-glib-dev \
qt6-base-dev \
qt6-declarative-dev

- name: Set up Flutter
uses: subosito/flutter-action@v2
Expand Down Expand Up @@ -131,6 +134,14 @@ jobs:
# platform's artifact, with the file left in whatever shape the build
# produced. The archive holds `bundle/` itself, so it extracts to one
# directory — the runner, its libraries and data/ next to each other.
cmake -S linux/widgets -B build/linux-widgets -DCMAKE_BUILD_TYPE=Release
cmake --build build/linux-widgets --parallel 2
mkdir -p build/linux/x64/release/bundle/widgets
cp assets/icon/icon.png build/linux/x64/release/bundle/techpie.png
cp -R build/linux-widgets/kde linux/widgets/gnome linux/widgets/common \
build/linux/x64/release/bundle/widgets/
cp linux/widgets/install.py \
build/linux/x64/release/bundle/widgets/
mkdir -p dist
tar -czf "dist/TechPie-${RELEASE_NAME}-linux-x86-64.tar.gz" \
-C build/linux/x64/release bundle
Expand Down
38 changes: 34 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'models/third_party_account.dart';
import 'services/assignment_service.dart';
import 'services/auth_service.dart';
import 'services/campus_card_service.dart';
import 'services/deadline_widget_service.dart';
import 'services/debug_logger.dart';
import 'services/ecard_bind_service.dart';
import 'services/ecard_widget_service.dart';
Expand Down Expand Up @@ -60,11 +61,19 @@ void main(List<String> args) async {

Future<void> _realMain(SharedPreferences prefs) async {
final storageService = StorageService(prefs);
configureAppProxy(storageService.appProxyEnabled ? storageService.appProxyUrl : '');
final debugLogger = DebugLogger()..enabled = storageService.debugMode;
final httpClient = LoggingHttpClient(debugLogger);
final uniAuthService = UniAuthService(logger: debugLogger);
final authService =
AuthService(storageService, httpClient, uniAuthService, logger: debugLogger);
final uniAuthService = UniAuthService(
logger: debugLogger,
proxyUrl: storageService.appProxyEnabled ? storageService.appProxyUrl : '',
);
final authService = AuthService(
storageService,
httpClient,
uniAuthService,
logger: debugLogger,
);
final themeService = ThemeService(storageService);
final campusCardService = CampusCardService(debugLogger: debugLogger, storage: storageService);
final ecardBindService = EcardBindService();
Expand Down Expand Up @@ -96,6 +105,9 @@ Future<void> _realMain(SharedPreferences prefs) async {
thirdPartyAuthService,
scheduleService,
);
final deadlineWidgetService = !kIsWeb && defaultTargetPlatform == TargetPlatform.linux
? DeadlineWidgetService(assignmentService, enabled: storageService.deadlineWidgetsEnabled)
: null;
final syncService = SyncService(
authService,
thirdPartyAuthService,
Expand Down Expand Up @@ -181,10 +193,12 @@ Future<void> _realMain(SharedPreferences prefs) async {
campusCardService: campusCardService,
ecardBindService: ecardBindService,
ecardWidgetService: ecardWidgetService,
deadlineWidgetService: deadlineWidgetService,
),
);

bootMark('cached data ready');
deadlineWidgetService?.initialize();

oaGymService.startProfileSync();
unawaited(campusCardService.refreshAccount());
Expand Down Expand Up @@ -309,6 +323,7 @@ class TechPieApp extends StatefulWidget {
final CampusCardService campusCardService;
final EcardBindService ecardBindService;
final EcardWidgetService? ecardWidgetService;
final DeadlineWidgetService? deadlineWidgetService;

const TechPieApp({
super.key,
Expand All @@ -327,6 +342,7 @@ class TechPieApp extends StatefulWidget {
required this.campusCardService,
required this.ecardBindService,
this.ecardWidgetService,
this.deadlineWidgetService,
});

@override
Expand All @@ -350,11 +366,16 @@ class _TechPieAppState extends State<TechPieApp> with WidgetsBindingObserver {
WidgetsBinding.instance.addObserver(this);
unawaited(_checkForUpdatesQuietly());
widget.ecardWidgetService?.setOpenPayHandler(_openEcardPayCode);
widget.deadlineWidgetService?.setOpenHandler(_openDeadlines);
}

@override
void didUpdateWidget(covariant TechPieApp oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.deadlineWidgetService != widget.deadlineWidgetService) {
oldWidget.deadlineWidgetService?.clearOpenHandler();
widget.deadlineWidgetService?.setOpenHandler(_openDeadlines);
}
if (oldWidget.ecardWidgetService == widget.ecardWidgetService) return;
oldWidget.ecardWidgetService?.clearOpenPayHandler();
widget.ecardWidgetService?.setOpenPayHandler(_openEcardPayCode);
Expand All @@ -364,6 +385,7 @@ class _TechPieAppState extends State<TechPieApp> with WidgetsBindingObserver {
void dispose() {
WidgetsBinding.instance.removeObserver(this);
widget.ecardWidgetService?.clearOpenPayHandler();
widget.deadlineWidgetService?.dispose();
widget.campusCardService.dispose();
super.dispose();
}
Expand All @@ -378,6 +400,11 @@ class _TechPieAppState extends State<TechPieApp> with WidgetsBindingObserver {
}
}

Future<void> _openDeadlines() async {
_navigatorKey.currentState?.popUntil((route) => route.isFirst);
appShellPendingDeadlines.value = true;
}

/// The check nobody asked for.
///
/// It may raise the update dialog, and says nothing else: a network the user
Expand All @@ -403,8 +430,10 @@ class _TechPieAppState extends State<TechPieApp> with WidgetsBindingObserver {
}
if (release == null || !mounted) return;

final dialogContext = _navigatorKey.currentState?.overlay?.context;
if (dialogContext == null || !dialogContext.mounted) return;
_promptedThisLaunch = true;
await showUpdateAvailableDialog(context, release);
await showUpdateAvailableDialog(dialogContext, release);
}

Future<void> _openEcardPayCode() async {
Expand Down Expand Up @@ -448,6 +477,7 @@ class _TechPieAppState extends State<TechPieApp> with WidgetsBindingObserver {
campusCardService: widget.campusCardService,
ecardBindService: widget.ecardBindService,
ecardWidgetService: widget.ecardWidgetService,
deadlineWidgetService: widget.deadlineWidgetService,
child: MaterialApp(
navigatorKey: _navigatorKey,
scaffoldMessengerKey: rootMessengerKey,
Expand Down
23 changes: 22 additions & 1 deletion lib/pages/assignments_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import '../widgets/blurred_app_bar.dart';
import '../widgets/ios/ios_native_navigation_bar.dart';
import '../widgets/swipeable_card.dart';
import 'hidden_assignments_page.dart';
import 'third_party_accounts_page.dart';

class AssignmentsPage extends StatefulWidget {
const AssignmentsPage({super.key});
Expand Down Expand Up @@ -415,6 +416,8 @@ class _AssignmentsPageState extends State<AssignmentsPage> {

Widget _emptyState(BuildContext context, AssignmentService service) {
final theme = Theme.of(context);
final hasSources = ServiceProvider.of(context)
.thirdPartyAuthService.boundPlatforms.isNotEmpty;
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
Expand All @@ -425,7 +428,25 @@ class _AssignmentsPageState extends State<AssignmentsPage> {
color: theme.colorScheme.onSurfaceVariant,
),
const SizedBox(height: 16),
Text('No upcoming deadlines', style: theme.textTheme.titleMedium),
Text(
!hasSources ? '连接课程平台以获取Deadlines' : service.loading
? '正在同步截止日期…' : !service.hasCachedData
? '尚未成功同步截止日期' : 'No upcoming deadlines',
style: theme.textTheme.titleMedium,
),
if (!hasSources) ...[
const SizedBox(height: 16),
FilledButton.icon(
icon: const Icon(Icons.link),
label: const Text('连接课程平台'),
onPressed: () => unawaited(
pushAdaptivePage<void>(
context,
builder: (_) => const ThirdPartyAccountsPage(),
),
),
),
],
if (service.error != null) ...[
const SizedBox(height: 8),
Padding(
Expand Down
76 changes: 76 additions & 0 deletions lib/pages/settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ import 'package:package_info_plus/package_info_plus.dart';
import 'package:techpie/services/auth_service.dart';
import 'package:url_launcher/url_launcher.dart';

import '../services/http_client.dart';
import '../services/service_provider.dart';
import '../services/storage_service.dart';
import '../services/sync_service.dart';
import '../services/theme_service.dart';
import '../services/uni_auth_service.dart';
import '../services/update_service.dart';
import '../utils/adaptive_layout.dart';
import '../utils/platform.dart';
Expand Down Expand Up @@ -409,6 +412,20 @@ class _SettingsPageState extends State<SettingsPage> {

// General section
_sectionHeader(theme, 'General'),
if (sp.deadlineWidgetService != null)
_AdaptiveSwitchTile(
usesIosLiquidGlass: useIosChrome,
secondary: const Icon(Icons.widgets_outlined),
title: 'Deadline widgets',
subtitle: 'Share task titles and dates with your desktop. '
'Widgets use cached data while TechPie is closed.',
value: storage.deadlineWidgetsEnabled,
onChanged: (value) async {
await storage.setDeadlineWidgetsEnabled(value);
await sp.deadlineWidgetService!.setEnabled(value);
if (mounted) setState(() {});
},
),
_AdaptiveSwitchTile(
usesIosLiquidGlass: useIosChrome,
secondary: const Icon(Icons.visibility_off_outlined),
Expand All @@ -422,6 +439,28 @@ class _SettingsPageState extends State<SettingsPage> {
});
},
),
ListTile(
leading: const Icon(Icons.lan_outlined),
title: const Text('Application proxy'),
subtitle: Text(
storage.appProxyEnabled && storage.appProxyUrl.isNotEmpty
? storage.appProxyUrl
: 'Disabled',
),
onTap: () => _showProxySettings(storage, sp.uniAuthService),
),
SwitchListTile(
secondary: const Icon(Icons.power_settings_new),
title: const Text('Enable application proxy'),
value: storage.appProxyEnabled,
onChanged: (value) async {
await storage.setAppProxyEnabled(value);
final proxy = value ? storage.appProxyUrl : '';
configureAppProxy(proxy);
sp.uniAuthService.setProxyUrl(proxy);
if (mounted) setState(() {});
},
),
ListTile(
leading: const Icon(Icons.info_outline),
title: const Text('About'),
Expand Down Expand Up @@ -538,6 +577,43 @@ class _SettingsPageState extends State<SettingsPage> {
}
}

Future<void> _showProxySettings(StorageService storage, UniAuthService uniAuth) async {
final controller = TextEditingController(text: storage.appProxyUrl);
final value = await showDialog<String>(
context: context,
builder: (context) => AlertDialog(
title: const Text('Application proxy'),
content: TextField(
controller: controller,
autofocus: true,
decoration: const InputDecoration(hintText: '127.0.0.1:7890'),
keyboardType: TextInputType.url,
),
actions: [
TextButton(onPressed: () => Navigator.pop(context), child: const Text('Cancel')),
FilledButton(onPressed: () => Navigator.pop(context, controller.text.trim()), child: const Text('Save')),
],
),
);
controller.dispose();
if (value == null || !mounted) return;
final proxy = value.trim();
if (proxy.isNotEmpty && !RegExp(r'^[^\s:]+:\d{1,5}$').hasMatch(proxy)) {
await showAdaptiveAlertDialog<void>(
context: context,
title: 'Invalid proxy',
message: 'Use host:port, for example 127.0.0.1:7890.',
actions: const [AdaptiveAlertAction<void>(label: 'OK')],
);
return;
}
await storage.setAppProxyUrl(proxy);
await storage.setAppProxyEnabled(proxy.isNotEmpty);
configureAppProxy(proxy);
uniAuth.setProxyUrl(proxy);
setState(() {});
}

void _showThemePicker(BuildContext context, ThemeService themeService) {
if (usesSidebarLayout(context)) {
showDesktopPopover(
Expand Down
Loading