-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from pacholoamit/feat/auto-start
feat/auto start
- Loading branch information
Showing
16 changed files
with
190 additions
and
41 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file added
BIN
+4.34 KB
.yarn/cache/tauri-plugin-autostart-api-https-123e333c81-a37ed161ef.zip
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React from "react"; | ||
import AutoStartSettingsView from "@/features/settings/views/autostart.view"; | ||
import PageWrapper from "@/components/page-wrapper"; | ||
import Card from "@/components/card"; | ||
|
||
import { Icon24Hours } from "@tabler/icons-react"; | ||
import { Center, Grid, NavLink } from "@mantine/core"; | ||
import { useState } from "react"; | ||
|
||
const settings = [{ icon: Icon24Hours, label: "Auto Start", view: <AutoStartSettingsView /> }]; | ||
|
||
const SettingsPage = () => { | ||
const [active, setActive] = useState(0); | ||
const items = settings.map((item, index) => ( | ||
<React.Fragment key={item.label}> | ||
<Grid.Col span={4}> | ||
<NavLink | ||
key={item.label} | ||
active={index === active} | ||
label={item.label} | ||
icon={<item.icon size="1rem" stroke={1.5} />} | ||
onClick={() => { | ||
setActive(index); | ||
}} | ||
/> | ||
</Grid.Col> | ||
<Grid.Col span={8}>{index === active && item.view}</Grid.Col> | ||
</React.Fragment> | ||
)); | ||
|
||
return ( | ||
<PageWrapper name="Settings"> | ||
<Center> | ||
<Card> | ||
<Grid style={{ width: "45rem" }}>{items}</Grid> | ||
</Card> | ||
</Center> | ||
</PageWrapper> | ||
); | ||
}; | ||
|
||
export default SettingsPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Skeleton, Switch } from "@mantine/core"; | ||
import { useEffect, useState } from "react"; | ||
import { autostart } from "@/lib"; | ||
|
||
const AutoStartSettingsView = () => { | ||
const [checked, setChecked] = useState(false); | ||
const [loading, setLoading] = useState(true); | ||
const checkAutoStart = async () => setChecked(await autostart.isEnabled()); | ||
|
||
useEffect(() => { | ||
checkAutoStart(); | ||
setLoading(false); | ||
}, [checkAutoStart]); | ||
|
||
const onChange = () => { | ||
if (!checked) { | ||
autostart.enable(); | ||
} else { | ||
autostart.disable(); | ||
} | ||
setChecked(!checked); | ||
}; | ||
|
||
if (loading) { | ||
return ( | ||
<> | ||
<Skeleton height={8} radius="xl" /> | ||
<Skeleton height={8} mt={6} radius="xl" /> | ||
<Skeleton height={8} mt={6} width="70%" radius="xl" /> | ||
</> | ||
); | ||
} | ||
return <Switch checked={checked} onChange={onChange} label="Start on system startup" />; | ||
}; | ||
|
||
export default AutoStartSettingsView; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { enable, isEnabled, disable } from "tauri-plugin-autostart-api"; | ||
|
||
export const enableAutostart = async () => { | ||
if (await isEnabled()) { | ||
return; | ||
} | ||
|
||
await enable(); | ||
}; | ||
|
||
export const disableAutostart = async () => { | ||
if (!(await isEnabled())) { | ||
return; | ||
} | ||
|
||
await disable(); | ||
}; | ||
|
||
export const autostart = { | ||
enable: enableAutostart, | ||
disable: disableAutostart, | ||
isEnabled, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "@/lib/helpers"; | ||
export * from "@/lib/types"; | ||
export * from "@/lib/store"; | ||
export * from "@/lib/autostart"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.