mirror of
https://github.com/immich-app/immich.git
synced 2025-01-01 08:31: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,7 +91,9 @@ class AppLogPage extends HookConsumerWidget {
|
||||||
logMessages.value = [];
|
logMessages.value = [];
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
IconButton(
|
Builder(
|
||||||
|
builder: (BuildContext iconContext) {
|
||||||
|
return IconButton(
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
Icons.share_rounded,
|
Icons.share_rounded,
|
||||||
color: context.primaryColor,
|
color: context.primaryColor,
|
||||||
|
@ -99,7 +101,9 @@ class AppLogPage extends HookConsumerWidget {
|
||||||
size: 20.0,
|
size: 20.0,
|
||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
immichLogger.shareLogs();
|
immichLogger.shareLogs(iconContext);
|
||||||
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
|
@ -65,7 +65,7 @@ class ImageViewerStateNotifier extends StateNotifier<AssetViewerPageState> {
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext buildContext) {
|
builder: (BuildContext buildContext) {
|
||||||
_shareService.shareAsset(asset).then(
|
_shareService.shareAsset(asset, context).then(
|
||||||
(bool status) {
|
(bool status) {
|
||||||
if (!status) {
|
if (!status) {
|
||||||
ImmichToast.show(
|
ImmichToast.show(
|
||||||
|
|
|
@ -85,7 +85,7 @@ class ImmichLogger {
|
||||||
_db.writeTxn(() => _db.loggerMessages.clear());
|
_db.writeTxn(() => _db.loggerMessages.clear());
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> shareLogs() async {
|
Future<void> shareLogs(BuildContext context) async {
|
||||||
final tempDir = await getTemporaryDirectory();
|
final tempDir = await getTemporaryDirectory();
|
||||||
final dateTime = DateTime.now().toIso8601String();
|
final dateTime = DateTime.now().toIso8601String();
|
||||||
final filePath = '${tempDir.path}/Immich_log_$dateTime.log';
|
final filePath = '${tempDir.path}/Immich_log_$dateTime.log';
|
||||||
|
@ -107,11 +107,13 @@ class ImmichLogger {
|
||||||
await io.close();
|
await io.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final box = context.findRenderObject() as RenderBox?;
|
||||||
|
|
||||||
// Share file
|
// Share file
|
||||||
await Share.shareXFiles(
|
await Share.shareXFiles(
|
||||||
[XFile(filePath)],
|
[XFile(filePath)],
|
||||||
subject: "Immich logs $dateTime",
|
subject: "Immich logs $dateTime",
|
||||||
sharePositionOrigin: Rect.zero,
|
sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size,
|
||||||
).then(
|
).then(
|
||||||
(value) => logFile.delete(),
|
(value) => logFile.delete(),
|
||||||
);
|
);
|
||||||
|
|
|
@ -19,11 +19,11 @@ class ShareService {
|
||||||
|
|
||||||
ShareService(this._apiService);
|
ShareService(this._apiService);
|
||||||
|
|
||||||
Future<bool> shareAsset(Asset asset) async {
|
Future<bool> shareAsset(Asset asset, BuildContext context) async {
|
||||||
return await shareAssets([asset]);
|
return await shareAssets([asset], context);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> shareAssets(List<Asset> assets) async {
|
Future<bool> shareAssets(List<Asset> assets, BuildContext context) async {
|
||||||
try {
|
try {
|
||||||
final downloadedXFiles = <XFile>[];
|
final downloadedXFiles = <XFile>[];
|
||||||
|
|
||||||
|
@ -64,9 +64,10 @@ class ShareService {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final box = context.findRenderObject() as RenderBox?;
|
||||||
Share.shareXFiles(
|
Share.shareXFiles(
|
||||||
downloadedXFiles,
|
downloadedXFiles,
|
||||||
sharePositionOrigin: Rect.zero,
|
sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size,
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
@ -22,7 +22,10 @@ void handleShareAssets(
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext buildContext) {
|
builder: (BuildContext buildContext) {
|
||||||
ref.watch(shareServiceProvider).shareAssets(selection.toList()).then(
|
ref
|
||||||
|
.watch(shareServiceProvider)
|
||||||
|
.shareAssets(selection.toList(), context)
|
||||||
|
.then(
|
||||||
(bool status) {
|
(bool status) {
|
||||||
if (!status) {
|
if (!status) {
|
||||||
ImmichToast.show(
|
ImmichToast.show(
|
||||||
|
|
Loading…
Reference in a new issue