Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
evandor committed Oct 14, 2024
1 parent ca85ccc commit 85f4755
Show file tree
Hide file tree
Showing 12 changed files with 218 additions and 67 deletions.
4 changes: 4 additions & 0 deletions src-bex/tabsets-content-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export default bexContent((bridge: any) => {
}

console.log("tabsets: initializing content script for tab analysis...")
// chrome.storage.local.get(["excalidraw"], (res) => {
// console.log("res", res)
// })
// chrome.storage.local.set({"test": "test"})
// @ts-ignore
window.contentScriptAnalysisAlredyCalled = true

Expand Down
16 changes: 12 additions & 4 deletions src/app/BrowserApi.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import {Tabset} from "src/tabsets/models/Tabset";
import {CLEANUP_PERIOD_IN_MINUTES, MONITORING_PERIOD_IN_MINUTES} from "boot/constants";
import {CLEANUP_PERIOD_IN_MINUTES, GITHUB_AUTO_BACKUP, MONITORING_PERIOD_IN_MINUTES} from "boot/constants";
import _ from "lodash"
import NavigationService from "src/services/NavigationService";
import IndexedDbPersistenceService from "src/services/IndexedDbPersistenceService";
import {Tab} from "src/tabsets/models/Tab";
import {uid} from "quasar";
import {LocalStorage, uid} from "quasar";
import {FeatureIdent} from "src/app/models/FeatureIdent";
import {useWindowsStore} from "src/windows/stores/windowsStore";
import {Router} from "vue-router";
import {useTabsetsStore} from "src/tabsets/stores/tabsetsStore";
import {useTabsetService} from "src/tabsets/services/TabsetService2";
import {useFeaturesStore} from "src/features/stores/featuresStore";
import IndexedDbRequestPersistence from "src/requests/persistence/IndexedDbRequestPersistence";
import {useRequestsService} from "src/requests/services/ContentService";
import {useCommandExecutor} from "src/core/services/CommandExecutor";
import {GithubBackupCommand} from "src/tabsets/commands/GithubBackupCommand";


function runHousekeeping() {
Expand Down Expand Up @@ -49,6 +50,9 @@ class BrowserApi {
console.debug(" ...initializing ChromeApi")

chrome.alarms.create("housekeeping", {periodInMinutes: CLEANUP_PERIOD_IN_MINUTES})

chrome.alarms.create("hourlyTasks", {periodInMinutes: 30})

chrome.alarms.create("monitoring", {periodInMinutes: MONITORING_PERIOD_IN_MINUTES})

chrome.alarms.onAlarm.addListener(
Expand All @@ -61,6 +65,10 @@ class BrowserApi {
// if (useFeaturesStore().hasFeature(FeatureIdent.MONITORING)) {
// checkMonitors(router)
// }
} else if (alarm.name === "hourlyTasks") {
if (LocalStorage.getItem(GITHUB_AUTO_BACKUP) as boolean) {
useCommandExecutor().execute(new GithubBackupCommand());
}
} else {
console.log("unknown alarm", alarm)
}
Expand Down Expand Up @@ -137,7 +145,7 @@ class BrowserApi {
// contexts: ['all']
// })
//}
// console.debug(" > context menu: save_to_currentTS")
// console.debug(" > context menu: save_to_currentTS")
chrome.contextMenus.create({
id: 'save_to_currentTS',
parentId: 'tabset_extension',
Expand Down
21 changes: 20 additions & 1 deletion src/app/listeners/BrowserListeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import NavigationService from "src/services/NavigationService";
import ContentUtils from "src/core/utils/ContentUtils";
import {EMAIL_LINK_REDIRECT_DOMAIN} from "boot/constants";
import {useUiStore} from "src/ui/stores/uiStore";
import {Tabset, TabsetType} from "src/tabsets/models/Tabset";
import {useWindowsStore} from "src/windows/stores/windowsStore";
import {Tab} from "src/tabsets/models/Tab";
import {useTabsetService} from "src/tabsets/services/TabsetService2";
Expand Down Expand Up @@ -272,6 +271,7 @@ class BrowserListeners {
if (tab.url && tab.url.startsWith("https://shared.tabsets.net")) {
return
}

BrowserApi.addIndicatorIcon(tab.id, tab.url)
}

Expand All @@ -294,6 +294,25 @@ class BrowserListeners {

await setCurrentTab()

// debugger
// //const fromPageLocalStore = await chrome.scripting.executeScript({ target: { tabId: info.tabId }}, () => {localStorage['excalidraw']});
// const returned = await chrome.scripting.executeScript({
// target: {tabId: info.tabId},
// func: (items) => {
// //Object.keys(items).forEach((key) => {
// localStorage.setItem("tabsetkey", "tabsetvalue")
// const res = localStorage.getItem("excalidraw")
// console.log("got res", res)
// return res
// //})
// },
// args: ['excalidraw'] // pass any parameters to function
// })
// console.log("returned", returned)


//console.log("fromPage", fromPageLocalStore)

chrome.tabs.get(info.tabId, tab => {
if (chrome.runtime.lastError) {
console.warn("got runtime error:" + chrome.runtime.lastError);
Expand Down
8 changes: 7 additions & 1 deletion src/boot/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ const CURRENT_USER_EMAIL = "current.user.email"

const UI_WINDOWS_ITEMS_PER_PAGE = 'ui.windows.itemsPerPage'

const GITHUB_USERNAME = "github.username"
const GITHUB_REPONAME = "github.reponame"
const GITHUB_TOKEN = "github.token"
const GITHUB_AUTO_BACKUP = "github.autobackup"

export default boot(({}) => {
})

Expand All @@ -59,6 +64,7 @@ export {
EMAIL_LINK_REDIRECT_DOMAIN,
CURRENT_USER_ID,
CURRENT_USER_EMAIL,
UI_WINDOWS_ITEMS_PER_PAGE
UI_WINDOWS_ITEMS_PER_PAGE,
GITHUB_USERNAME, GITHUB_REPONAME, GITHUB_TOKEN, GITHUB_AUTO_BACKUP
}

2 changes: 1 addition & 1 deletion src/notes
50 changes: 7 additions & 43 deletions src/pages/SettingsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
v-if="useFeaturesStore().hasFeature(FeatureIdent.ARCHIVE_TABSET)"/>
<q-tab name="search" label="Search Engine" v-if="useFeaturesStore().hasFeature(FeatureIdent.DEV_MODE)"/>
<q-tab name="importExport" label="Import/Export"/>
<q-tab name="backup" label="Backup"/>
<q-tab name="internals" label="Internals" v-if="useFeaturesStore().hasFeature(FeatureIdent.DEV_MODE)"/>
<!-- <q-tab name="featureToggles" label="Feature Toggles"-->
<!-- :class="useAuthStore().userMayAccess(AccessItem.FEATURE_TOGGLES) ? 'text-primary':'text-grey'"/>-->
Expand Down Expand Up @@ -341,45 +342,12 @@

<div v-if="tab === 'importExport'">

<div class="q-pa-md q-gutter-sm">

<q-banner rounded style="border:1px solid orange">You can export your data in various formats and re-import them
from json. Please
note that it is not guaranteed that older exports can be imported with newer versions of the tabsets
extension.
</q-banner>

<div class="row q-pa-md">
<div class="col-3"><b>Export</b></div>
<div class="col-3">json or as bookmarks</div>
<div class="col-1"></div>
<div class="col-5">
<q-btn
@click="showExportDialog"
flat round dense icon="file_download" color="primary">
<q-tooltip>Export your tabsets</q-tooltip>
</q-btn>
</div>
</div>

<div class="row q-pa-md">
<div class="col-3"><b>Import</b></div>
<div class="col-3">
from json<br>
You might need to restart tabsets.
</div>
<div class="col-1"></div>
<div class="col-5">
<q-btn
@click="showImportDialog"
flat round dense icon="file_upload" color="primary">
<q-tooltip>Import your tabsets backup</q-tooltip>
</q-btn>
</div>
</div>
<ImportExportSettings />

</div>
</div>

<div v-if="tab === 'backup'">
<BackupSettings />
</div>

<div v-if="tab === 'featureToggles'">
Expand Down Expand Up @@ -418,19 +386,18 @@ import {
STRIP_CHARS_IN_USER_INPUT,
TITLE_IDENT
} from "boot/constants";
import {useAuthStore} from "stores/authStore";
import InfoLine from "pages/helper/InfoLine.vue";
import FeatureToggleSettings from "pages/helper/FeatureToggleSettings.vue";
import {useI18n} from "vue-i18n";
import {useTabsetsStore} from "src/tabsets/stores/tabsetsStore";
import {useFeaturesStore} from "src/features/stores/featuresStore";
import VueJsonPretty from "vue-json-pretty";
import 'vue-json-pretty/lib/styles.css';
import ExportDialog from "src/tabsets/dialogues/ExportDialog.vue";
import ImportDialog from "src/tabsets/dialogues/ImportDialog.vue";
import {useGroupsStore} from "../tabsets/stores/groupsStore";
import OpenRightDrawerWidget from "src/ui/widgets/OpenRightDrawerWidget.vue";
import {usePermissionsStore} from "stores/usePermissionsStore";
import BackupSettings from "pages/helper/BackupSettings.vue";
import ImportExportSettings from "pages/helper/ImportExportSettings.vue";
const { t } = useI18n()
Expand Down Expand Up @@ -588,9 +555,6 @@ const simulateNewVersion = (version: string) => NavigationService.updateAvailabl
const restoreHints = () => useUiStore().restoreHints()
const showExportDialog = () => $q.dialog({component: ExportDialog, componentProps: {inSidePanel: true}})
const showImportDialog = () => $q.dialog({component: ImportDialog, componentProps: {inSidePanel: true}})
const simulateStaticSuggestion = () => {
const suggestions: [Suggestion] = [
// @ts-ignore
Expand Down
29 changes: 15 additions & 14 deletions src/pages/SidePanelPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -280,23 +280,24 @@ if (inBexMode()) {
useUiStore().draggingTab(message.data.tabId, null as unknown as any)
} else if (message.name === "note-changed") {
// TODO needed?
const tabset = useTabsetsStore().getTabset(message.data.tabsetId) as Tabset
if (message.data.noteId) {
console.log("updating note", message.data.noteId)
const res = useTabsetsStore().getTabAndTabsetId(message.data.noteId)
//.then((res: TabAndTabsetId | undefined) => {
if (res) {
const note = res.tab
note.title = message.data.tab.title
note.description = message.data.tab.description
note.longDescription = message.data.tab.longDescription
}
useTabsetService().saveTabset(tabset)
//const tabset = useTabsetsStore().getTabset(message.data.tabsetId) as Tabset
if (message.data.notebookId) {
console.log("updating notebook/tabset", message.data.notebookId, message.data.tabsetId)
useTabsetService().reloadTabset(message.data.tabsetId)
// const res = useTabsetsStore().getTabAndTabsetId(message.data.noteId)
// //.then((res: TabAndTabsetId | undefined) => {
// if (res) {
// const note = res.tab
// note.title = message.data.tab.title
// note.description = message.data.tab.description
// note.longDescription = message.data.tab.longDescription
// }
// useTabsetService().saveTabset(tabset)
// })
} else {
console.log("adding tab", message.data.tab)
tabset.tabs.push(message.data.tab)
useTabsetService().saveTabset(tabset)
//tabset.tabs.push(message.data.tab)
//useTabsetService().saveTabset(tabset)
}
} else if (message.name === "tab-added") {
// hmm - getting this twice...
Expand Down
90 changes: 90 additions & 0 deletions src/pages/helper/BackupSettings.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<template>
<div class="q-pa-md q-gutter-sm">


<q-banner rounded style="border:1px solid orange">Backup your tabsets to a public github repository of your choice.
</q-banner>

<div class="row q-pa-md">
<div class="col-3"><b>Username</b></div>
<div class="col-3">Your github username</div>
<div class="col-1"></div>
<div class="col-5">
<q-input v-model="username" dense label="Username"/>
</div>
</div>

<div class="row q-pa-md">
<div class="col-3"><b>Repository</b></div>
<div class="col-3">A preferrably empty public repository</div>
<div class="col-1"></div>
<div class="col-5">
<q-input v-model="reponame" dense label="Repository Name"/>
</div>
</div>

<div class="row q-pa-md">
<div class="col-3"><b>GitHub Access Token</b></div>
<div class="col-3">Click <a href="https://github.com/settings/tokens" target="_blank">here</a> to create a new
token (use scope <em>public_repo</em>).
</div>
<div class="col-1"></div>
<div class="col-5">
<q-input v-model="githubToken" type="password" dense label="Github Token"/>
</div>
</div>

<div class="row q-pa-md" v-if="username && reponame && githubToken">
<div class="col-3"><b>Save</b></div>
<div class="col-3">
<q-checkbox v-model="autobackup" label="Automatically daily backup"/>
</div>
<div class="col-1"></div>
<div class="col-5">
<q-btn dense label="Backup now" @click="runGithubBackup()"/>
</div>
</div>


</div>
</template>

<script lang="ts" setup>
import {ref, watchEffect} from "vue";
import {LocalStorage} from "quasar";
import {useCommandExecutor} from "src/core/services/CommandExecutor";
import {GithubBackupCommand} from "src/tabsets/commands/GithubBackupCommand";
import {GITHUB_AUTO_BACKUP, GITHUB_REPONAME, GITHUB_TOKEN, GITHUB_USERNAME} from "boot/constants";
const username = ref<string>(LocalStorage.getItem(GITHUB_USERNAME) as string)
const reponame = ref<string>(LocalStorage.getItem(GITHUB_REPONAME) as string)
const githubToken = ref<string>(LocalStorage.getItem(GITHUB_TOKEN) as string)
const autobackup = ref<boolean>(LocalStorage.getItem(GITHUB_AUTO_BACKUP) || false)
watchEffect(() => {
(username.value && username.value.trim().length > 0)
? LocalStorage.set(GITHUB_USERNAME, username.value)
: LocalStorage.remove(GITHUB_USERNAME)
})
watchEffect(() => {
(reponame.value && reponame.value.trim().length > 0)
? LocalStorage.set(GITHUB_REPONAME, reponame.value)
: LocalStorage.remove(GITHUB_REPONAME)
})
watchEffect(() => {
(githubToken.value && githubToken.value.trim().length > 0)
? LocalStorage.set(GITHUB_TOKEN, githubToken.value)
: LocalStorage.remove(GITHUB_TOKEN)
})
watchEffect(() => {
LocalStorage.set(GITHUB_AUTO_BACKUP, autobackup.value)
})
const runGithubBackup = () => {
useCommandExecutor().executeFromUi(new GithubBackupCommand())
}
</script>
Loading

0 comments on commit 85f4755

Please sign in to comment.