diff --git a/package.json b/package.json index fa5d515..7a7cb7c 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,6 @@ "neo-scraper": "^0.5.8", "normalize.css": "^8.0.1", "pinia": "^2.0.36", - "pinia-plugin-persistedstate": "^3.1.0", "vue-router": "4" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 251b4f5..77dbde2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -32,7 +32,6 @@ specifiers: normalize.css: ^8.0.1 npm-run-all: ^4.1.5 pinia: ^2.0.36 - pinia-plugin-persistedstate: ^3.1.0 rimraf: ^3.0.2 sass: ^1.57.1 typescript: ^4.9.3 @@ -54,7 +53,6 @@ dependencies: neo-scraper: 0.5.8 normalize.css: 8.0.1 pinia: 2.0.36_hmuptsblhheur2tugfgucj7gc4 - pinia-plugin-persistedstate: 3.1.0_pinia@2.0.36 vue-router: 4.1.6_vue@3.2.47 devDependencies: @@ -4974,14 +4972,6 @@ packages: engines: {node: '>=4'} dev: true - /pinia-plugin-persistedstate/3.1.0_pinia@2.0.36: - resolution: {integrity: sha512-8UN+vYMEPBdgNLwceY08mi5olI0wkYaEb8b6hD6xW7SnBRuPydWHlEhZvUWgNb/ibuf4PvufpvtS+dmhYjJQOw==} - peerDependencies: - pinia: ^2.0.0 - dependencies: - pinia: 2.0.36_hmuptsblhheur2tugfgucj7gc4 - dev: false - /pinia/2.0.36_hmuptsblhheur2tugfgucj7gc4: resolution: {integrity: sha512-4UKApwjlmJH+VuHKgA+zQMddcCb3ezYnyewQ9NVrsDqZ/j9dMv5+rh+1r48whKNdpFkZAWVxhBp5ewYaYX9JcQ==} peerDependencies: diff --git a/src/api/index.ts b/src/api/index.ts index 11e655a..4353129 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -82,7 +82,7 @@ export default class SzurubooruApi { async createPost(post: ScrapedPostDetails, contentToken?: string): Promise { const obj = { - tags: post.tags.map((x) => x.name), + tags: post.tags.map((x) => x.names[0]), safety: post.rating, source: post.source, notes: post.notes, diff --git a/src/background/main.ts b/src/background/main.ts index 8d7c3e6..1812ad3 100644 --- a/src/background/main.ts +++ b/src/background/main.ts @@ -46,7 +46,7 @@ async function uploadPost(data: PostUploadCommandData) { const tagsWithCategory = data.post.tags.filter((x) => x.category); const unsetCategoryTags = createdPost.tags .filter((x) => x.category == "default") - .filter((x) => tagsWithCategory.some((y) => x.names.includes(y.name))); + .filter((x) => tagsWithCategory.some((y) => x.names.includes(y.names[0]))); if (unsetCategoryTags.length != 0) { info.updateTagsState = { @@ -64,7 +64,7 @@ async function uploadPost(data: PostUploadCommandData) { info.updateTagsState.current = parseInt(i); pushInfo(); - const wantedCategory = tagsWithCategory.find((x) => tags[i].names.includes(x.name))?.category; + const wantedCategory = tagsWithCategory.find((x) => tags[i].names.includes(x.names[0]))?.category; if (wantedCategory) { if (existingCategories.some((x) => x.name == wantedCategory)) { tags[i].category = wantedCategory; diff --git a/src/composables/useStorageLocal.ts b/src/composables/useStorageLocal.ts new file mode 100644 index 0000000..5706dc9 --- /dev/null +++ b/src/composables/useStorageLocal.ts @@ -0,0 +1,28 @@ +import { storage } from "webextension-polyfill"; +import type { MaybeRef, RemovableRef, StorageLikeAsync, UseStorageAsyncOptions } from "@vueuse/core"; +import { useStorageAsync } from "@vueuse/core"; + +const storageLocal: StorageLikeAsync = { + removeItem(key: string) { + return storage.local.remove(key); + }, + + setItem(key: string, value: string) { + console.log("setItem"); + console.dir(value); + return storage.local.set({ [key]: value }); + }, + + async getItem(key: string) { + console.log("getItem"); + const item = (await storage.local.get(key))[key]; + console.dir(item); + return item; + }, +}; + +export const useStorageLocal = ( + key: string, + initialValue: MaybeRef, + options?: UseStorageAsyncOptions +): RemovableRef => useStorageAsync(key, initialValue, storageLocal, options); diff --git a/src/logic/common-setup.ts b/src/logic/common-setup.ts index 39861f9..993bbdd 100644 --- a/src/logic/common-setup.ts +++ b/src/logic/common-setup.ts @@ -3,11 +3,9 @@ import { library } from "@fortawesome/fontawesome-svg-core"; import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome"; import { faCog, faChevronDown, faChevronUp, faChevronLeft } from "@fortawesome/free-solid-svg-icons"; import { createPinia } from "pinia"; -import piniaPluginPersistedstate from "pinia-plugin-persistedstate"; export function setupPinia(app: App) { const pinia = createPinia(); - pinia.use(piniaPluginPersistedstate); app.use(pinia); } diff --git a/src/options/App.vue b/src/options/App.vue index e0b99f2..e1172ba 100644 --- a/src/options/App.vue +++ b/src/options/App.vue @@ -2,24 +2,18 @@ import { useColorMode } from "@vueuse/core"; import SzuruWrapper from "~/api"; import { SzuruSiteConfig } from "~/config"; -import { useConfigStore } from "~/stores"; +import { cfg } from "~/stores"; import { getErrorMessage } from "~/utils"; -let autoSearchSimilar = ref(false); -let loadTagCounts = ref(false); -let addPageUrlToSource = ref(false); -let statusText = ref(""); +let statusText = ref("Version " + browser.runtime.getManifest().version); let statusType = ref("status-quiet"); -let sites = reactive([]); -let selectedSiteId = ref(undefined); + const selectedSite = computed(() => { - if (selectedSiteId.value) { - return sites.find((x) => x.id == selectedSiteId.value); + if (cfg.value.selectedSiteId) { + return cfg.value.sites.find((x) => x.id == cfg.value.selectedSiteId); } }); -const configStore = useConfigStore(); - type StatusType = "success" | "error" | "quiet"; async function testConnection() { @@ -48,16 +42,6 @@ async function testConnection() { } } -async function saveSettings() { - configStore.sites = sites; - configStore.autoSearchSimilar = autoSearchSimilar.value; - configStore.loadTagCounts = loadTagCounts.value; - configStore.addPageUrlToSource = addPageUrlToSource.value; - configStore.selectedSiteId = selectedSiteId.value; - - setStatus("Settings successfully saved"); -} - function setStatus(text: string, type: StatusType = "success") { statusText.value = text; statusType.value = "status-" + type; @@ -65,31 +49,22 @@ function setStatus(text: string, type: StatusType = "success") { function addSite() { const site = new SzuruSiteConfig(); - sites.push(site); - selectedSiteId.value = site.id; + cfg.value.sites.push(site); + cfg.value.selectedSiteId = site.id; } function removeSelectedSite() { if (selectedSite.value) { - const idx = sites.indexOf(selectedSite.value); - sites.splice(idx, 1); + const idx = cfg.value.sites.indexOf(selectedSite.value); + cfg.value.sites.splice(idx, 1); + } + + // Select first site in list, if it exists. + if (cfg.value.sites.length > 0) { + cfg.value.selectedSiteId = cfg.value.sites[0].id; } } -onMounted(async () => { - statusText.value = "Version " + browser.runtime.getManifest().version; - - for (let site of configStore.sites) { - // This somehow makes `site` reactive. - sites.push(site); - } - - autoSearchSimilar.value = configStore.autoSearchSimilar; - loadTagCounts.value = configStore.loadTagCounts; - addPageUrlToSource.value = configStore.addPageUrlToSource; - selectedSiteId.value = configStore.selectedSiteId; -}); - let mode = useColorMode({ emitAuto: true }); @@ -105,8 +80,8 @@ let mode = useColorMode({ emitAuto: true });
- + @@ -154,7 +129,7 @@ let mode = useColorMode({ emitAuto: true });

@@ -165,7 +140,7 @@ let mode = useColorMode({ emitAuto: true });

@@ -177,7 +152,7 @@ let mode = useColorMode({ emitAuto: true });

@@ -192,7 +167,7 @@ let mode = useColorMode({ emitAuto: true });

- +
diff --git a/src/popup/pages/MergePost.vue b/src/popup/pages/MergePost.vue index 792fb38..4b51e0a 100644 --- a/src/popup/pages/MergePost.vue +++ b/src/popup/pages/MergePost.vue @@ -3,15 +3,14 @@ import { isEqual, cloneDeep } from "lodash"; import SzurubooruApi from "~/api"; import { Post, UpdatePostRequest } from "~/api/models"; import { BrowserCommand, PostUpdateCommandData, TagDetails } from "~/models"; -import { useConfigStore, useMergeStore, usePopupStore } from "~/stores"; +import { cfg, useMergeStore, usePopupStore } from "~/stores"; import { emptyPost, getUrl } from "~/utils"; const props = defineProps(["siteId", "postId"]); -const cfg = useConfigStore(); const merge = useMergeStore(); const pop = usePopupStore(); -const szuruConfig = cfg.sites.find((x) => x.id == props.siteId)!; +const szuruConfig = cloneDeep(cfg.value.sites.find((x) => x.id == props.siteId))!; const szuru = SzurubooruApi.createFromConfig(szuruConfig); // Used for the update post request. @@ -54,7 +53,7 @@ function addTag(tag: TagDetails) { tagsToAdd.push(tag); // Add implications for the tag - if (cfg.addTagImplications) { + if (cfg.value.addTagImplications) { tagsToAdd.push(...tag.implications); } } @@ -162,7 +161,7 @@ watch( ); watch( - () => cfg.merge.addMissingTags, + () => cfg.value.merge.addMissingTags, (value) => { if (value) { addMissingTags(); @@ -173,7 +172,7 @@ watch( ); watch( - () => cfg.merge.appendSource, + () => cfg.value.merge.appendSource, (value) => { if (value) { appendSources(); @@ -184,7 +183,7 @@ watch( ); watch( - () => cfg.merge.mergeSafety, + () => cfg.value.merge.mergeSafety, (value) => { if (value) { mergeSafety(); @@ -198,9 +197,9 @@ onMounted(async () => { existingPostRo = await szuru?.getPost(props.postId); if (existingPostRo) { post.value = cloneDeep(existingPostRo); - if (cfg.merge.appendSource) appendSources(); - if (cfg.merge.addMissingTags) addMissingTags(); - if (cfg.merge.mergeSafety) mergeSafety(); + if (cfg.value.merge.appendSource) appendSources(); + if (cfg.value.merge.addMissingTags) addMissingTags(); + if (cfg.value.merge.mergeSafety) mergeSafety(); if (scrapedPost?.resolution) { // Set imageToKeep depending on which image has the largest resolution. @@ -257,6 +256,29 @@ onMounted(async () => {
+ +
+
    +
  • + Tags: +{{ tagsToAdd.length }} + -{{ tagsRemoved }} +
  • +
  • + Sources: +2 + -1 +
  • +
  • + Safety: {{ existingPostRo?.safety }} {{ post.safety }} +
  • +
  • + Updating post content +
  • + + +
+
+
+
@@ -349,27 +371,6 @@ onMounted(async () => {
- - -
-
    -
  • - Tags: +{{ tagsToAdd.length }} - -{{ tagsRemoved }} -
  • -
  • - Sources: +2 - -1 -
  • -
  • - Safety: {{ existingPostRo?.safety }} {{ post.safety }} -
  • -
  • - Updating post content -
  • -
-
-
diff --git a/src/popup/pages/PopupMain.vue b/src/popup/pages/PopupMain.vue index ddcd2bc..c591f14 100644 --- a/src/popup/pages/PopupMain.vue +++ b/src/popup/pages/PopupMain.vue @@ -1,5 +1,6 @@