Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 50 additions & 11 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"desktop/internal"
"desktop/internal/api"
"errors"
"fmt"
"log"
"os"
"os/exec"
"strings"
Expand Down Expand Up @@ -64,11 +64,11 @@ func (a *App) startup(ctx context.Context) {
// startSchedulerWorker()
}

func (a *App) GetDownloadedImages() []string {
func (a *App) GetDownloadedImages() ([]string, error) {
selectedPath, err := appConf.Get("image.selected_abs_path")

if err != nil {
println(err)
return nil, err
}
path := selectedPath.(string)
var fp string = path
Expand All @@ -78,10 +78,10 @@ func (a *App) GetDownloadedImages() []string {
}
img, err := internal.GetAllFilesInDir(fp)
if err != nil {
println(err.Error())
return nil, err
}

return img
return img, nil
}

func (a *App) SelectImageDir() []string {
Expand All @@ -104,14 +104,14 @@ func (a *App) SelectImageDir() []string {
return imgs
}

func (a *App) DownloadImages() {
func (a *App) DownloadImages() error {
apikey, _ := appConf.Get("api.unsplash_apikey")
dp, _ := appConf.Get("image.selected_abs_path")
tot, _ := appConf.Get("api.download_limit")
cat, _ := appConf.Get("api.image_category")

if apikey == nil || dp == nil {
log.Fatal("Image path not set")
return fmt.Errorf("Image path not set")
}

var ct int
Expand Down Expand Up @@ -145,9 +145,13 @@ func (a *App) DownloadImages() {
err := deleteFilesWithPrefix(imagePath, "picasa_")

if err != nil {
log.Fatal("Error deleting images ", err.Error())
return fmt.Errorf("Error deleting images: %v ", err.Error())
}
if err := internal.FetchImages(c); err != nil {
return err
}
internal.FetchImages(c)

return nil
}

func (a *App) SetWallpaper(path string) {
Expand Down Expand Up @@ -243,14 +247,49 @@ func deleteFilesWithPrefix(dir, prf string) error {
return nil
}

func (a *App) GetGradient() error {
err := internal.GenerateGradientImage()
func (a *App) GetGradientImage(c []api.RGBA) error {
if len(c) == 0 {
return errors.New("no colors added")
}

err := internal.GenerateGradientImage(c[0], c[1])
if err != nil {
return err
}

return nil
}

func (a *App) GetHexToRGBA(color string) (api.RGBA, error) {
fmt.Println(color)
r, _ := internal.HexToRGBA(color)
fmt.Println(r)
return api.RGBA{}, nil
}

func (a *App) Testament() error {
return fmt.Errorf("Testament...")
}

// func (ax *App) GGradient(color string) interface{} {
//
// r, g, b, a, err := internal.HexToRGBA(color)
// if err != nil {
// log.Fatal(err)
// }
// res := struct {
// R int `json:"r"`
// G int `json:"g"`
// B int `json:"b"`
// A int `json:"a"`
// }{
// R: r,
// G: g,
// B: b,
// A: a,
// }
// return res
// }

// https://gist.github.com/stupidbodo/0db61fa874213a31dc57 - replacement for cronjob
// https://gist.github.com/harubaru/f727cedacae336d1f7877c4bbe2196e1#model-overview
1 change: 0 additions & 1 deletion frontend/dist/assets/no-image.7f4e8366.svg

This file was deleted.

4 changes: 2 additions & 2 deletions frontend/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
--main-color: orange;
}
</style>
<script type="module" crossorigin src="/assets/index.f16bcb2d.js"></script>
<link rel="stylesheet" href="/assets/index.77bdd74d.css">
<script type="module" crossorigin src="/assets/index.90bd1699.js"></script>
<link rel="stylesheet" href="/assets/index.6694263b.css">
</head>
<body class="dark:bg-gray-700 dark:text-gray-50">
<div id="app"></div>
Expand Down
17 changes: 14 additions & 3 deletions frontend/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,25 @@
import Setting from './pages/Setting.svelte';
import PlainArt from './pages/PlainArt.svelte';

import { Router, Route } from 'svelte-routing';
import type { SvelteComponentTyped } from 'svelte';
import {
Router as RouterComponent,
Route as RouteComponent,
} from 'svelte-routing';

const Router: typeof SvelteComponentTyped = RouterComponent;
const Route: typeof SvelteComponentTyped = RouteComponent;
import AbstractArt from './pages/AbstractArt.svelte';
import Ai from './pages/AI.svelte';
export let url = '';
</script>

<main>
<Router {url}>
<Route path="/setting" component={Setting} />
<Route path="/"><Main /></Route>
<Route path="/plain-art"><PlainArt /></Route>
<Route path="/ai" component={Ai} />
<!-- <Route path="/abstract-art" component={AbstractArt} /> -->
<Route path="/" component={Main} />
<Route path="/plain-art" component={PlainArt} />
</Router>
</main>
18 changes: 18 additions & 0 deletions frontend/src/components/CloseIcon.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<script lang="ts">
export let width = '1em';
</script>

<svg
{width}
style="text-align: center; display: inline-block;"
aria-hidden="true"
focusable="false"
role="img"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 352 512"
>
<path
fill="currentColor"
d="M242.72 256l100.07-100.07c12.28-12.28 12.28-32.19 0-44.48l-22.24-22.24c-12.28-12.28-32.19-12.28-44.48 0L176 189.28 75.93 89.21c-12.28-12.28-32.19-12.28-44.48 0L9.21 111.45c-12.28 12.28-12.28 32.19 0 44.48L109.28 256 9.21 356.07c-12.28 12.28-12.28 32.19 0 44.48l22.24 22.24c12.28 12.28 32.2 12.28 44.48 0L176 322.72l100.07 100.07c12.28 12.28 32.2 12.28 44.48 0l22.24-22.24c12.28-12.28 12.28-32.19 0-44.48L242.72 256z"
/>
</svg>
19 changes: 19 additions & 0 deletions frontend/src/components/ErrorIcon.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<script lang="ts">
export let width = '1em';
</script>

<svg
{width}
style="text-align: center; display: inline-block;"
aria-hidden="true"
focusable="false"
role="img"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 512 512"
>
<path
fill="currentColor"
d="M256 40c118.621 0 216 96.075 216 216 0 119.291-96.61 216-216 216-119.244 0-216-96.562-216-216 0-119.203 96.602-216 216-216m0-32C119.043 8 8 119.083 8 256c0 136.997 111.043 248 248 248s248-111.003 248-248C504 119.083 392.957 8 256 8zm-11.49 120h22.979c6.823 0 12.274 5.682 11.99 12.5l-7 168c-.268 6.428-5.556 11.5-11.99 11.5h-8.979c-6.433 0-11.722-5.073-11.99-11.5l-7-168c-.283-6.818 5.167-12.5 11.99-12.5zM256 340c-15.464 0-28 12.536-28 28s12.536 28 28 28 28-12.536 28-28-12.536-28-28-28z"
class=""
></path>
</svg>
18 changes: 18 additions & 0 deletions frontend/src/components/InfoIcon.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<script lang="ts">
export let width = '1em';
</script>

<svg
{width}
style="text-align: center; display: inline-block;"
aria-hidden="true"
focusable="false"
role="img"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 512 512"
>
<path
fill="currentColor"
d="M256 40c118.621 0 216 96.075 216 216 0 119.291-96.61 216-216 216-119.244 0-216-96.562-216-216 0-119.203 96.602-216 216-216m0-32C119.043 8 8 119.083 8 256c0 136.997 111.043 248 248 248s248-111.003 248-248C504 119.083 392.957 8 256 8zm-36 344h12V232h-12c-6.627 0-12-5.373-12-12v-8c0-6.627 5.373-12 12-12h48c6.627 0 12 5.373 12 12v140h12c6.627 0 12 5.373 12 12v8c0 6.627-5.373 12-12 12h-72c-6.627 0-12-5.373-12-12v-8c0-6.627 5.373-12 12-12zm36-240c-17.673 0-32 14.327-32 32s14.327 32 32 32 32-14.327 32-32-14.327-32-32-32z"
/>
</svg>
74 changes: 16 additions & 58 deletions frontend/src/components/ListImages.svelte
Original file line number Diff line number Diff line change
@@ -1,73 +1,31 @@
<script lang="ts">
import {
GetDownloadedImages,
SelectImageDir,
DownloadImages,
} from '../../wailsjs/go/main/App.js';

import { navigate } from 'svelte-routing';

import LoaderImage from '../../src/assets/images/loader.svg';
import { imagePathStore } from '../store/app';

import Modal from '../components/Modal.svelte';

import { onMount } from 'svelte';

import rpc from '../rpc';
let images: string[] = [];
export let images: string[];
let path: string = '';
let isFolderSelected: boolean = false;
let isLoading = true;

imagePathStore.subscribe((value) => {
path = value;
});

function dispatcher(image: string) {
console.log('Clicked...');
imagePathStore.set(image);
}

function setImagePath(image: string) {
path = image;
}

onMount(async (): Promise<any> => {
const result = await GetDownloadedImages();
images = result ?? [];
isLoading = false;

rpc.on('shortcut.page.setting', () => {
navigate('/setting', { replace: true });
});
});
</script>

<template>
<section class="w-[95%] mx-auto mt-14">
{#if isLoading}
<div class="mx-auto w-48 h-screen flex justify-center items-center">
<img src={LoaderImage} alt="" />
<h4 class="font-bold">Processing...</h4>
</div>
{:else}
<div class="flex flex-wrap justify-between">
{#each images as image}
<div
class="bg-gray-800 w-[300px] h-[300px] mb-3 cursor-default"
on:click={() => setImagePath(image)}
on:keydown={() => setImagePath(image)}
>
<img
src={image.toString()}
alt=""
class="object-cover h-[100%] w-[100%]"
/>
</div>
{/each}
</div>
{/if}
<div class="flex flex-wrap justify-between">
{#each images as image}
<div
class="bg-gray-800 w-[300px] h-[300px] mb-3 cursor-default"
on:click={() => setImagePath(image)}
on:keydown={() => setImagePath(image)}
>
<img
src={image.toString()}
alt=""
class="object-cover h-[100%] w-[100%]"
/>
</div>
{/each}
</div>
<Modal {path} />
</section>
</template>
30 changes: 9 additions & 21 deletions frontend/src/components/Navigation.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,14 @@
import DownloadImage from '../../src/assets/images/download.svg';
import ConfigImage from '../../src/assets/images/config.svg';

import PlainArtImage from '../../src/assets/images/plain.svg';

import AbstractArt from '../../src/assets/images/art.svg';

import AIArt from '../../src/assets/images/ai.svg';
import { dispatcher } from '../../src/utilities/util';

let isLoading = true;

let images: string[] = [];

async function downloadImages() {
try {
isLoading = true;
const res = await DownloadImages();
} catch (e) {
} finally {
const result = await GetDownloadedImages();
images = result ?? [];
isLoading = false;
}
dispatcher('downloading');
}
</script>

Expand All @@ -50,7 +38,7 @@
class="mr-1 dark:brightness-0 dark:invert-[1]"
/> Images</a
>

<!--
<a
href="/plain-art"
use:link
Expand All @@ -65,7 +53,7 @@
>

<a
href="#/"
href="/abstract-art"
class="dark:text-gray-50 text-gray-500 text-xs flex ml-10 hover:cursor-default"
>
<img
Expand All @@ -76,9 +64,8 @@
/> Abstract Art</a
>

<a
href="#/"
on:click={downloadImages}
<a
href="/ai"
class="dark:text-gray-50 text-gray-500 text-xs flex ml-10 hover:cursor-default"
>
<img
Expand All @@ -89,7 +76,7 @@
/> AI
</a>

<a
<a
href="#"
class="dark:text-gray-50 text-gray-500 text-xs flex ml-10 hover:cursor-default"
>
Expand All @@ -99,11 +86,12 @@
alt=""
class="mr-1 dark:brightness-0 dark:invert-[1]"
/> Upload folder</a
>
>-->
</div>
<div class="flex">
<a
href="#"
on:click|preventDefault={downloadImages}
class="dark:text-gray-50 text-gray-500 text-xs flex mr-5 hover:cursor-default"
>
<img
Expand Down
Loading
Loading