Skip to content

Commit

Permalink
Merge branch 'feature/autoUpdates' of github.com:napse-invest/Napse
Browse files Browse the repository at this point in the history
  • Loading branch information
tomjeannesson committed Mar 14, 2024
2 parents 7e0fdb1 + 195d764 commit 1117b7e
Show file tree
Hide file tree
Showing 13 changed files with 141 additions and 68 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Deploy to Github Releases

on:
release:
types: [published]



jobs:
release:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]

steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18.x


- name: Build/release Electron app
uses: samuelmeuli/action-electron-builder@v1
with:
# GitHub token, automatically provided to the action
# (No need to define this secret in the repo settings)
github_token: ${{ secrets.github_token }}

# If the commit is tagged with a version (e.g. "v1.0.0"),
# release the app after building
release: ${{ startsWith(github.ref, 'refs/tags/v') }}
4 changes: 4 additions & 0 deletions desktop-app/electron-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ files:
- package.json
- app

linux:
target: deb


publish: null
31 changes: 30 additions & 1 deletion desktop-app/main/background.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EnvironmentStatus } from '@aws-sdk/client-elastic-beanstalk'
import { BrowserWindow, app, ipcMain } from 'electron'
import { BrowserWindow, app, autoUpdater, dialog, ipcMain } from 'electron'
import serve from 'electron-serve'
import {
EB_APP_NAME,
Expand All @@ -25,6 +25,35 @@ if (isProd) {
;(async () => {
await app.whenReady()

if (isProd) {
const server = 'https://hazel-c8oqh794d-napse-investment.vercel.app/'
const url = `${server}/update/${process.platform}/${app.getVersion()}`

autoUpdater.setFeedURL({ url })
setInterval(() => {
autoUpdater.checkForUpdates()
}, 60000)
autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName) => {
const dialogOpts = {
type: 'info',
buttons: ['Restart', 'Later'],
title: 'Application Update',
message: process.platform === 'win32' ? releaseNotes : releaseName,
detail:
'A new version has been downloaded. Restart the application to apply the updates.'
}

dialog.showMessageBox(dialogOpts).then((returnValue) => {
if (returnValue.response === 0) autoUpdater.quitAndInstall()
})
console.log('update-downloaded')
})
autoUpdater.on('error', (message) => {
console.error('There was a problem updating the application')
console.error(message)
})
}

const mainWindow = createWindow('main', {
width: 1000,
height: 600
Expand Down
1 change: 0 additions & 1 deletion desktop-app/main/helpers/aws/deployToAWS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ 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
17 changes: 8 additions & 9 deletions desktop-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@
"name": "napse",
"description": "Napse Desktop App",
"homepage": "https://napse-invest.com",
"version": "1.4.0",
"version": "1.5.0",
"author": "Napse Invest <[email protected]>",
"main": "app/background.js",
"scripts": {
"start": "nextron",
"build": "nextron build",
"build": "nextron build --mac --linux --win --x64",
"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 Expand Up @@ -53,15 +52,15 @@
"axios": "^1.5.0",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"electron-dl": "^3.5.1",
"extract-zip": "^2.0.1",
"fs": "^0.0.1-security",
"https": "^1.0.0",
"cmdk": "^0.2.1",
"date-fns": "^3.3.1",
"electron-dl": "^3.5.1",
"electron-serve": "^1.1.0",
"electron-store": "^8.1.0",
"embla-carousel-react": "^8.0.0-rc20",
"extract-zip": "^2.0.1",
"fs": "^0.0.1-security",
"https": "^1.0.0",
"lucide-react": "^0.344.0",
"next-themes": "^0.2.1",
"react-day-picker": "^8.10.0",
Expand All @@ -70,8 +69,8 @@
"redaxios": "^0.5.1",
"separator": "^0.1.0",
"shadcn-ui": "^0.4.1",
"superagent": "^8.1.2",
"sonner": "^1.4.3",
"superagent": "^8.1.2",
"table": "^6.8.1",
"tabs": "^0.2.0",
"tailwind-merge": "^1.14.0",
Expand All @@ -88,7 +87,7 @@
"@typescript-eslint/parser": "^6.16.0",
"autoprefixer": "^10.4.7",
"electron": "^21.4.4",
"electron-builder": "^24.12.0",
"electron-builder": "^24.13.3",
"eslint": "^8.57.0",
"eslint-config-next": "13.5.4",
"eslint-config-standard-with-typescript": "^39.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ export default function CustomForm<T extends Object>({

return (
<Form {...form}>
{/* <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-2"> */}
<form className="space-y-2">
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-2">
{inputs.map((input, index) => {
return (
<FormField
Expand Down Expand Up @@ -228,14 +227,11 @@ export default function CustomForm<T extends Object>({
</Button>
) : (
<Button
type="submit"
onClick={async (e) => {
setIsLoading(true)
const submit = form.handleSubmit(onSubmit)(e)

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

return submit
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export default function SelectedObject<T extends Object>({
<CustomForm<typeof object>
inputs={inputs}
onSubmit={async (values) => {
console.log(values)
if (!updateOnClick) return
try {
await updateOnClick(values)
Expand Down
2 changes: 2 additions & 0 deletions desktop-app/renderer/lib/localStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function addServer(
}

function updateServer(server: Server) {
console.log(server)
if (typeof window !== 'undefined') {
if (!localStorage.servers) {
localStorage.servers = JSON.stringify({})
Expand All @@ -34,6 +35,7 @@ function updateServer(server: Server) {
url: server.url,
token: server.token
}
console.log(servers)
localStorage.servers = JSON.stringify(servers)
}
}
Expand Down
9 changes: 7 additions & 2 deletions desktop-app/renderer/pages/servers/[slug]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useRouter } from 'next/router'
import { useEffect, useState } from 'react'
import * as z from 'zod'
import SelectedAPIKey from './selectedAPIKey'

export default function Servers(): JSX.Element {
const router = useRouter()
const searchParams = useSearchParams()
Expand All @@ -39,8 +40,12 @@ export default function Servers(): JSX.Element {
objectIdentifier="name"
object={server}
setObject={setServer}
updateOnClick={() => {
updateServer(server)
updateOnClick={(values) => {
updateServer({
name: values.name,
url: values.url,
token: values.token
})
}}
deleteOnClick={() => {
removeServer(server.name)
Expand Down
2 changes: 1 addition & 1 deletion desktop-app/renderer/pages/settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ export default function Settings(): JSX.Element {
: !isReadyToUpdate
? 'Warning: Server not ready'
: !hasAvailableUpdate
? 'No updates available'
? 'Warning: No updates available'
: ''}
</div>
</CardHeader>
Expand Down
Loading

0 comments on commit 1117b7e

Please sign in to comment.