mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-12 19:33:41 +00:00
fix: incorrect storage path in linux (#270)
This commit is contained in:
9 files changed
+164
-85
No files matched your search
@@ -209,6 +209,10 @@ class AppController extends GetxController with WindowListener, TrayListener {
|
||||
}
|
||||
|
||||
Future<void> _initForegroundTask() async {
|
||||
if (!Util.isMobile()) {
|
||||
return;
|
||||
}
|
||||
|
||||
FlutterForegroundTask.init(
|
||||
androidNotificationOptions: AndroidNotificationOptions(
|
||||
channelId: 'gopeed_service',
|
||||
@@ -269,13 +273,8 @@ class AppController extends GetxController with WindowListener, TrayListener {
|
||||
_defaultStartConfig!.address = "127.0.0.1:0";
|
||||
} else {
|
||||
_defaultStartConfig!.network = "unix";
|
||||
if (Util.isDesktop()) {
|
||||
_defaultStartConfig!.address = unixSocketPath;
|
||||
}
|
||||
if (Util.isMobile()) {
|
||||
_defaultStartConfig!.address =
|
||||
"${(await getTemporaryDirectory()).path}/$unixSocketPath";
|
||||
}
|
||||
_defaultStartConfig!.address =
|
||||
"${(await getTemporaryDirectory()).path}/$unixSocketPath";
|
||||
}
|
||||
_defaultStartConfig!.apiToken = '';
|
||||
return _defaultStartConfig!;
|
||||
|
||||
@@ -4,8 +4,6 @@ import "libgopeed_boot_stub.dart"
|
||||
if (dart.library.io) 'entry/libgopeed_boot_native.dart';
|
||||
|
||||
abstract class LibgopeedBoot {
|
||||
static const unixSocketPath = 'gopeed.sock';
|
||||
|
||||
static LibgopeedBoot? _instance;
|
||||
|
||||
static LibgopeedBoot get instance {
|
||||
|
||||
@@ -37,11 +37,13 @@ Future<void> init() async {
|
||||
});
|
||||
}
|
||||
|
||||
if (!Util.isWeb()) {
|
||||
await Util.initStorageDir();
|
||||
}
|
||||
initLogger();
|
||||
|
||||
final controller = Get.put(AppController());
|
||||
try {
|
||||
if (!Util.isWeb()) {
|
||||
await Util.initStorageDir();
|
||||
}
|
||||
await controller.loadStartConfig();
|
||||
final startCfg = controller.startConfig.value;
|
||||
controller.runningPort.value = await LibgopeedBoot.instance.start(startCfg);
|
||||
|
||||
@@ -1,18 +1,24 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:logger/logger.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'util.dart';
|
||||
|
||||
final logger = Logger(
|
||||
filter: ProductionFilter(),
|
||||
printer: SimplePrinter(printTime: true, colors: false),
|
||||
output: buildOutput(),
|
||||
);
|
||||
late final Logger logger;
|
||||
|
||||
buildOutput() {
|
||||
initLogger() {
|
||||
// if is debug mode, don't log to file
|
||||
logger = Logger(
|
||||
filter: ProductionFilter(),
|
||||
printer: SimplePrinter(printTime: true, colors: false),
|
||||
output: _buildOutput(),
|
||||
);
|
||||
}
|
||||
|
||||
_buildOutput() {
|
||||
// if is debug mode, don't log to file
|
||||
if (!kDebugMode && Util.isDesktop()) {
|
||||
const logDirPath = 'logs';
|
||||
final logDirPath = path.join(Util.getStorageDir(), 'logs');
|
||||
var logDir = Directory(logDirPath);
|
||||
if (!logDir.existsSync()) {
|
||||
logDir.createSync();
|
||||
|
||||
@@ -6,6 +6,8 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
import 'log_util.dart';
|
||||
|
||||
class Util {
|
||||
static String? _storageDir;
|
||||
|
||||
@@ -55,6 +57,16 @@ class Util {
|
||||
storageDir = (await getExternalStorageDirectory())?.path ?? storageDir;
|
||||
} else if (Platform.isIOS) {
|
||||
storageDir = (await getLibraryDirectory()).path;
|
||||
} else if (Util.isLinux()) {
|
||||
storageDir = File(Platform.resolvedExecutable).parent.path;
|
||||
// check has write permission, if not, fallback to application support dir
|
||||
try {
|
||||
final testFile = File(path.join(storageDir, ".test"));
|
||||
await testFile.writeAsString("test");
|
||||
await testFile.delete();
|
||||
} catch (e) {
|
||||
storageDir = (await getApplicationSupportDirectory()).path;
|
||||
}
|
||||
}
|
||||
_storageDir = storageDir;
|
||||
}
|
||||
@@ -63,10 +75,6 @@ class Util {
|
||||
return _storageDir!;
|
||||
}
|
||||
|
||||
static String getStorageAsset(String asset) {
|
||||
return path.join(getStorageDir(), asset);
|
||||
}
|
||||
|
||||
static isAndroid() {
|
||||
return !kIsWeb && Platform.isAndroid;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user