trixon
February 27, 2021, 8:55am
1
What is the proper way to inform and instruct the user of a probably needed permission?
In my case it’s mostly about removable-media .
Should I put the following in the description
sudo snap connect mapton:removable-media :removable-media
together with some information or add a link to somewhere?
Seems a bit verbose though.
Is it possible from within my (java) snap check if and interface is connected or not?
ogra
February 27, 2021, 2:07pm
2
you can use a command-chain script and snapctl to check if an interface is connected, see:
#! /bin/sh [ -e "$SNAP_USER_DATA/.check-complete" ] && exec "$@" if ! id -Gn | grep -q video; then yad --text "<b>Error, can not open video playback device \!</b>\n\nThe user $LOGNAME is not in the "video" group.\nPlease execute:\n\n <b>sudo usermod -a -G video $LOGNAME</b>\n\nIn a Terminal, afterwards log out and back in again." \ --borders=5 --center --on-top --undecorated \ --skip-taskbar && exit 0 fi if ! snapctl is-connected hardware-observe; then yad --text "<b>Error, can not get status of video playback device \!</b>\n\nPlease connect the hardware-observe snap interface\nwith the command:\n\n <b>sudo snap connect vlc-pi:hardware-observe</b>\n\nOr through the Permissions UI in the snap-store application" \ --borders=5 --center --on-top --undecorated \ --skip-taskbar && exit 0 fi if [ ! -d "$SNAP_USER_COMMON/.local/lib/locale/$LANG" ]; then yad --text "\nGenerating VLC translations for:\n\n\t$LANG" \ --borders=10 --no-buttons --center --on-top \ --undecorated --skip-taskbar --timeout=10 \ --timeout-indicator=bottom &
1 Like
trixon
February 28, 2021, 6:59am
3
Thank you @ogra , and the best way to check if the app is inside a snap?
ogra
February 28, 2021, 11:38am
4
pick an environment variable to your liking
$ snap run --shell <yoursnap>
...
$ env | grep SNAP
...
$ exit
$
trixon
March 4, 2021, 7:11pm
6
Here’s the result in java for anyone who’s interested.
public static boolean isConnected(String plugOrSlot) throws IOException, InterruptedException {
var processBuilder = new ProcessBuilder(StringUtils.split(String.format("snapctl is-connected %s", plugOrSlot)));
var process = processBuilder.start();
return 0 == process.waitFor();
}
public static boolean isSnap() {
var env = System.getenv();
return env.containsKey("SNAP_ARCH") && env.containsKey("SNAP_INSTANCE_NAME");
}
/*
* Copyright 2021 Patrik Karlström.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package se.trixon.almond.util;
import java.io.IOException;
import org.apache.commons.lang3.StringUtils;
This file has been truncated. show original
ppd
March 5, 2021, 8:40am
7
Are there plans to include permission prompt dialogs in the Ubuntu desktop at any point in the future? Just like Android asks for permission to use the camera on behalf of an app for example.
2 Likes
trixon
March 5, 2021, 2:36pm
8
This is what I ended up with, but I really do prefer the way @ppd is talking about.
2 Likes
This is known on our roadmap as “prompting” and it is something we really want to do, but it will take a while before it is ready since it requires significant kernel/apparmor work before we can make use of it. When we have something closer to working we will share more info on the forum about it.
5 Likes