mirror of
https://github.com/immich-app/immich.git
synced 2024-12-28 22:51:59 +00:00
fix(mobile): native share functionality on iPad (#11294)
* pass context to share method * use correct context * fix: multiselection and logs sharing * fix: lint
This commit is contained in:
parent
86a658b891
commit
62ac9bb7cd
5 changed files with 27 additions and 17 deletions
|
@ -91,15 +91,19 @@ class AppLogPage extends HookConsumerWidget {
|
|||
logMessages.value = [];
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
Icons.share_rounded,
|
||||
color: context.primaryColor,
|
||||
semanticLabel: "Share logs",
|
||||
size: 20.0,
|
||||
),
|
||||
onPressed: () {
|
||||
immichLogger.shareLogs();
|
||||
Builder(
|
||||
builder: (BuildContext iconContext) {
|
||||
return IconButton(
|
||||
icon: Icon(
|
||||
Icons.share_rounded,
|
||||
color: context.primaryColor,
|
||||
semanticLabel: "Share logs",
|
||||
size: 20.0,
|
||||
),
|
||||
onPressed: () {
|
||||
immichLogger.shareLogs(iconContext);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
|
|
|
@ -65,7 +65,7 @@ class ImageViewerStateNotifier extends StateNotifier<AssetViewerPageState> {
|
|||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext buildContext) {
|
||||
_shareService.shareAsset(asset).then(
|
||||
_shareService.shareAsset(asset, context).then(
|
||||
(bool status) {
|
||||
if (!status) {
|
||||
ImmichToast.show(
|
||||
|
|
|
@ -85,7 +85,7 @@ class ImmichLogger {
|
|||
_db.writeTxn(() => _db.loggerMessages.clear());
|
||||
}
|
||||
|
||||
Future<void> shareLogs() async {
|
||||
Future<void> shareLogs(BuildContext context) async {
|
||||
final tempDir = await getTemporaryDirectory();
|
||||
final dateTime = DateTime.now().toIso8601String();
|
||||
final filePath = '${tempDir.path}/Immich_log_$dateTime.log';
|
||||
|
@ -107,11 +107,13 @@ class ImmichLogger {
|
|||
await io.close();
|
||||
}
|
||||
|
||||
final box = context.findRenderObject() as RenderBox?;
|
||||
|
||||
// Share file
|
||||
await Share.shareXFiles(
|
||||
[XFile(filePath)],
|
||||
subject: "Immich logs $dateTime",
|
||||
sharePositionOrigin: Rect.zero,
|
||||
sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size,
|
||||
).then(
|
||||
(value) => logFile.delete(),
|
||||
);
|
||||
|
|
|
@ -19,11 +19,11 @@ class ShareService {
|
|||
|
||||
ShareService(this._apiService);
|
||||
|
||||
Future<bool> shareAsset(Asset asset) async {
|
||||
return await shareAssets([asset]);
|
||||
Future<bool> shareAsset(Asset asset, BuildContext context) async {
|
||||
return await shareAssets([asset], context);
|
||||
}
|
||||
|
||||
Future<bool> shareAssets(List<Asset> assets) async {
|
||||
Future<bool> shareAssets(List<Asset> assets, BuildContext context) async {
|
||||
try {
|
||||
final downloadedXFiles = <XFile>[];
|
||||
|
||||
|
@ -64,9 +64,10 @@ class ShareService {
|
|||
);
|
||||
}
|
||||
|
||||
final box = context.findRenderObject() as RenderBox?;
|
||||
Share.shareXFiles(
|
||||
downloadedXFiles,
|
||||
sharePositionOrigin: Rect.zero,
|
||||
sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size,
|
||||
);
|
||||
return true;
|
||||
} catch (error) {
|
||||
|
|
|
@ -22,7 +22,10 @@ void handleShareAssets(
|
|||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext buildContext) {
|
||||
ref.watch(shareServiceProvider).shareAssets(selection.toList()).then(
|
||||
ref
|
||||
.watch(shareServiceProvider)
|
||||
.shareAssets(selection.toList(), context)
|
||||
.then(
|
||||
(bool status) {
|
||||
if (!status) {
|
||||
ImmichToast.show(
|
||||
|
|
Loading…
Reference in a new issue