From 5b7b3b1dfd5ce7c275881098310667b09562ad27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Mon, 11 Nov 2024 12:27:53 +0100 Subject: New upstream version 0.32.10 --- src/AppDirs.vala | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'src/AppDirs.vala') diff --git a/src/AppDirs.vala b/src/AppDirs.vala index 05e172c..fd357c2 100644 --- a/src/AppDirs.vala +++ b/src/AppDirs.vala @@ -193,12 +193,39 @@ class AppDirs { public static File get_exec_dir() { return exec_dir; } + + public enum Runtime { + NATIVE, + FLATPAK, + SNAP, + UNKNOWN + } + + private static Runtime _runtime = Runtime.UNKNOWN; + + public static Runtime get_runtime() { + if (_runtime == Runtime.UNKNOWN) { + var snap = Environment.get_variable("SNAP_NAME"); + if (snap != null) { + _runtime = Runtime.SNAP; + } + else { + var flatpak_canary = File.new_for_path("/.flatpak-info"); + if (flatpak_canary.query_exists()) { + _runtime = Runtime.FLATPAK; + } else { + _runtime = Runtime.NATIVE; + } + } + } + + return _runtime; + } public static File get_temp_dir() { if (tmp_dir == null) { var basedir = Environment.get_tmp_dir(); - var flatpak_canary = File.new_for_path("/.flatpak-info"); - if (flatpak_canary.query_exists() && basedir == "/tmp") { + if (get_runtime() == Runtime.FLATPAK && basedir == "/tmp") { basedir = Environment.get_user_cache_dir() + "/tmp"; } -- cgit v1.2.3