Skip to content

Commit

Permalink
Better validation of invalid sync states
Browse files Browse the repository at this point in the history
Signed-off-by: Marcus Crane <[email protected]>
  • Loading branch information
marcus-crane committed Jun 18, 2024
1 parent 9c02d49 commit 9516cbf
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 32 deletions.
9 changes: 9 additions & 0 deletions backend/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,16 @@ func (b *Backend) PromptForLocalDBPath() error {
}

func (b *Backend) ForwardToReadwise() (int, error) {
highlightBreakdown := b.Kobo.CountDeviceBookmarks()
if highlightBreakdown.Total == 0 {
logrus.Error("Tried to submit highlights when there are none on device.")
return 0, fmt.Errorf("Your device doesn't seem to have any highlights so there is nothing left to sync.")
}
includeStoreBought := b.Settings.UploadStoreHighlights
if !includeStoreBought && highlightBreakdown.Sideloaded == 0 {
logrus.Error("Tried to submit highlights with no sideloaded highlights + store-bought syncing disabled. Result is that no highlights would be fetched.")
return 0, fmt.Errorf("You have disabled store-bought syncing but you don't have any sideloaded highlights either. This combination means there are no highlights left to be synced.")
}
content, err := b.Kobo.ListDeviceContent(includeStoreBought)
if err != nil {
return 0, err
Expand Down
15 changes: 4 additions & 11 deletions backend/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ import (
)

type Settings struct {
path string `json:"-"`
ReadwiseToken string `json:"readwise_token"`
UploadCovers bool `json:"upload_covers"`
UploadStoreHighlights bool `json:"upload_store_highlights"`
UploadStorePromptShown bool `json:"upload_store_prompt_shown"`
path string `json:"-"`
ReadwiseToken string `json:"readwise_token"`
UploadCovers bool `json:"upload_covers"`
UploadStoreHighlights bool `json:"upload_store_highlights"`
}

func LoadSettings(portable bool) (*Settings, error) {
Expand Down Expand Up @@ -88,11 +87,5 @@ func (s *Settings) SaveCoverUploading(uploadCovers bool) error {

func (s *Settings) SaveStoreHighlights(uploadStoreHighlights bool) error {
s.UploadStoreHighlights = uploadStoreHighlights
s.UploadStorePromptShown = uploadStoreHighlights
return s.Save()
}

func (s *Settings) MarkUploadStorePromptShown() error {
s.UploadStorePromptShown = true
return s.Save()
}
Empty file removed frontend/dist/.gitkeep
Empty file.
12 changes: 1 addition & 11 deletions frontend/src/pages/Overview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ import { GetSettings, GetSelectedKobo, ForwardToReadwise } from "../../wailsjs/g
export default function Overview(props) {
const [settingsLoaded, setSettingsLoaded] = useState(false)
const [readwiseConfigured, setReadwiseConfigured] = useState(false)
const [uploadStorePromptSeen, setUploadStorePromptSeen] = useState(false)
const [selectedKobo, setSelectedKobo] = useState({})
const [highlightCounts, setHighlightCounts] = useState({})
const [storeUploadWarningOpen, setStoreUploadWarningOpen] = useState(false)
const [uploadStoreHighlights, setUploadStoreHighlights] = useState(false)

const cancelButtonRef = useRef(null)

Expand All @@ -30,7 +27,6 @@ export default function Overview(props) {
useEffect(() => {
GetSettings().then((settings) => {
setSettingsLoaded(true);
setUploadStorePromptSeen(settings.upload_store_prompt_shown)
setReadwiseConfigured(settings.readwise_token !== "")
setUploadStoreHighlights(settings.upload_store_highlights)
});
Expand All @@ -53,10 +49,8 @@ export default function Overview(props) {
.catch(err => {
if (err.includes("401")) {
toast.error("Received 401 Unauthorised from Readwise. Is your access token correct?", { id: toastId })
} else if (err.includes("failed to upload covers")) {
toast.error(err, { id: toastId })
} else {
toast.error(`There was a problem sending your highlights: ${err}`, { id: toastId })
toast.error(err, { id: toastId, duration: 8000 })
}
})
}
Expand Down Expand Up @@ -88,11 +82,7 @@ export default function Overview(props) {
<li>
<button onClick={() => {
if (readwiseConfigured) {
if (uploadStorePromptSeen || uploadStoreHighlights) {
syncWithReadwise()
} else {
setStoreUploadWarningOpen(true)
}
} else {
promptReadwise()
}
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/pages/Settings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import {
import {
SaveToken,
SaveCoverUploading,
SaveStoreHighlights,
MarkUploadStorePromptShown
SaveStoreHighlights
} from "../../wailsjs/go/backend/Settings";
import { CheckTokenValidity } from "../../wailsjs/go/backend/Readwise";

Expand Down
2 changes: 0 additions & 2 deletions frontend/wailsjs/go/backend/Settings.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT

export function MarkUploadStorePromptShown():Promise<void>;

export function Save():Promise<void>;

export function SaveCoverUploading(arg1:boolean):Promise<void>;
Expand Down
4 changes: 0 additions & 4 deletions frontend/wailsjs/go/backend/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT

export function MarkUploadStorePromptShown() {
return window['go']['backend']['Settings']['MarkUploadStorePromptShown']();
}

export function Save() {
return window['go']['backend']['Settings']['Save']();
}
Expand Down
2 changes: 0 additions & 2 deletions frontend/wailsjs/go/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ export namespace backend {
readwise_token: string;
upload_covers: boolean;
upload_store_highlights: boolean;
upload_store_prompt_shown: boolean;

static createFrom(source: any = {}) {
return new Settings(source);
Expand All @@ -217,7 +216,6 @@ export namespace backend {
this.readwise_token = source["readwise_token"];
this.upload_covers = source["upload_covers"];
this.upload_store_highlights = source["upload_store_highlights"];
this.upload_store_prompt_shown = source["upload_store_prompt_shown"];
}
}

Expand Down

0 comments on commit 9516cbf

Please sign in to comment.