diff --git a/src/renderer/src/App.jsx b/src/renderer/src/App.jsx
index 060eca3..a875a38 100644
--- a/src/renderer/src/App.jsx
+++ b/src/renderer/src/App.jsx
@@ -89,6 +89,15 @@ class App extends React.Component {
message.success("Google Drive API authorized")
},
+ "drive:unauthorized": (event, data) => {
+ this.setState({
+ authorizedServices: {
+ drive: false,
+ },
+ })
+
+ message.success("Google Drive API unauthorized")
+ }
}
onUpdateAvailable = () => {
@@ -122,6 +131,8 @@ class App extends React.Component {
console.log(`[INIT] >`, initResult)
+ app.location.push("/")
+
this.setState({
loading: false,
pkg: initResult.pkg,
diff --git a/src/renderer/src/layout/components/Header/index.jsx b/src/renderer/src/layout/components/Header/index.jsx
index c2b1ed7..1d33c94 100644
--- a/src/renderer/src/layout/components/Header/index.jsx
+++ b/src/renderer/src/layout/components/Header/index.jsx
@@ -34,6 +34,12 @@ const Header = (props) => {
}
+ }
+ onClick={() => app.location.push("/")}
+ />
+
}
diff --git a/src/renderer/src/pages/settings/index.jsx b/src/renderer/src/pages/settings/index.jsx
index 78023d3..20c85e6 100644
--- a/src/renderer/src/pages/settings/index.jsx
+++ b/src/renderer/src/pages/settings/index.jsx
@@ -2,98 +2,78 @@ import React from "react"
import * as antd from "antd"
import { Icons, Icon } from "components/Icons"
+import settingsList from "@renderer/settings_list"
+
import "./index.less"
-const settingsList = [
- {
- id: "drive_auth",
- name: "Google Drive Authorize",
- description: "Authorize your Google Drive account to be used for bundles installation.",
- icon: "SiGoogledrive",
- type: "button",
- value: async () => {
- return api.settings.get("drive_auth")
- },
- render: (props) => {
- return {
- if (!props.value) {
- message.info("Authorizing...")
- return ipc.exec("drive:authorize")
- }
-
- return api.settings.delete("drive_auth")
- }}
- >
- {
- props.value ? "Deauthorize" : "Authorize"
- }
-
- }
- },
- {
- id: "check_update",
- name: "Check for updates",
- description: "Check for updates to the app.",
- icon: "MdUpdate",
- type: "button",
- props: {
- children: "Check",
- onClick: () => {
- message.info("Checking for updates...")
- app.checkUpdates()
- }
- }
- }
-]
-
const SettingTypeToComponent = {
switch: antd.Switch,
button: antd.Button,
}
const SettingItem = (props) => {
- const {
- id,
- name,
- description,
- type,
- icon,
- props: _props,
- render,
- } = props.setting
+ const { setting } = props
const [loading, setLoading] = React.useState(false)
const [value, setValue] = React.useState(null)
- React.useEffect(() => {
- if (typeof props.setting.value === "function") {
- setLoading(true)
+ async function handleChange(value) {
+ console.log(`Setting [${setting.id}] set to >`, value)
+
+ setValue(value)
+
+ if (setting.storaged) {
+ api.settings.set(setting.id, value)
+ }
+ }
+
+ async function fetchDefaultValue() {
+ if (typeof setting.defaultValue !== "undefined") {
+ if (typeof setting.defaultValue === "function") {
+ setLoading(true)
+
+ const value = await setting.defaultValue()
- props.setting.value().then((value) => {
setValue(value)
setLoading(false)
- })
- } else {
- setLoading(false)
+ } else {
+ setValue(setting.defaultValue)
+ setLoading(false)
+ }
}
- }, [props.setting.value])
+ }
+
+ React.useEffect(() => {
+ fetchDefaultValue()
+
+ if (setting.watchIpc) {
+ for (const watchIpc of setting.watchIpc) {
+ ipc.on(watchIpc, (event, value) => {
+ fetchDefaultValue()
+ })
+ }
+ }
+
+ return () => {
+ if (setting.watchIpc) {
+ for (const watchIpc of setting.watchIpc) {
+ ipc.off(watchIpc, (event, value) => {
+ fetchDefaultValue()
+ })
+ }
+ }
+ }
+ }, [])
let componentProps = {
value: value,
- ..._props,
+ handleChange: handleChange,
+ ...setting.props,
}
- async function handleChange(value) {
- console.log(`Setting [${id}] set to >`, value)
- setValue(value)
- api.settings.set(id, value)
- }
-
- switch (type) {
+ switch (setting.type) {
case "switch": {
- componentProps.defaultChecked = defaultProps.defaultChecked ?? false
+ componentProps.defaultChecked = !!value
componentProps.onChange = (e) => {
handleChange(e)
}
@@ -101,10 +81,11 @@ const SettingItem = (props) => {
}
}
- const Component = SettingTypeToComponent[type.toLowerCase()]
+ const Component = SettingTypeToComponent[setting.type.toLowerCase()]
+
const Render = () => {
- if (typeof render === "function") {
- return render(componentProps)
+ if (typeof setting.render === "function") {
+ return setting.render(componentProps)
}
return React.createElement(Component, componentProps)
@@ -115,16 +96,16 @@ const SettingItem = (props) => {
>
-
+
- {name}
+ {setting.name}
- {description}
+ {setting.description}
diff --git a/src/renderer/src/router.jsx b/src/renderer/src/router.jsx
index 0f9b141..52a4b26 100644
--- a/src/renderer/src/router.jsx
+++ b/src/renderer/src/router.jsx
@@ -78,7 +78,7 @@ export const PageRender = () => {
}
return
- } />
- } />
+ } />
+ } />
}
\ No newline at end of file
diff --git a/src/renderer/src/settings_list.jsx b/src/renderer/src/settings_list.jsx
new file mode 100644
index 0000000..7fc5472
--- /dev/null
+++ b/src/renderer/src/settings_list.jsx
@@ -0,0 +1,49 @@
+import { Button } from "antd"
+
+export default [
+ {
+ id: "drive_auth",
+ name: "Google Drive Authorize",
+ description: "Authorize your Google Drive account to be used for bundles installation.",
+ icon: "SiGoogledrive",
+ type: "button",
+ storaged: false,
+ watchIpc: ["drive:authorized", "drive:unauthorized"],
+ defaultValue: async () => {
+ return await api.settings.get("drive_auth")
+ },
+ render: (props) => {
+ return
+ }
+ },
+ {
+ id: "check_update",
+ name: "Check for updates",
+ description: "Check for updates to the app.",
+ icon: "MdUpdate",
+ type: "button",
+ props: {
+ children: "Check",
+ onClick: () => {
+ message.info("Checking for updates...")
+ app.checkUpdates()
+ }
+ },
+ storaged: false
+ }
+]