Skip to content

Commit

Permalink
Fix auto launch
Browse files Browse the repository at this point in the history
  • Loading branch information
ziulev committed Dec 14, 2021
1 parent 53363da commit b6783c5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
2 changes: 0 additions & 2 deletions apps/spotter/src/components/queryPanel/queryPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
StyleSheet,
Text,
View,
Appearance,
} from 'react-native';
import { useSettings, useSpotterState } from '../../providers';
import { OptionIcon, QueryPanelOptions } from './options.queryPanel';
Expand All @@ -14,7 +13,6 @@ import { useEvents } from '../../providers/events.provider';
import { getHint } from '../../helpers';
import { PluginOnQueryOption, PluginRegistryOption, SpotterThemeColors } from '../../interfaces';
import { Subscription } from 'rxjs';
import { DARK_THEME, LIGHT_THEME } from '../../constants';

export const QueryPanel: FC<{}> = () => {

Expand Down
10 changes: 6 additions & 4 deletions apps/spotter/src/components/settings/general.settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ export const GeneralSettings: FC<{}> = () => {
useEffect(() => {
const setSettings = async () => {
const loginItems = await shell.execute('osascript -e \'tell application "System Events" to get the name of every login item\' || echo \'\'');
const launchAtLoginStatus = !!loginItems.split(',').find(item => item === 'spotter');
const launchAtLoginStatus = !!loginItems.split(',').find((item: string) => item.includes('Spotter'));

setLaunchAtLoginEnabled(launchAtLoginStatus);

const spotterPath = await shell.execute('osascript -e \'POSIX path of (path to application "Spotify")\'');
const spotterPath = await shell.execute('osascript -e \'POSIX path of (path to application "Spotter")\'');

setSpotterPath(spotterPath);
};

Expand All @@ -28,9 +29,10 @@ export const GeneralSettings: FC<{}> = () => {
Alert.alert('You have to move Spotter.app to Applications folder');
return;
}
shell.execute(`osascript -e 'tell application "System Events" to make login item at end with properties {path:"${spotterPath}", hidden:false}'`)
const properties = `{path:\"${spotterPath}\", hidden:false}`
shell.execute(`osascript -e 'tell application "System Events" to make login item at end with properties ${properties}'`)
} else {
shell.execute('osascript -e \'tell application "System Events" to delete login item "spotter"\'')
shell.execute('osascript -e \'tell application "System Events" to delete login item "Spotter"\'')
}
setLaunchAtLoginEnabled(value);
};
Expand Down
33 changes: 29 additions & 4 deletions apps/spotter/src/components/settings/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ export const Settings: FC<{}> = () => {

const onSelectPage = useCallback(setActivePage, []);

const { colors$ } = useSettings();

const [colors, setColors] = useState<SpotterThemeColors>();

const subscriptions: Subscription[] = [];

useEffect(() => {
subscriptions.push(
colors$.subscribe(setColors),
);
}, []);

useEffect(() => {
return () => subscriptions.forEach(s => s.unsubscribe());
}, []);

const renderPage = (page: Pages) => {
switch(page) {
case Pages.general:
Expand All @@ -37,7 +53,7 @@ export const Settings: FC<{}> = () => {
<View style={{
display: 'flex',
flexDirection: 'row',
borderBottomWidth: 1,
backgroundColor: colors?.background,
}}>
{Object.values(Pages).map(page => (
<TouchableOpacity
Expand All @@ -47,14 +63,23 @@ export const Settings: FC<{}> = () => {
>
<Text
style={{
// color: page === activePage ? colors?.text : colors?.hoveredOptionText,
color: page === activePage ? colors?.hoveredOptionBackground: colors?.text,
}}
>{page[0].toUpperCase() + page.slice(1)}</Text>
</TouchableOpacity>
))}
</View>
<ScrollView>
<View style={{margin: 15}}>
<View style={{
height: 1,
backgroundColor: colors?.text,
opacity: 0.2,
}}></View>
<ScrollView style={{
backgroundColor: colors?.background,
}}>
<View style={{
margin: 15,
}}>
{renderPage(activePage)}
</View>
</ScrollView>
Expand Down

0 comments on commit b6783c5

Please sign in to comment.