-
-
Notifications
You must be signed in to change notification settings - Fork 164
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
Auto export snapshots #1047
Auto export snapshots #1047
Conversation
Thank you for starting work on it! It's an implementation of #876 (if I'm not mistaken), and I'll merge it when it's done. A few first thoughts:
|
Cool. Glad you're into it. I will also need feedback about the refactoring i did... Moving some functions to the actions file that were previously in the Vue file and splitting prepare and export. I'll also need an explanation of what happens in minify snapshot, cuz it kept me very busy trying to understand what it means for a tab to equal -1 |
Refactoring is ok. Cleaning up of the
It means that the value is the same as in the previous snapshot (
Call the Also, please, use prettier: |
should i take time to get this happening automatically on save via eslint? or you prefer the manual step? also, |
ok, maybe i ran into some of those situations, but i anyway managed to work around them by calling auto export before the minification... and many thanks for the explanations and collaboration! |
I meant to selectively run prettier only for changed files, but never mind, I'll setup a Github action to automate this on PR, so you don't need to run prettier manually. (I'll also update
thank You for spending your time on this |
i do agree that it might have been better, but it is not so easy for me to revert those changes line by line. How important is it for you @mbnuqw ? Do you like the feature idea in general? (i find it really nice for pasting or importing into nested knowledge tools like Logseq) |
do you have any time for an interim code review? features are basically working now, and I'll take some more time to clean up and review over the weekend. |
Sorry for delay.
Not much, leave the features as they are.
Yes, and it already was planned (but after v5 release), so it's good to have it implemented earlier. Testing:Possibly wrong indent in md output with "Tree Friendly MD (add extra bullets for windows and tabs)":
It looks like Panel 1 is sub-element of the last pinned tab. What if we use this structure?:
Auto-export doesn't work with an empty path ("Path to Export to (relative to downloads)").It should have the default value ("./" or maybe "./Snapshots" folder). Firefox always asks (if configured in FF settings) where to save for auto-created snapshot.It steals focus and will annoy users. We should use "json" and "both" format options doesn't work |
const dt = new Date(ms) | ||
let time = `${dt.getHours()}`.padStart(2, '0') | ||
time += delimiter + `${dt.getMinutes()}`.padStart(2, '0') | ||
if (min) time += delimiter + `${dt.getMinutes()}`.padStart(2, '0') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove min
argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'd like to keep it for a later option i have in mind (if its harmless enough for you)
src/types/settings.ts
Outdated
@@ -1,6 +1,7 @@ | |||
import { SETTINGS_OPTIONS } from '../defaults' | |||
|
|||
export interface SettingsState { | |||
[x: string]: any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove [x: string]: any
src/services/snapshots.actions.ts
Outdated
import { Containers } from './containers' | ||
import { DEFAULT_CONTAINER_ID } from 'src/defaults/containers' | ||
import { PanelType } from 'src/types/sidebar' | ||
import { ItemInfo } from 'src/types/tabs' | ||
import { Info } from './info' | ||
import { createDefaultSidebarConfig, getSidebarConfigFromV4 } from './sidebar-config' | ||
import { Favicons } from './favicons' | ||
import { nextTick } from 'vue' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove import { nextTick } from 'vue'
(b/c it's unused, and I'm trying to import view lib only in components and top-lvl scripts like sidebar.ts or setup.ts)
waiting = await Promise.allSettled([ | ||
browser.storage.local.get<Stored>(['sidebar', 'containers', 'snapshots']), | ||
Tabs.updateBgTabsTreeData(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert this change (I guess it's a debugging, but just to be sure)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think i added that, rather just moved it from the old location, I'll try with and without it... And remove if not needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
waiting = await Promise.allSettled([
browser.storage.local.get<Stored>(['sidebar', 'containers', 'snapshots']),
Tabs.updateBgTabsTreeData(),
])
console.log('updateBgTabsTreeData')
await Tabs.updateBgTabsTreeData(), console.log('getting store')
waiting = await Promise.allSettled([
browser.storage.local.get<Stored>(['sidebar', 'containers', 'snapshots']),
])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this actally better in "parallel" in the allSettled array below? or ok to do it first?
src/services/snapshots.actions.ts
Outdated
export async function exportSnapshot(snapshot: Snapshot) { | ||
const prepared = await prepareExport(snapshot) | ||
if (!prepared || !browser?.downloads) | ||
return console.warn('failed attempt to export snapshot', { snapshot, prepared, browser }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use internal Logs.warn('Snapshots.exportSnapshot: Cannot export snapshot')
@@ -467,7 +506,7 @@ async function adaptTabsPanels(snapshot: NormalizedSnapshot): Promise<void> { | |||
} | |||
|
|||
for (const storedId of stored.sidebar.nav) { | |||
const storedPanel = stored.sidebar.panels[storedId] | |||
const storedPanel = stored.sidebar?.panels?.[storedId] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
|
||
let panelState = panelsById[tab.panelId] | ||
if (!panelState) { | ||
let panelConfig = snapshot.sidebar?.panels?.[tab.panelId] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for optional chaining (b/c type is NormilizedSnapshot
)
@@ -683,7 +827,8 @@ export function convertFromV4(oldSnapshots: Snapshot_v4[]): Snapshot[] { | |||
|
|||
// Check panel | |||
if (snapTab.panelId !== -1) { | |||
const panelConf = snapshot.sidebar.panels[snapTab.panelId] | |||
const panelConf = snapshot.sidebar?.panels?.[snapTab.panelId] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to opt chaining b/c snapshot is NormilizedSnapshot
and sidebar is SidebarConfig
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌🙏
|
||
// if(!parsed)return | ||
const { id, time, containers, sidebar, tabs } = snapshot //parsed | ||
const normSnapshot = { id, time, containers, sidebar, tabs } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const normSnapshot
is not NormalizedSnapshot
and that may cause issues in convertToMarkdown
fn. It's better to use NormalizedSnapshot
type instead of Snapshot | SnapshotState
and update:
exportSnapshot(...)
toexportSnapshot(snapshot: NormalizedSnapshot)
- in
createSnapshot(...)
fn, pass aNormalizedSnapshot
- compatible type instead of theSnapshot
to theexportSnapshot()
:
if (Settings.state.snapAutoExport) {
void exportSnapshot(currentSnapshot)
}
with
if (Settings.state.snapAutoExport) {
exportSnapshot({
id: currentSnapshot.id,
time: currentSnapshot.time,
containers: stored.containers,
sidebar: stored.sidebar,
tabs,
})
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/services/snapshots.actions.ts
Outdated
return { id, time, containers, sidebar, tabs, jsonFile, mdFile } | ||
} | ||
|
||
export async function getMostRecentSnapshot() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getMostRecentSnapshot, getMostRecentSnapshotMd are not used, remove?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i thought i would need them, and still might if we want to decouple timing of snapshot creation and export.
i can remove them for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great Thanks for the detailed review! Looking forward to get this ready to merge... |
> - ## Window 1
> - ### Pinned tabs
> - Tab 1 (pinned)
> - Tab 2 (pinned)
> - ### Panel 1
> - Tab 3 just started on this adjustment and realized that technically the pinned tabs "live" within the panels. this indicates a structure like this may be better: - ## Window 1
- ### Panel 1 Base
- Pinned
- Tab 1 (pinned)
- Tab 2 (pinned)
- non-pinned Tab 3 ...
** OR **
- ### Panel 2 - Media
- Tab 1 (pinned)
- Tab 2 (pinned)
- non-pinned Tab 3 ... |
Hm... you're right, We need to change the way how snapshot is created to distinguish the global pinned tabs (e.g. with tab.panelId === -1) and per-panel (tab.panelId === "PANEL_ID"), because right now it's not possible to get the type of pinned tab. I can do this after this PR will be merged. |
- ## Window 1
- ### Panel 1 Base
- Pinned
- Tab 1 (pinned)
- Tab 2 (pinned)
- non-pinned Tab 3 ...
** OR **
- ### Panel 2 - Media
- Tab 1 (pinned)
- Tab 2 (pinned)
- non-pinned Tab 3 ... Both variants are ok, but the second is better b/c we don't need to translate to other languages "Pinned" (considering that the pinned tabs are marked with 📌). |
Also semantically feels better to me... |
great that you can do that after merge! it works now (onezoomin@73b62c0) but feels rather hackish to remerge the pinned tabs that belong in the panels. |
I ran out of time for this week... if you want to finish these up, please feel free... otherwise i'll try to squeeze in some time later next week!
|
Alright, thank you for your time. I'll try to finish this and publish a new release soon. |
🙏 |
1 similar comment
🙏 |
work in progress, very interested in feedback
i want to have snapshots show up in my logseq graph automatically... so i hacked together this mvp
@mbnuqw i really dig the architecture... very easy to dive into your code (mostly ; -)