Skip to content

Commit 3e9eb6e

Browse files
committed
feat: プログレスログのデバッグ出力をコメントアウト
1 parent 7100cf8 commit 3e9eb6e

File tree

2 files changed

+64
-34
lines changed

2 files changed

+64
-34
lines changed

lib/services/enhanced_update_service.dart

Lines changed: 62 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -82,22 +82,22 @@ class EnhancedUpdateService {
8282
}
8383
/// プログレス更新
8484
void _updateProgress(UpdateProgress progress) {
85-
developer.log(
86-
'Progress Update: ${progress.status} - ${progress.formattedProgress}',
87-
name: 'EnhancedUpdateService'
88-
);
85+
// developer.log(
86+
// 'Progress Update: ${progress.status} - ${progress.formattedProgress}',
87+
// name: 'EnhancedUpdateService'
88+
// );
8989

9090
if (_progressController != null && !_progressController!.isClosed) {
9191
_progressController!.add(progress);
92-
developer.log('Progress sent to stream successfully', name: 'EnhancedUpdateService');
92+
// developer.log('Progress sent to stream successfully', name: 'EnhancedUpdateService');
9393
} else {
9494
developer.log('Warning: Progress controller is null or closed', name: 'EnhancedUpdateService');
9595
// 緊急時はStreamControllerを再初期化
9696
if (_progressController == null) {
9797
initializeProgressStream();
9898
if (_progressController != null && !_progressController!.isClosed) {
9999
_progressController!.add(progress);
100-
developer.log('Progress sent after emergency re-initialization', name: 'EnhancedUpdateService');
100+
// developer.log('Progress sent after emergency re-initialization', name: 'EnhancedUpdateService');
101101
}
102102
}
103103
}
@@ -288,30 +288,27 @@ class EnhancedUpdateService {
288288
initializeProgressStream();
289289
}
290290

291-
_resetDownloadState(); // ダウンロード開始前に状態をリセット
291+
_resetDownloadState();
292292

293293
_updateProgress(UpdateProgress(
294294
progress: 0.0,
295295
status: 'ダウンロード準備中...',
296296
));
297297

298298
final client = http.Client();
299-
// http.StreamedResponse? response; // Removed as it's declared later
300-
// StreamSubscription? subscription; // Removed as await for is used
301-
// final fileBytes = <int>[]; // Removed as data is written directly to sink
302299
String? filePath;
303300

304301
try {
305302
final request = http.Request('GET', Uri.parse(releaseInfo.downloadUrl!));
306-
final http.StreamedResponse response = await client.send(request); // Ensure response is typed
303+
final http.StreamedResponse response = await client.send(request);
307304

308305
if (response.statusCode != 200) {
309306
_updateProgress(UpdateProgress(
310307
progress: 0.0,
311308
status: 'ダウンロードエラー: ${response.statusCode}',
312309
errorMessage: 'HTTP ${response.statusCode}: ${response.reasonPhrase}',
313310
));
314-
client.close(); // Close client on error
311+
client.close();
315312
return null;
316313
}
317314

@@ -335,19 +332,19 @@ class EnhancedUpdateService {
335332
if (_cancelDownload) {
336333
developer.log('Download cancelled by user.', name: 'EnhancedUpdateService');
337334
_updateProgress(UpdateProgress(
338-
progress: totalBytes > 0 ? downloadedBytes / totalBytes : 0.0, // キャンセル時点の進捗
335+
progress: totalBytes > 0 ? downloadedBytes / totalBytes : 0.0,
339336
status: 'ダウンロードがキャンセルされました',
340337
bytesDownloaded: downloadedBytes,
341338
totalBytes: totalBytes,
342339
errorMessage: 'User cancelled download',
343340
));
344341
await sink.close();
345-
if (await file.exists()) { // Check if file exists before deleting
342+
if (await file.exists()) {
346343
await file.delete();
347344
}
348345
filePath = null;
349-
client.close(); // Close client on cancellation
350-
return null; // Return null as download was cancelled
346+
client.close();
347+
return null;
351348
}
352349

353350
sink.add(chunk);
@@ -384,15 +381,13 @@ class EnhancedUpdateService {
384381
await sink.close();
385382

386383
if (_cancelDownload) {
387-
// This case should ideally be handled within the loop, but as a safeguard:
388-
if (filePath != null && await File(filePath).exists()) { // Check filePath and existence
384+
if (filePath != null && await File(filePath).exists()) {
389385
await File(filePath).delete();
390386
}
391-
client.close(); // Ensure client is closed
387+
client.close();
392388
return null;
393389
}
394390

395-
// Check if file exists after download attempt (excluding cancellation)
396391
if (!await file.exists()){
397392
developer.log('Error: File does not exist after download attempt (not due to cancellation). Path: ${file.path}', name: 'EnhancedUpdateService');
398393
_updateProgress(UpdateProgress(
@@ -407,17 +402,16 @@ class EnhancedUpdateService {
407402
return null;
408403
}
409404

410-
411405
if (totalBytes == 0 || downloadedBytes == totalBytes) {
412406
_updateProgress(UpdateProgress(
413407
progress: 1.0,
414-
status: 'ダウンロード完了',
408+
status: 'ダウンロード完了!インストールを開始します...',
415409
bytesDownloaded: downloadedBytes,
416410
totalBytes: totalBytes,
417-
isCompleted: true,
411+
isCompleted: false, // まだ完了していない(インストールが残っている)
418412
));
419413
developer.log('Download completed: ${file.path}', name: 'EnhancedUpdateService');
420-
client.close(); // Close client on success
414+
client.close();
421415
return file.path;
422416
} else if (downloadedBytes < totalBytes && totalBytes > 0) {
423417
_updateProgress(UpdateProgress(
@@ -431,7 +425,7 @@ class EnhancedUpdateService {
431425
if (await file.exists()) {
432426
await file.delete();
433427
}
434-
client.close(); // Close client on incomplete download
428+
client.close();
435429
return null;
436430
} else {
437431
_updateProgress(UpdateProgress(
@@ -445,12 +439,12 @@ class EnhancedUpdateService {
445439
if (await file.exists()) {
446440
await file.delete();
447441
}
448-
client.close(); // Close client on unexpected issue
442+
client.close();
449443
return null;
450444
}
451445

452-
} catch (e, s) { // Added stack trace
453-
developer.log('Download error: $e\\nStackTrace: $s', name: 'EnhancedUpdateService'); // Log stack trace
446+
} catch (e, s) {
447+
developer.log('Download error: $e\\nStackTrace: $s', name: 'EnhancedUpdateService');
454448
_updateProgress(UpdateProgress(
455449
progress: 0.0,
456450
status: 'ダウンロードエラー',
@@ -464,13 +458,11 @@ class EnhancedUpdateService {
464458
developer.log('Error deleting incomplete file: $deleteError', name: 'EnhancedUpdateService');
465459
}
466460
}
467-
client.close(); // Ensure client is closed on catch
461+
client.close();
468462
return null;
469-
} finally {
470-
// client.close(); // Moved to specific exit points (success, error, cancellation)
471463
}
472464
}
473-
465+
474466
/// 起動時のアップデートチェック(サイレント)
475467
Future<EnhancedAppUpdateInfo?> checkForUpdateOnStartup(String currentVersion, String owner, String repo) async {
476468
try {
@@ -705,4 +697,42 @@ class EnhancedUpdateService {
705697
));
706698
}
707699
}
700+
701+
/// ダウンロードとインストールを連続して実行
702+
Future<void> downloadAndInstallUpdate(EnhancedAppUpdateInfo releaseInfo, BuildContext context) async {
703+
try {
704+
// バージョンを記録
705+
await markUpdateAttempt(releaseInfo.version);
706+
707+
// ダウンロード実行
708+
final downloadedPath = await downloadUpdateWithProgress(releaseInfo);
709+
710+
if (downloadedPath != null && !_cancelDownload) {
711+
// ダウンロード成功後、インストール開始
712+
await applyUpdate(downloadedPath, context);
713+
} else if (_cancelDownload) {
714+
_updateProgress(UpdateProgress(
715+
progress: 0.0,
716+
status: 'アップデートがキャンセルされました',
717+
isCompleted: true,
718+
errorMessage: 'Update cancelled by user',
719+
));
720+
} else {
721+
_updateProgress(UpdateProgress(
722+
progress: 0.0,
723+
status: 'ダウンロードに失敗しました',
724+
isCompleted: true,
725+
errorMessage: 'Download failed',
726+
));
727+
}
728+
} catch (e) {
729+
developer.log('Error in downloadAndInstallUpdate: $e', name: 'EnhancedUpdateService');
730+
_updateProgress(UpdateProgress(
731+
progress: 0.0,
732+
status: 'アップデート処理中にエラーが発生しました',
733+
isCompleted: true,
734+
errorMessage: e.toString(),
735+
));
736+
}
737+
}
708738
}

lib/widgets/update_dialogs.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class _UpdateProgressDialogState extends State<UpdateProgressDialog> {
7373
// Listen to progress stream
7474
_progressSubscription = _updateService.progressStream?.listen(
7575
(progress) {
76-
debugPrint('[UpdateProgressDialog] Progress received: ${progress.status} - ${progress.progress * 100}%');
76+
//debugPrint('[UpdateProgressDialog] Progress received: ${progress.status} - ${progress.progress * 100}%');
7777
if (mounted) {
7878
setState(() {
7979
_currentProgress = progress;
@@ -86,7 +86,7 @@ class _UpdateProgressDialogState extends State<UpdateProgressDialog> {
8686
_isDownloading = false;
8787
}
8888
});
89-
debugPrint('[UpdateProgressDialog] UI updated with progress: ${progress.status}');
89+
// debugPrint('[UpdateProgressDialog] UI updated with progress: ${progress.status}');
9090
}
9191
},
9292
onError: (error) {

0 commit comments

Comments
 (0)