mirror of
https://github.com/ankitects/anki.git
synced 2025-09-23 00:12:25 -04:00
Fix silent file save failures and bad default save path in Flatpak (#2427)
* add Jack Pearson to CONTRIBUTORS * Skip file cleanup operations when impossible in sandbox * Rename checkNeedPortalSupport -> running_in_sandbox
This commit is contained in:
parent
a32c7a8e63
commit
7fbff43a58
2 changed files with 19 additions and 1 deletions
|
@ -113,6 +113,7 @@ Mani <github.com/krmanik>
|
||||||
Kaben Nanlohy <kaben.nanlohy@gmail.com>
|
Kaben Nanlohy <kaben.nanlohy@gmail.com>
|
||||||
Tobias Predel <tobias.predel@gmail.com>
|
Tobias Predel <tobias.predel@gmail.com>
|
||||||
Daniel Tang <danielzgtg.opensource@gmail.com>
|
Daniel Tang <danielzgtg.opensource@gmail.com>
|
||||||
|
Jack Pearson <github.com/jrpear>
|
||||||
|
|
||||||
********************
|
********************
|
||||||
|
|
||||||
|
|
|
@ -638,6 +638,23 @@ def getFile(
|
||||||
return ret[0] if ret else None
|
return ret[0] if ret else None
|
||||||
|
|
||||||
|
|
||||||
|
def running_in_sandbox():
|
||||||
|
"""Check whether running in Flatpak or Snap. When in such a sandbox, Qt
|
||||||
|
will not report the true location of user-chosen files, but instead a
|
||||||
|
temporary location from which the sandboxing software will copy the file to
|
||||||
|
the user-chosen destination. Thus file renames are impossible and caching
|
||||||
|
the reported file location is unhelpful."""
|
||||||
|
in_flatpak = (
|
||||||
|
QStandardPaths.locate(
|
||||||
|
QStandardPaths.StandardLocation.RuntimeLocation,
|
||||||
|
"flatpak-info",
|
||||||
|
)
|
||||||
|
!= ""
|
||||||
|
)
|
||||||
|
in_snap = os.environ.get("SNAP") != ""
|
||||||
|
return in_flatpak or in_snap
|
||||||
|
|
||||||
|
|
||||||
def getSaveFile(
|
def getSaveFile(
|
||||||
parent: QDialog,
|
parent: QDialog,
|
||||||
title: str,
|
title: str,
|
||||||
|
@ -662,7 +679,7 @@ def getSaveFile(
|
||||||
f"{key} (*{ext})",
|
f"{key} (*{ext})",
|
||||||
options=QFileDialog.Option.DontConfirmOverwrite,
|
options=QFileDialog.Option.DontConfirmOverwrite,
|
||||||
)[0]
|
)[0]
|
||||||
if file:
|
if file and not running_in_sandbox():
|
||||||
# add extension
|
# add extension
|
||||||
if not file.lower().endswith(ext):
|
if not file.lower().endswith(ext):
|
||||||
file += ext
|
file += ext
|
||||||
|
|
Loading…
Reference in a new issue