Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check if app in application folder for permissions #1143

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions public/locales/af/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
"day": "Dag",
"disconnect": "Ontkoppel",
"hashrate": "Hashtempo",
"installation-problem": "Installation problem",
"max-temperature": "Maksimum temperatuur",
"mode": "Modus",
"not-installed-in-applications-directory": "Oops! Tari Universe needs to live in the Applications directory. Mind installing it there?",
"please-try-again-later": "Probeer asseblief later weer. As die probleem voortduur, kontak ons asseblief.",
"resources": "Hulpbronne",
"restart": "Herbegin",
Expand Down
2 changes: 2 additions & 0 deletions public/locales/cn/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
"day": "天",
"disconnect": "断开连接",
"hashrate": "哈希率",
"installation-problem": "Installation problem",
"max-temperature": "最高温度",
"mode": "模式",
"not-installed-in-applications-directory": "Oops! Tari Universe needs to live in the Applications directory. Mind installing it there?",
"please-try-again-later": "请稍后再试。如果问题仍然存在,请联系我们。",
"resources": "资源",
"restart": "重启",
Expand Down
2 changes: 2 additions & 0 deletions public/locales/de/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
"day": "Tag",
"disconnect": "Trennen",
"hashrate": "Hashrate",
"installation-problem": "Installation problem",
"max-temperature": "Maximaltemperatur",
"mode": "Modus",
"not-installed-in-applications-directory": "Oops! Tari Universe needs to live in the Applications directory. Mind installing it there?",
"please-try-again-later": "Bitte versuche es später erneut. Wenn das Problem weiterhin besteht, kontaktiere uns bitte.",
"resources": "Ressourcen",
"restart": "Neustarten",
Expand Down
2 changes: 2 additions & 0 deletions public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
"day": "Day",
"disconnect": "Disconnect",
"hashrate": "Hashrate",
"installation-problem": "Installation problem",
"max-temperature": "Max temperature",
"mode": "Mode",
"not-installed-in-applications-directory": "Oops! Tari Universe needs to live in the Applications directory. Mind installing it there?",
"please-try-again-later": "Please try again later. If the problem persists, please contact us.",
"resources": "Resources",
"restart": "Restart",
Expand Down
2 changes: 2 additions & 0 deletions public/locales/fr/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
"day": "Jour",
"disconnect": "Déconnecter",
"hashrate": "Taux de hachage",
"installation-problem": "Installation problem",
"max-temperature": "Température maximale",
"mode": "Mode",
"not-installed-in-applications-directory": "Oops! Tari Universe needs to live in the Applications directory. Mind installing it there?",
"please-try-again-later": "Réessaye plus tard s'il te plaît. Si le problème persiste, contacte-nous s'il te plaît.",
"resources": "Ressources",
"restart": "Redémarrer",
Expand Down
2 changes: 2 additions & 0 deletions public/locales/hi/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
"day": "दिन",
"disconnect": "डिस्कनेक्ट करें",
"hashrate": "हैश दर",
"installation-problem": "Installation problem",
"max-temperature": "अधिकतम तापमान",
"mode": "मोड",
"not-installed-in-applications-directory": "Oops! Tari Universe needs to live in the Applications directory. Mind installing it there?",
"please-try-again-later": "कृपया बाद में पुनः प्रयास करें। यदि समस्या बनी रहती है, तो कृपया हमसे संपर्क करें।",
"resources": "संसाधन",
"restart": "पुनः आरंभ करें",
Expand Down
2 changes: 2 additions & 0 deletions public/locales/id/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
"day": "Hari",
"disconnect": "Putuskan Koneksi",
"hashrate": "Hashrate",
"installation-problem": "Installation problem",
"max-temperature": "Suhu maksimum",
"mode": "Mode",
"not-installed-in-applications-directory": "Oops! Tari Universe needs to live in the Applications directory. Mind installing it there?",
"please-try-again-later": "Silakan coba lagi nanti. Jika masalah berlanjut, silakan hubungi kami.",
"resources": "Sumber daya",
"restart": "Mulai Ulang",
Expand Down
2 changes: 2 additions & 0 deletions public/locales/ja/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
"day": "日",
"disconnect": "切断",
"hashrate": "ハッシュレート",
"installation-problem": "Installation problem",
"max-temperature": "最大温度",
"mode": "モード",
"not-installed-in-applications-directory": "Oops! Tari Universe needs to live in the Applications directory. Mind installing it there?",
"please-try-again-later": "後でもう一度お試しください。問題が続く場合は、お問い合わせください。",
"resources": "リソース",
"restart": "再起動",
Expand Down
2 changes: 2 additions & 0 deletions public/locales/ko/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
"day": "일",
"disconnect": "연결 해제",
"hashrate": "해시레이트",
"installation-problem": "Installation problem",
"max-temperature": "최대 온도",
"mode": "모드",
"not-installed-in-applications-directory": "Oops! Tari Universe needs to live in the Applications directory. Mind installing it there?",
"please-try-again-later": "나중에 다시 시도해 주세요. 문제가 계속되면 저희에게 연락해 주세요.",
"resources": "자원",
"restart": "재시작",
Expand Down
2 changes: 2 additions & 0 deletions public/locales/pl/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
"day": "Dzień",
"disconnect": "Odłącz",
"hashrate": "Prędkość ( hashrate )",
"installation-problem": "Installation problem",
"max-temperature": "Maksymalna temperatura",
"mode": "Tryb",
"not-installed-in-applications-directory": "Oops! Tari Universe needs to live in the Applications directory. Mind installing it there?",
"please-try-again-later": "Spróbuj ponownie później. Jeśli problem będzie się powtarzał, skontaktuj się z nami.",
"resources": "Zasoby",
"restart": "Uruchom ponownie",
Expand Down
2 changes: 2 additions & 0 deletions public/locales/ru/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
"day": "День",
"disconnect": "Отключить",
"hashrate": "Хэшрейт",
"installation-problem": "Installation problem",
"max-temperature": "Максимальная температура",
"mode": "Режим",
"not-installed-in-applications-directory": "Oops! Tari Universe needs to live in the Applications directory. Mind installing it there?",
"please-try-again-later": "Пожалуйста, попробуйте позже. Если проблема сохраняется, свяжитесь с нами.",
"resources": "Ресурсы",
"restart": "Перезапустить",
Expand Down
2 changes: 2 additions & 0 deletions public/locales/tr/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
"day": "Gün",
"disconnect": "Bağlantıyı Kes",
"hashrate": "Hashrate",
"installation-problem": "Installation problem",
"max-temperature": "Maks. Sıcaklık",
"mode": "Mod",
"not-installed-in-applications-directory": "Oops! Tari Universe needs to live in the Applications directory. Mind installing it there?",
"please-try-again-later": "Lütfen daha sonra tekrar deneyin. Sorun devam ederse, lütfen bizimle iletişime geçin.",
"resources": "Kaynaklar",
"restart": "Yeniden Başlat",
Expand Down
24 changes: 24 additions & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ use tokio::sync::{Mutex, RwLock};
use tokio::time;
use tor_adapter::TorConfig;
use utils::logging_utils::setup_logging;
#[cfg(target_os = "macos")]
use utils::macos_utils::is_app_in_applications_folder;
use utils::shutdown_utils::stop_all_processes;
use wallet_adapter::TransactionInfo;

Expand Down Expand Up @@ -128,6 +130,12 @@ struct UpdateProgressRustEvent {
content_length: u64,
downloaded: u64,
}
#[derive(Debug, Serialize, Clone)]
#[allow(dead_code)]
struct CriticalProblemEvent {
title: Option<String>,
description: Option<String>,
}

#[tauri::command]
async fn set_mode(
Expand Down Expand Up @@ -649,6 +657,22 @@ async fn setup_inner(
)
.inspect_err(|e| error!(target: LOG_TARGET, "Could not emit event 'message': {:?}", e))?;

#[cfg(target_os = "macos")]
if !cfg!(dev) && !is_app_in_applications_folder() {
window
.emit(
"critical_problem",
CriticalProblemEvent {
title: None,
description: Some("not-installed-in-applications-directory".to_string()),
},
)
.inspect_err(
|e| error!(target: LOG_TARGET, "Could not emit event 'critical_problem': {:?}", e),
)?;
return Ok(());
}

let data_dir = app
.path_resolver()
.app_local_data_dir()
Expand Down
11 changes: 11 additions & 0 deletions src-tauri/src/utils/macos_utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#[cfg(target_os = "macos")]
use std::env;
#[cfg(target_os = "macos")]
use std::path::Path;

#[cfg(target_os = "macos")]
pub fn is_app_in_applications_folder() -> bool {
let current_exe = env::current_exe().unwrap();
let applications_folder = Path::new("/Applications");
current_exe.starts_with(applications_folder)
}
1 change: 1 addition & 0 deletions src-tauri/src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod auto_rollback;
pub mod file_utils;
pub mod logging_utils;
pub mod macos_utils;
pub mod platform_utils;
pub mod setup_utils;
pub mod shutdown_utils;
2 changes: 2 additions & 0 deletions src/App/AppWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useAppConfigStore } from '../store/useAppConfigStore.ts';
import { setupLogger } from '../utils/shared-logger.ts';
import { useDetectMode } from '../hooks/helpers/useDetectMode.ts';
import App from './App.tsx';
import useListenForCriticalProblem from '@app/hooks/useListenForCriticalProblem.tsx';

// FOR ANYTHING THAT NEEDS TO BE INITIALISED

Expand Down Expand Up @@ -39,6 +40,7 @@ export default function AppWrapper() {
useUpdateListener();
useLangaugeResolver();
useListenForExternalDependencies();
useListenForCriticalProblem();
useEffect(() => {
async function initialize() {
await fetchAppConfig();
Expand Down
16 changes: 16 additions & 0 deletions src/components/AdminUI/groups/DialogsGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useAppStateStore } from '@app/store/appStateStore';

export function DialogsGroup() {
const { setCriticalError, criticalError } = useAppStateStore();
const { setCriticalProblem, criticalProblem } = useAppStateStore();
const { setDialogToShow, dialogToShow, showExternalDependenciesDialog, setShowExternalDependenciesDialog } =
useUIStore();

Expand All @@ -18,6 +19,21 @@ export function DialogsGroup() {
>
Critical Error
</Button>
<Button
onClick={() =>
setCriticalProblem(
criticalProblem
? undefined
: {
title: 'This is a critical problem description',
description: 'This is a critical problem description',
}
)
}
$isActive={!!criticalProblem}
>
Critical Problem
</Button>
<Button
onClick={() => setDialogToShow(dialogToShow === 'autoUpdate' ? undefined : 'autoUpdate')}
$isActive={dialogToShow === 'autoUpdate'}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { SquaredButton } from '@app/components/elements/buttons/SquaredButton';
import { CircularProgress } from '@app/components/elements/CircularProgress';
import { Dialog, DialogContent } from '@app/components/elements/dialog/Dialog';
import { Stack } from '@app/components/elements/Stack';
import { Typography } from '@app/components/elements/Typography';
import { useAppStateStore } from '@app/store/appStateStore';
import { invoke } from '@tauri-apps/api';
import { useCallback, useState } from 'react';
import { useTranslation } from 'react-i18next';

export const CriticalProblemDialog = () => {
const { t } = useTranslation('common', { useSuspense: false });
const criticalProblem = useAppStateStore((s) => s.criticalProblem);
const [isExiting, setIsExiting] = useState(false);

const handleClose = useCallback(async () => {
try {
setIsExiting(true);
await invoke('exit_application');
} catch (e) {
console.error('Error closing application| handleClose in CriticalProblemDialog: ', e);
}
setIsExiting(false);
}, []);

return (
<Dialog open={!!criticalProblem}>
<DialogContent>
<Stack gap={16}>
<Stack gap={4}>
<Typography variant="h4">{t(criticalProblem?.title || 'installation-problem')}</Typography>
<Typography variant="p">{t(criticalProblem?.description || 'installation-problem')}</Typography>
</Stack>
<Stack direction="row" justifyContent="center" gap={8}>
{isExiting ? (
<CircularProgress />
) : (
<SquaredButton color="error" size="medium" onClick={handleClose} style={{ width: '100%' }}>
{t('close-tari-universe')}
</SquaredButton>
)}
</Stack>
</Stack>
</DialogContent>
</Dialog>
);
};
2 changes: 2 additions & 0 deletions src/containers/floating/FloatingElements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import PaperWalletModal from './PaperWalletModal/PaperWalletModal.tsx';
import ShareRewardModal from './ShareRewardModal/ShareRewardModal';
import AdminUI from '@app/components/AdminUI/AdminUI.tsx';
import { ToastStack } from '@app/components/ToastStack/ToastStack.tsx';
import { CriticalProblemDialog } from './CriticalProblemDialog/CriticalProblemDialog.tsx';

const environment = import.meta.env.MODE;

Expand All @@ -23,6 +24,7 @@ export default function FloatingElements() {
<PaperWalletModal />
<ShareRewardModal />
<ToastStack />
<CriticalProblemDialog />
{environment === 'development' && <AdminUI />}
</FloatingTree>
);
Expand Down
19 changes: 19 additions & 0 deletions src/hooks/useListenForCriticalProblem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { useAppStateStore } from '@app/store/appStateStore';
import { CriticalProblem } from '@app/types/app-status';
import { listen } from '@tauri-apps/api/event';
import { useEffect } from 'react';

const useListenForCriticalProblem = () => {
const setCriticalProblem = useAppStateStore((s) => s.setCriticalProblem);
useEffect(() => {
const unlistenPromise = listen<CriticalProblem>('critical_problem', ({ payload }) => {
setCriticalProblem(payload);
});

return () => {
unlistenPromise.then((unlisten) => unlisten());
};
}, [setCriticalProblem]);
};

export default useListenForCriticalProblem;
5 changes: 4 additions & 1 deletion src/store/appStateStore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ApplicationsVersions, ExternalDependency } from '@app/types/app-status';
import { ApplicationsVersions, CriticalProblem, ExternalDependency } from '@app/types/app-status';
import { setAnimationState } from '@app/visuals';
import { create } from './create';
import { invoke } from '@tauri-apps/api';
Expand All @@ -13,6 +13,8 @@ interface AppState {
setCriticalError: (value: string | undefined) => void;
error?: string;
setError: (value: string | undefined) => void;
criticalProblem?: Partial<CriticalProblem>;
setCriticalProblem: (value?: Partial<CriticalProblem>) => void;
topStatus: string;
setTopStatus: (value: string) => void;
setupTitle: string;
Expand Down Expand Up @@ -49,6 +51,7 @@ export const useAppStateStore = create<AppState>()((set, getState) => ({
type: 'error',
});
},
setCriticalProblem: (criticalProblem) => set({ criticalProblem }),
topStatus: 'Not mining',
setTopStatus: (value) => set({ topStatus: value }),
setupTitle: '',
Expand Down
5 changes: 5 additions & 0 deletions src/types/app-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ export interface ExternalDependency {
status: ExternalDependencyStatus;
}

export interface CriticalProblem {
title: string;
description: string;
}

export interface CpuMinerMetrics {
hardware: PublicDeviceParameters[];
mining: CpuMinerStatus;
Expand Down