# Description of Changes - Adds a reusable banner component/system to the core app - Adds banner at the top of the desktop app if Stirling isn't your default PDF editor, with a button to make it your default - Adds a permanent button in the settings to do it manually (in case you've dismissed the banner) - Simplifies the file loading logic to fix a bug where the input file could be duplicated occasionally. Now, the TS just receives files from one buffer, regardless of how they've been passed to the app in Rust. ## Caveats I've only been able to get the setting of default apps working properly on Mac. The Windows build isn't signed (yet) so we can't use the proper API for it, so currently it just sends you to the Settings UI. I've also not been able to test it on Linux at all.
62 lines
1.8 KiB
TypeScript
62 lines
1.8 KiB
TypeScript
import { useState, useEffect } from 'react';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { defaultAppService } from '@app/services/defaultAppService';
|
|
import { alert } from '@app/components/toast';
|
|
|
|
export const useDefaultApp = () => {
|
|
const { t } = useTranslation();
|
|
const [isDefault, setIsDefault] = useState<boolean | null>(null);
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
|
|
useEffect(() => {
|
|
checkDefaultStatus();
|
|
}, []);
|
|
|
|
const checkDefaultStatus = async () => {
|
|
try {
|
|
const status = await defaultAppService.isDefaultPdfHandler();
|
|
setIsDefault(status);
|
|
} catch (error) {
|
|
console.error('Failed to check default status:', error);
|
|
}
|
|
};
|
|
|
|
const handleSetDefault = async () => {
|
|
setIsLoading(true);
|
|
try {
|
|
const result = await defaultAppService.setAsDefaultPdfHandler();
|
|
|
|
if (result === 'set_successfully') {
|
|
alert({
|
|
alertType: 'success',
|
|
title: t('defaultApp.success.title', 'Default App Set'),
|
|
body: t('defaultApp.success.message', 'Stirling PDF is now your default PDF editor'),
|
|
});
|
|
setIsDefault(true);
|
|
} else if (result === 'opened_settings') {
|
|
alert({
|
|
alertType: 'neutral',
|
|
title: t('defaultApp.settingsOpened.title', 'Settings Opened'),
|
|
body: t('defaultApp.settingsOpened.message', 'Please select Stirling PDF in your system settings'),
|
|
});
|
|
}
|
|
} catch (error) {
|
|
console.error('Failed to set default:', error);
|
|
alert({
|
|
alertType: 'error',
|
|
title: t('defaultApp.error.title', 'Error'),
|
|
body: t('defaultApp.error.message', 'Failed to set default PDF handler'),
|
|
});
|
|
} finally {
|
|
setIsLoading(false);
|
|
}
|
|
};
|
|
|
|
return {
|
|
isDefault,
|
|
isLoading,
|
|
checkDefaultStatus,
|
|
handleSetDefault,
|
|
};
|
|
};
|