Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.

Commit 3907f6c

Browse files
committed
chore: apply new pages
1 parent 0899ae8 commit 3907f6c

File tree

7 files changed

+91
-194
lines changed

7 files changed

+91
-194
lines changed

main/background.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { app, BrowserWindow, ipcMain } from 'electron';
1+
import { app, ipcMain } from 'electron';
22
import serve from 'electron-serve';
33
import { createWindow } from './helpers';
44
import electronLogger from "electron-log";
@@ -7,10 +7,13 @@ import ipcEvents from './helpers/ipcEvents';
77
import tray from './helpers/tray';
88
import util, { isProd } from './util';
99
import apiEvents from './helpers/apiEvents';
10+
import userSettings from "./helpers/userSettings"
1011

1112
// AUTO UPDATER
1213
autoUpdater.logger = electronLogger
1314

15+
autoUpdater.allowPrerelease = userSettings.get("beta")
16+
1417
// @ts-ignore
1518
autoUpdater.logger.transports.file.level = "info"
1619
// AUTO UPDATER
@@ -45,12 +48,12 @@ if (isProd) {
4548
show: false,
4649
frame: false
4750
})
48-
mainWindow.loadURL(util.renderPage("main"))
51+
mainWindow.loadURL(util.renderPage("home"))
4952

5053
splashWindow.on('close', () => {
5154
if(mainWindow) mainWindow.show()
5255
})
53-
56+
5457
autoUpdater.on("update-not-available", () => {
5558
splashWindow.webContents.send("load-window")
5659
})

main/helpers/ipcEvents.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { randomUUID } from "crypto";
2-
import { app, dialog, ipcMain, Notification } from "electron";
2+
import { app, ipcMain, Notification } from "electron";
33
import Store from "electron-store";
44
import files from "./files";
55
import util from "../util";
66
import { PasswordData } from "../../renderer/util/interfaces";
7+
import userSettings from "./userSettings"
78

89
const passwordStore = new Store({
910
name: 'passwords'
@@ -74,7 +75,8 @@ const init = () => {
7475

7576
ipcMain.handle("select-file", async (_, options) => files.select(options))
7677

77-
ipcMain.handle("save-file", async (_, path) => files.save(path, "testPy.png"))
78+
ipcMain.handle("get-setting", async(_, name) => userSettings.get(name))
79+
ipcMain.handle("update-setting", async(_, name, value) => userSettings.set(name, value))
7880
};
7981

8082
export default {

main/helpers/tray.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Tray, Menu, nativeImage } from "electron"
1+
import { Tray, Menu, nativeImage, BrowserWindow } from "electron"
22
import util from "../util"
33

44
const init = async() => {
@@ -10,6 +10,14 @@ const init = async() => {
1010
{ label: "Exit LockPass", role: "quit" }
1111
])
1212

13+
tray.on('right-click', () => {
14+
if(BrowserWindow.getAllWindows().length > 1) {
15+
const win = BrowserWindow.getAllWindows()[0]
16+
win.show()
17+
win.restore()
18+
}
19+
})
20+
1321
tray.setToolTip("LockPass")
1422
tray.setContextMenu(contextMenu)
1523
}

main/helpers/userSettings.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import Store from "electron-store"
2+
3+
const settingStore = new Store({
4+
name: "settings",
5+
defaults: {
6+
beta: false
7+
},
8+
clearInvalidConfig: true
9+
})
10+
11+
export default settingStore

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"private": true,
33
"name": "lock-pass",
44
"description": "A simple password manager",
5-
"version": "1.4.0",
5+
"version": "1.5.0",
66
"author": "Nemika Hajbour <nemika@bytestobits.dev>",
77
"repository": {
88
"type": "git",

renderer/pages/main.tsx

Lines changed: 0 additions & 187 deletions
This file was deleted.

renderer/pages/settings.tsx

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { Badge, Checkbox, Divider, Flex, HStack, Text } from "@chakra-ui/react"
2+
import { ipcRenderer } from "electron"
3+
import { useEffect, useState } from "react"
4+
import Main from "../components/Main"
5+
6+
export default () => {
7+
const [firstFetch, setFetch] = useState(false)
8+
9+
const [beta, setBeta] = useState(false)
10+
const [version, setVersion] = useState("")
11+
12+
useEffect(() => {
13+
14+
if (!firstFetch) {
15+
const init = async() => {
16+
setBeta(await ipcRenderer.invoke("get-setting", "beta"))
17+
setVersion(await ipcRenderer.invoke("get-version"))
18+
}
19+
20+
init()
21+
22+
setFetch(true)
23+
}
24+
25+
})
26+
27+
const handleUpdate = async(name, value) => {
28+
await ipcRenderer.invoke("update-setting", name, value)
29+
}
30+
31+
return (
32+
<Main>
33+
<Flex
34+
w="calc(100vw - 150px)"
35+
maxH="calc(100vh - 30px)"
36+
overflowY="auto"
37+
m={5}
38+
p={5}
39+
rounded="md"
40+
border="2px solid white"
41+
bg="darkBackground"
42+
direction="column"
43+
>
44+
<Text fontWeight="bold" fontSize="30px">Settings</Text>
45+
<Divider mb={2} />
46+
47+
<HStack>
48+
<Text>Beta Releases: </Text>
49+
<Checkbox isChecked={beta} onChange={async() => {
50+
await handleUpdate("beta", !beta)
51+
setBeta(!beta)
52+
}} />
53+
</HStack>
54+
55+
<Badge colorScheme="orange" w="max-content" rounded="md" p={2} my={2}>Version: {version}</Badge>
56+
57+
</Flex>
58+
</Main>
59+
)
60+
}

0 commit comments

Comments
 (0)