Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
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
4 changes: 4 additions & 0 deletions packages/path_provider/path_provider_linux/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.0
* This release updates getApplicationSupportPath to use the application ID instead of the executable name.
* No migration is provided, so any older apps that were using this path will now have a different directory.

## 0.0.1+2
* This release updates the example to depend on the endorsed plugin rather than relative path

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@
// found in the LICENSE file.
import 'dart:io';
import 'dart:async';
import 'dart:ffi';
import 'package:ffi/ffi.dart';

import 'package:xdg_directories/xdg_directories.dart' as xdg;
import 'package:path/path.dart' as path;
import 'package:path_provider_platform_interface/path_provider_platform_interface.dart';

// GApplication* g_application_get_default();
typedef g_application_get_default_c = IntPtr Function();
typedef g_application_get_default_dart = int Function();

// const gchar* g_application_get_application_id(GApplication* application);
typedef g_application_get_application_id_c = Pointer<Utf8> Function(IntPtr);
typedef g_application_get_application_id_dart = Pointer<Utf8> Function(int);

/// The linux implementation of [PathProviderPlatform]
///
/// This class implements the `package:path_provider` functionality for linux
Expand All @@ -22,11 +32,43 @@ class PathProviderLinux extends PathProviderPlatform {
return Future.value("/tmp");
}

// Gets the application ID set in GApplication.
String _getApplicationId() {
DynamicLibrary gio;
try {
gio = DynamicLibrary.open('libgio-2.0.so');
} on ArgumentError {
return null;
}
var g_application_get_default = gio.lookupFunction<
g_application_get_default_c,
g_application_get_default_dart>('g_application_get_default');
var app = g_application_get_default();
if (app == 0) return null;

var g_application_get_application_id = gio.lookupFunction<
g_application_get_application_id_c,
g_application_get_application_id_dart>(
'g_application_get_application_id');
var app_id = g_application_get_application_id(app);
if (app_id == null) return null;

return Utf8.fromUtf8(app_id);
}

// Gets the unique ID for this application.
Future<String> _getId() async {
var appId = _getApplicationId();
if (appId != null) return appId;

// Fall back to using the executable name.
return path.basenameWithoutExtension(
await File('/proc/self/exe').resolveSymbolicLinks());
}

@override
Future<String> getApplicationSupportPath() async {
final processName = path.basenameWithoutExtension(
await File('/proc/self/exe').resolveSymbolicLinks());
final directory = Directory(path.join(xdg.dataHome.path, processName));
final directory = Directory(path.join(xdg.dataHome.path, await _getId()));
// Creating the directory if it doesn't exist, because mobile implementations assume the directory exists
if (!await directory.exists()) {
await directory.create(recursive: true);
Expand Down
3 changes: 2 additions & 1 deletion packages/path_provider/path_provider_linux/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: path_provider_linux
description: linux implementation of the path_provider plugin
version: 0.0.1+2
version: 0.1.0
homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider/path_provider_linux

flutter:
Expand All @@ -15,6 +15,7 @@ environment:
flutter: ">=1.10.0 <2.0.0"

dependencies:
ffi: ^0.1.3
path: ^1.6.4
xdg_directories: ^0.1.0
path_provider_platform_interface: ^1.0.1
Expand Down