Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customize automatic syncing #2

Closed
Scarvy opened this issue Nov 10, 2024 · 3 comments
Closed

Customize automatic syncing #2

Scarvy opened this issue Nov 10, 2024 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@Scarvy
Copy link
Owner

Scarvy commented Nov 10, 2024

Similar to the official Obsidian-Readwise plugin settings, add an option for users to select automatic syncing at specific intervals (e.g., Every 1 hour, Every 12 hours, Every 24 hours, Every week).

The default option would be Manual and these options will be stored in the user's settings like folder, currentAccount, and defaultAccount

@Scarvy Scarvy added the enhancement New feature or request label Nov 10, 2024
@Scarvy Scarvy self-assigned this Nov 10, 2024
@Scarvy Scarvy changed the title Customize automatic syncing - daily, weekly, monthly Customize automatic syncing Nov 13, 2024
@Scarvy
Copy link
Owner Author

Scarvy commented Nov 15, 2024

Add option to select different sync frequencies and a toast message for user confirmation of settings change.

image

Screenshot 2024-11-15 at 3 19 35 PM

@Scarvy
Copy link
Owner Author

Scarvy commented Nov 17, 2024

Add switch to toggle sync when the app opens

Image

@Scarvy
Copy link
Owner Author

Scarvy commented Nov 17, 2024

Code for triggerOnLoad is set to true

const triggerOnLoad = Boolean(store.get('triggerOnLoad'))
      console.log('Trigger on load: ', triggerOnLoad)
      if (triggerOnLoad) {
        // if sync is already in progress, don't start another one
        if (Boolean(store.get('isSyncing'))) {
          mainWindow.webContents.send('toast:show', { variant: 'default', message: 'Sync already in progress...'})
          console.log('Sync already in progress')
          return
        }

        mainWindow.webContents.send('toast:show', { variant: 'default', message: 'Initiating sync...'})
        const readwiseSync = new ReadwiseSync(mainWindow, store)
        readwiseSync.syncHighlights(undefined, true)
        console.log('Syncing highlights on load')
      }

Configure sync schedule:

ipcMain.handle('update-sync-frequency', async (_event, frequency: string) => {
  return await configureScheduledSync(frequency)
})

async function configureScheduledSync(frequency: string) {
  const minutes = parseInt(frequency)
  let milliseconds = minutes * 60 * 1000 // convert minutes to milliseconds
  console.log("Settings interval to ", milliseconds)
  if (!milliseconds) {
    // user set frequency to "Manual"
    return '0'
  }
  setInterval(async () => {
    console.log('Syncing highlights...', new Date())
    const readwiseSync = new ReadwiseSync(mainWindow, store)
    await readwiseSync.syncHighlights(undefined, true)
  }, milliseconds)
  return frequency
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant