Skip to content

Commit

Permalink
feat: sentry & update detector
Browse files Browse the repository at this point in the history
  • Loading branch information
olup committed Jul 31, 2022
1 parent e27ea6c commit 5d56646
Show file tree
Hide file tree
Showing 16 changed files with 412 additions and 146 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build-next.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
run: |
Set-Item -Path Env:CGO_LDFLAGS -Value "-LD:/a/lunii-admin/lunii-admin/bindings/windows/lib"
Set-Item -Path Env:CGO_CFLAGS -Value "-ID:/a/lunii-admin/lunii-admin/bindings/windows/include"
wails build -debug -o lunii-admin_windows_amd64.exe -ldflags "-v '-extldflags=-static -lm'"
go generate && wails build -debug -o lunii-admin_windows_amd64.exe -ldflags "-v '-extldflags=-static -lm'"
- uses: ncipollo/release-action@v1
with:
Expand Down Expand Up @@ -86,7 +86,7 @@ jobs:
run: go install github.com/wailsapp/wails/v2/cmd/wails@latest

- name: Build
run: wails build -debug -o lunii-admin_linux_amd64
run: go generate && wails build -debug -o lunii-admin_linux_amd64

- uses: ncipollo/release-action@v1
with:
Expand Down Expand Up @@ -131,7 +131,7 @@ jobs:
run: go install github.com/wailsapp/wails/v2/cmd/wails@latest

- name: Build
run: wails build -debug
run: go generate && wails build -debug

- name: Create Zip
run: ditto -c -k --sequesterRsrc --keepParent build/bin/lunii-admin.app lunii-admin_darwin_amd64.zip
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/build-version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
run: |
Set-Item -Path Env:CGO_LDFLAGS -Value "-LD:/a/lunii-admin/lunii-admin/bindings/windows/lib"
Set-Item -Path Env:CGO_CFLAGS -Value "-ID:/a/lunii-admin/lunii-admin/bindings/windows/include"
wails build -o lunii-admin_windows_amd64.exe -ldflags "-v '-extldflags=-static -lm'"
go generate && wails build -o lunii-admin_windows_amd64.exe -ldflags "-v '-extldflags=-static -lm'"
- uses: ncipollo/release-action@v1
with:
Expand Down Expand Up @@ -84,7 +84,7 @@ jobs:
run: go install github.com/wailsapp/wails/v2/cmd/wails@latest

- name: Build
run: wails build -o lunii-admin_linux_amd64
run: go generate && wails build -o lunii-admin_linux_amd64

- uses: ncipollo/release-action@v1
with:
Expand Down Expand Up @@ -127,7 +127,7 @@ jobs:
run: go install github.com/wailsapp/wails/v2/cmd/wails@latest

- name: Build
run: wails build
run: go generate && wails build

- name: Create Zip
run: ditto -c -k --sequesterRsrc --keepParent build/bin/lunii-admin.app lunii-admin_darwin_amd64.zip
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ node_modules
.DS_Store
build/bin
build/darwin
version.txt
112 changes: 107 additions & 5 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,31 @@ package main

import (
"context"
_ "embed"
"fmt"
"log"
"os"
"path/filepath"
goruntime "runtime"
"strings"

"github.com/blang/semver"
"github.com/denisbrodbeck/machineid"
"github.com/google/uuid"
"github.com/rhysd/go-github-selfupdate/selfupdate"

"github.com/olup/lunii-cli/pkg/lunii"
studiopackbuilder "github.com/olup/lunii-cli/pkg/pack-builder"
"github.com/wailsapp/wails/v2/pkg/runtime"

"github.com/getsentry/sentry-go"
)

//go:generate bash scripts/get-version.sh
//go:embed version.txt
var version string
var machineId, _ = machineid.ID()

// App struct
type App struct {
ctx context.Context
Expand All @@ -27,9 +38,34 @@ func NewApp() *App {

func (a *App) startup(ctx context.Context) {
a.ctx = ctx

// Sentry config
err := sentry.Init(sentry.ClientOptions{
Dsn: "https://[email protected]/6615295",
// Set TracesSampleRate to 1.0 to capture 100%
// of transactions for performance monitoring.
// We recommend adjusting this value in production,
TracesSampleRate: 1.0,
AttachStacktrace: true,
Environment: "production",
})
if err != nil {
log.Fatalf("sentry.Init: %s", err)
}

sentry.ConfigureScope(func(scope *sentry.Scope) {
scope.SetContext("infos", map[string]interface{}{
"version": version,
"machineId": machineId,
})
})

sentry.CaptureMessage("initial-event")
}

func (a *App) GetDeviceInfos() *lunii.Device {
defer sentry.Recover()

device, err := lunii.GetDevice()
if err != nil {
return nil
Expand All @@ -38,6 +74,8 @@ func (a *App) GetDeviceInfos() *lunii.Device {
}

func (a *App) ListPacks() []lunii.Metadata {
defer sentry.Recover()

device, err := lunii.GetDevice()
if err != nil {
return nil
Expand All @@ -50,6 +88,8 @@ func (a *App) ListPacks() []lunii.Metadata {
}

func (a *App) RemovePack(uuid uuid.UUID) (bool, error) {
defer sentry.Recover()

device, err := lunii.GetDevice()
if err != nil {
return false, err
Expand All @@ -69,6 +109,8 @@ func (a *App) RemovePack(uuid uuid.UUID) (bool, error) {
}

func (a *App) CreatePack(directoryPath string, destinationPath string) (string, error) {
defer sentry.Recover()

_, err := studiopackbuilder.CreateStudioPack(directoryPath, destinationPath)
if err != nil {
return "", err
Expand All @@ -77,13 +119,17 @@ func (a *App) CreatePack(directoryPath string, destinationPath string) (string,
}

func (a *App) OpenDirectory(title string) string {
defer sentry.Recover()

path, _ := runtime.OpenDirectoryDialog(a.ctx, runtime.OpenDialogOptions{
Title: title,
})
return path
}

func (a *App) SaveFile(title string, defaultDirectory string, defaultFileName string) string {
defer sentry.Recover()

fmt.Println("Select save path - options : ", defaultDirectory, defaultFileName)
path, _ := runtime.SaveFileDialog(a.ctx, runtime.SaveDialogOptions{
Title: title,
Expand All @@ -94,13 +140,16 @@ func (a *App) SaveFile(title string, defaultDirectory string, defaultFileName st
}

func (a *App) OpenFile(title string) string {
defer sentry.Recover()

path, _ := runtime.OpenFileDialog(a.ctx, runtime.OpenDialogOptions{
Title: title,
})
return path
}

func (a *App) InstallPack(packPath string) (string, error) {
defer sentry.Recover()

device, err := lunii.GetDevice()
studioPack, err := lunii.ReadStudioPack(packPath)
Expand All @@ -117,6 +166,7 @@ func (a *App) InstallPack(packPath string) (string, error) {
}

func (a *App) ChangePackOrder(uuid uuid.UUID, index int) (string, error) {
defer sentry.Recover()

fmt.Println("Moving ", uuid, index)

Expand All @@ -136,6 +186,8 @@ func (a *App) ChangePackOrder(uuid uuid.UUID, index int) (string, error) {
}

func (a *App) SyncLuniiStoreMetadata(uuids []uuid.UUID) (string, error) {
defer sentry.Recover()

device, err := lunii.GetDevice()
if err != nil {
return "", err
Expand All @@ -154,6 +206,8 @@ func (a *App) SyncLuniiStoreMetadata(uuids []uuid.UUID) (string, error) {
}

func (a *App) SyncStudioMetadata(uuids []uuid.UUID, dbPath string) (string, error) {
defer sentry.Recover()

device, err := lunii.GetDevice()
if err != nil {
return "", err
Expand All @@ -171,17 +225,65 @@ func (a *App) SyncStudioMetadata(uuids []uuid.UUID, dbPath string) (string, erro
return "", nil
}

func (a *App) CheckForUpdate() (bool, string, string) {
type CheckUpdateResponse struct {
CanUpdate bool `json:"canUpdate"`
LatestVersion string `json:"latestVersion"`
ReleaseNotes string `json:"releaseNotes"`
}

func (a *App) CheckForUpdate() (*CheckUpdateResponse, error) {
defer sentry.Recover()

latest, found, err := selfupdate.DetectLatest("olup/lunii-admin")
v := semver.MustParse("0.0.3")

trimmedVersion := strings.TrimPrefix(version, "v")
trimmedVersion = strings.TrimSuffix(trimmedVersion, "\n")

if trimmedVersion == "next" {
return &CheckUpdateResponse{
CanUpdate: false,
LatestVersion: "",
ReleaseNotes: "",
}, nil
}

v := semver.MustParse(trimmedVersion)

if err != nil {
log.Println("Error occurred while detecting version:", err)
return false, "", ""
return nil, err
}

if !found || latest.Version.LTE(v) {
log.Println("Current version is the latest")
return false, "", ""
return &CheckUpdateResponse{
CanUpdate: false,
LatestVersion: "",
ReleaseNotes: "",
}, nil
}
return true, latest.Version.String(), latest.ReleaseNotes

return &CheckUpdateResponse{
CanUpdate: true,
LatestVersion: latest.Version.String(),
ReleaseNotes: latest.ReleaseNotes,
}, nil
}

type Infos struct {
Version string `json:"version"`
MachineId string `json:"machineId"`
Os string `json:"os"`
Arch string `json:"arch"`
}

func (a *App) GetInfos() (*Infos, error) {
defer sentry.Recover()

return &Infos{
Version: version,
MachineId: machineId,
Os: goruntime.GOOS,
Arch: goruntime.GOARCH,
}, nil
}
84 changes: 32 additions & 52 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,82 +1,62 @@
import { Box, Button, Center, Icon, Text, Tooltip } from "@chakra-ui/react";
import { useQuery } from "@tanstack/react-query";
import { Box, Button, Center, Icon, Text } from "@chakra-ui/react";
import { BiPlug } from "react-icons/bi";
import {
FiPackage,
FiRefreshCcw,
FiSmartphone,
FiUpload,
} from "react-icons/fi";
import { Link, Route } from "wouter";
import { ListPacks } from "../wailsjs/go/main/App";
import { Route } from "wouter";
import { DetailsModal } from "./components/DetailsModal";
import { DeviceModal } from "./components/DeviceModal";
import { AboutModal } from "./components/AboutModal";
import { Header } from "./components/Header";
import { IsInstallingModal } from "./components/IsInstallingModal";
import { NewPackModal } from "./components/NewPackModal";
import { PackList } from "./components/PackList";
import { SyncMdMenu } from "./components/SyncMdMenu";
import { UpdateModal } from "./components/UpdateModal";
import { useDeviceQuery } from "./hooks/useApi";
import { useInstallPack } from "./hooks/useInstallPack";
import { FiRefreshCcw } from "react-icons/fi";

function App() {
const {
data: device,
refetch: refetchDevice,
isLoading: isLoadingDevice,
refetch: refetchDevice,
} = useDeviceQuery();

if (isLoadingDevice) return null;

return (
<Box id="App" p={3}>
<Box id="App">
<Route path="/create-pack">
<NewPackModal />
</Route>
<Route path="/device">
<DeviceModal />
<Route path="/about">
<AboutModal />
</Route>
<Route path="/pack/:id">
<DetailsModal />
</Route>
<Route path="/update">
<UpdateModal />
</Route>

{!device && (
<>
<Box display="flex">
<Tooltip label="Try refreshing after the device has been mounted by the system">
<Button
colorScheme="orange"
rightIcon={<FiRefreshCcw />}
onClick={() => refetchDevice()}
>
Refresh
</Button>
</Tooltip>
<Link to="/create-pack">
<Button
variant="ghost"
colorScheme="linkedin"
leftIcon={<FiPackage />}
ml={2}
>
Create pack
</Button>
</Link>
<Box pt="56px" height="100vh">
<Header />
{device && (
<Box p={3}>
<PackList />
</Box>
<Center opacity={0.3} fontSize={20} h={500} flexDirection="column">
<Icon as={BiPlug}></Icon>
)}

<Text>No device connected</Text>
{!device && (
<Center fontSize={20} h="100%" flexDirection="column">
<Icon as={BiPlug} opacity={0.3}></Icon>
<Text opacity={0.3} mb={4}>
No device connected
</Text>
<Button
rightIcon={<FiRefreshCcw />}
onClick={() => refetchDevice()}
>
Refresh
</Button>
</Center>
</>
)}

{device && (
<Box pt="56px">
<Header />
<PackList />
</Box>
)}
)}
</Box>
</Box>
);
}
Expand Down
Loading

0 comments on commit 5d56646

Please sign in to comment.