Skip to content

Commit

Permalink
feat(electron): build now works
Browse files Browse the repository at this point in the history
  • Loading branch information
tomjeannesson committed Mar 12, 2024
1 parent 173861f commit 62bbfac
Show file tree
Hide file tree
Showing 15 changed files with 193 additions and 77 deletions.
2 changes: 1 addition & 1 deletion desktop-app/.prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"semi": false,
"plugins": [
"prettier-plugin-tailwindcss",
"prettier-plugin-organize-imports"
"prettier-plugin-organize-imports"
]
}
6 changes: 1 addition & 5 deletions desktop-app/electron-builder.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
appId: com.example.nextron
productName: My Nextron App
productName: Napse
copyright: Copyright © 2018 Yoshihide Shiono
directories:
output: dist
Expand All @@ -10,8 +10,4 @@ files:
- package.json
- app

linux:
target: deb
icon: renderer/public/images/logo.svg

publish: null
9 changes: 6 additions & 3 deletions desktop-app/main/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if (isProd) {
})
ipcMain.handle('fullCleanupAWS', async (event, args) => {
if (args.secrets) {
return await fullCleanupAWS(args.secrets, mainWindow)
return await fullCleanupAWS(args.secrets, args.deleteData, mainWindow)
}
})
ipcMain.handle('updateAWS', async (event, args) => {
Expand Down Expand Up @@ -83,9 +83,12 @@ if (isProd) {
EB_APP_NAME,
EB_ENV_NAME
)
if (environments) {
if (environments && environments.length > 0) {
for (const env of environments) {
if (env.Status != EnvironmentStatus.Ready) {
if (
env.Status != EnvironmentStatus.Terminated &&
env.Status != EnvironmentStatus.Ready
) {
allReady = false
break
}
Expand Down
25 changes: 19 additions & 6 deletions desktop-app/main/helpers/aws/deployToAWS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,27 @@ import {
} from 'main/helpers'
import path from 'path'

export const EB_BUCKET_NAME = 'napse-eb-bucket'
export const EB_APP_NAME = 'napse'
export const EB_BUCKET_NAME = `napse-eb-bucket${
process.env.NODE_ENV === 'production' ? '' : '-dev'
}`
export const EB_APP_NAME = `napse${
process.env.NODE_ENV === 'production' ? '' : '-dev'
}`
export const EB_APP_DESCRIPTION = 'No description'
export const EB_ENV_NAME = 'napse-env'
export const IAM_ROLE_NAME_SERVICE_ROLE = 'napse-iam-service-role'
export const IAM_ROLE_NAME_EC2_ROLE = 'napse-iam-ec2-role'
export const IAM_INSTANCE_PROFILE_NAME = 'napse-iam-instance-profile'
export const EB_ENV_NAME = `napse-env${
process.env.NODE_ENV === 'production' ? '' : '-dev'
}`
export const IAM_ROLE_NAME_SERVICE_ROLE = `napse-iam-service-role${
process.env.NODE_ENV === 'production' ? '' : '-dev'
}`
export const IAM_ROLE_NAME_EC2_ROLE = `napse-iam-ec2-role${
process.env.NODE_ENV === 'production' ? '' : '-dev'
}`
export const IAM_INSTANCE_PROFILE_NAME = `napse-iam-instance-profile${
process.env.NODE_ENV === 'production' ? '' : '-dev'
}`

console.log('EB_BUCKET_NAME', EB_BUCKET_NAME)
export default async function Main(
secrets: {
AWS__API_TOKEN: string
Expand Down
7 changes: 5 additions & 2 deletions desktop-app/main/helpers/aws/fullCleanupAWS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default async function Main(
AWS__API_SECRET: string
AWS__REGION: string
},
deleteData: boolean,
mainWindow: BrowserWindow
) {
updateStatus(mainWindow, 'fullReset', 'START')
Expand Down Expand Up @@ -101,7 +102,9 @@ export default async function Main(
await deleteIAMRole(secrets, mainWindow, IAM_ROLE_NAME_SERVICE_ROLE)
updateStatus(mainWindow, 'fullReset', 'deleteEBApp')
await deleteEBApp(secrets, mainWindow, EB_APP_NAME)
updateStatus(mainWindow, 'fullReset', 'deleteBucket')
await deleteBucket(secrets, mainWindow, EB_BUCKET_NAME)
if (deleteData) {
updateStatus(mainWindow, 'fullReset', 'deleteBucket')
await deleteBucket(secrets, mainWindow, EB_BUCKET_NAME)
}
updateStatus(mainWindow, 'fullReset', 'END')
}
5 changes: 3 additions & 2 deletions desktop-app/main/helpers/utils/updateStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ const SATUS = {
busy: true
},
END: {
description: 'Full reset complete, see you soon!',
description: 'Reset complete, see you soon!',
busy: false
}
}
Expand All @@ -219,6 +219,7 @@ export default async function Main<T extends keyof typeof SATUS>(
busy: errorMessage ? false : (SATUS[stage][step] as StatusStep).busy,
progress: (index / (Object.keys(SATUS[stage]).length - 1)) * 100,
errorMessage: errorMessage,
extraData: extraData
extraData: extraData,
step: step
})
}
8 changes: 7 additions & 1 deletion desktop-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@
"name": "napse",
"description": "Napse Desktop App",
"homepage": "https://napse-invest.com",
"version": "1.0.0",
"version": "1.4.0",
"author": "Napse Invest <napse.invest@gmail.com>",
"main": "app/background.js",
"scripts": {
"start": "nextron",
"build": "nextron build",
"build:mac": "nextron build --mac",
"build:mac:universal": "nextron build --mac --universal",
"build:linux": "nextron build --linux",
"build:win32": "nextron build --win --ia32",
"build:win64": "nextron build --win --x64",
"build:all": "nextron build --mac --linux --win --x64",
"postinstall": "electron-builder install-app-deps",
"lint": "next lint"
},
Expand Down
10 changes: 7 additions & 3 deletions desktop-app/renderer/components/custom/selectedObject/inputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,14 @@ export default function CustomForm<T extends Object>({
) : (
<Button
type="submit"
onClick={(e) => {
console.log('props', e)
onClick={async (e) => {
setIsLoading(true)
return form.handleSubmit(onSubmit)(e)
const submit = form.handleSubmit(onSubmit)(e)

await new Promise((resolve) => setTimeout(resolve, 400))
setIsLoading(false)

return submit
}}
>
{buttonDescription ?? 'Submit'}
Expand Down
156 changes: 114 additions & 42 deletions desktop-app/renderer/pages/settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { ReloadIcon } from '@radix-ui/react-icons'
import { ipcRenderer } from 'electron'
import fs from 'fs'
import path from 'path'
import { useEffect, useState } from 'react'
import { Dispatch, SetStateAction, useEffect, useState } from 'react'
import { z } from 'zod'

const defaultSecrets = {
Expand Down Expand Up @@ -102,7 +102,19 @@ async function testHasAvailableUpdate(
}
throw new Error('Provider not supported')
}

async function updateStatus(
secrestsSet: boolean,
secrets: { [key: string]: string },
provider: TypeProviders,
setIsDeployed: Dispatch<SetStateAction<boolean>>,
setIsReadyToUpdate: Dispatch<SetStateAction<boolean>>,
setHasAvailableUpdate: Dispatch<SetStateAction<boolean>>
) {
if (!secrestsSet) return
setIsDeployed(await testIsDeployed(secrets, provider))
setIsReadyToUpdate(await testIsReadyToUpdate(secrets, provider))
setHasAvailableUpdate(await testHasAvailableUpdate(secrets, provider))
}
export default function Settings(): JSX.Element {
const { toast } = useToast()
const [infoDeploy, setInfoDeploy] = useState('')
Expand Down Expand Up @@ -148,12 +160,29 @@ export default function Settings(): JSX.Element {
setInfoFullReset(data.errorMessage ? data.errorMessage : data.message)
removeServer(provider)
}
if (data.step === 'END') {
updateStatus(
secrestsSet,
secrets,
provider,
setIsDeployed,
setIsReadyToUpdate,
setHasAvailableUpdate
)
}
setIsErrorMessage(data.errorMessage ? true : false)

setLoading(data.busy)
setProgress(data.progress)
})
}, [provider])
}, [
provider,
secrestsSet,
secrets,
setIsDeployed,
setIsReadyToUpdate,
setHasAvailableUpdate
])

useEffect(() => {
const rootPath = process.env.HOME || process.env.USERPROFILE
Expand All @@ -175,21 +204,18 @@ export default function Settings(): JSX.Element {

useEffect(() => {
async function apiCall() {
if (!secrestsSet) return
setIsDeployed(await testIsDeployed(secrets, provider))
setIsReadyToUpdate(await testIsReadyToUpdate(secrets, provider))
updateStatus(
secrestsSet,
secrets,
provider,
setIsDeployed,
setIsReadyToUpdate,
setHasAvailableUpdate
)
}
apiCall()
}, [secrets, provider, secrestsSet])

useEffect(() => {
async function handleUpdateAvailable() {
if (!secrestsSet) return
setHasAvailableUpdate(await testHasAvailableUpdate(secrets, provider))
}
handleUpdateAvailable()
}, [secrets, provider, secrestsSet])

useEffect(() => {
if (hasAvailableUpdate) {
toast({
Expand Down Expand Up @@ -256,8 +282,11 @@ export default function Settings(): JSX.Element {
<TabsTrigger value={'Update'} disabled={loading}>
Update
</TabsTrigger>
<TabsTrigger value={'Reset'} disabled={loading}>
Reset
<TabsTrigger value={'Pause'} disabled={loading}>
Pause
</TabsTrigger>
<TabsTrigger value={'Full Reset'} disabled={loading}>
Full Reset
</TabsTrigger>
</TabsList>
<TabsContent value={'Setup'}>
Expand Down Expand Up @@ -343,12 +372,12 @@ export default function Settings(): JSX.Element {
{
"We've made deploying your own server easy, just click this button!"
}
{isDeployed && (
<div className=" text-destructive text-sm">
Warning: Server already deployed
</div>
)}
</CardDescription>
{isDeployed && (
<div className=" text-destructive text-sm">
Warning: Server already deployed
</div>
)}
</CardHeader>
<CardContent className="flex flex-col items-center justify-center">
<div className="h-4" />
Expand Down Expand Up @@ -383,21 +412,16 @@ export default function Settings(): JSX.Element {
{
"Here's a little button to update your server, just in case you want to do so."
}
{!isReadyToUpdate ? (
<div className=" text-destructive text-sm">
Warning: No server deployed
</div>
) : (
<></>
)}
{isReadyToUpdate && !hasAvailableUpdate ? (
<div className=" text-destructive text-sm">
No updates available
</div>
) : (
<></>
)}
</CardDescription>
<div className=" text-destructive text-sm">
{!isDeployed
? 'Warning: No server deployed'
: !isReadyToUpdate
? 'Warning: Server not ready'
: !hasAvailableUpdate
? 'No updates available'
: ''}
</div>
</CardHeader>
<CardContent className="flex flex-col items-center justify-center">
<div className="h-4" />
Expand Down Expand Up @@ -436,28 +460,76 @@ export default function Settings(): JSX.Element {
</CardContent>
</Card>
</TabsContent>
<TabsContent value={'Reset'}>
<TabsContent value={'Pause'}>
<Card className="h-[100%]">
<CardHeader>
<CardTitle>Pause</CardTitle>
<CardDescription>
{
"If you're not using your server, you can pause it to save some money."
}
</CardDescription>
<div className=" text-destructive text-sm">
{!isDeployed
? 'Warning: No server deployed'
: !isReadyToUpdate
? 'Warning: Server not ready'
: ''}
</div>
</CardHeader>

<CardContent className="flex flex-col items-center justify-center">
<div className="h-4" />
<Button
className="w-[100%]"
onClick={() => {
ipcRenderer.invoke('fullCleanupAWS', {
secrets: secrets,
deleteData: false
})
}}
disabled={loading || !isReadyToUpdate || !isDeployed}
>
{loading && (
<ReloadIcon className="mr-2 h-4 w-4 animate-spin" />
)}
{loading ? 'Shutting down server' : 'Shut down server'}
</Button>

<div className="h-1" />
{loading && <Progress value={progress} />}
<div className="h-1" />
<div className="text-muted-foreground text-center text-sm">
{infoFullReset}
</div>
</CardContent>
</Card>
</TabsContent>
<TabsContent value={'Full Reset'}>
<Card className="h-[100%]">
<CardHeader>
<CardTitle>Full Reset</CardTitle>
<CardDescription>
{
"Had enough of your server? Just click this button and it'll be gone."
}
<br />
{"It's just that easy."}
<div className=" text-destructive text-sm">
{!isReadyToUpdate ? 'Warning: No server deployed' : ''}
</div>
</CardDescription>
<div className=" text-destructive text-sm">
{!isDeployed
? 'Warning: No server deployed'
: !isReadyToUpdate
? 'Warning: Server not ready'
: ''}
</div>
</CardHeader>
<CardContent className="flex flex-col items-center justify-center">
<div className="h-4" />
<Button
className="w-[100%]"
onClick={() => {
ipcRenderer.invoke('fullCleanupAWS', {
secrets
secrets: secrets,
deleteData: true
})
}}
disabled={loading || !isReadyToUpdate || !isDeployed}
Expand Down
Binary file removed desktop-app/resources/icon.icns
Binary file not shown.
Binary file removed desktop-app/resources/icon.ico
Binary file not shown.
Binary file added desktop-app/resources/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 62bbfac

Please sign in to comment.