Skip to content

Commit

Permalink
Add Portable Sketch Book format
Browse files Browse the repository at this point in the history
  • Loading branch information
kpicaza committed Oct 13, 2023
1 parent 0425fe7 commit 7c7a080
Show file tree
Hide file tree
Showing 33 changed files with 719 additions and 136 deletions.
64 changes: 64 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
APP_NAME="Open Sketch"
APP_ENV=local
APP_KEY=base64:CtMJILvYQpvcoSlICeIOJZggQgmNOemBJNs8Sn8Rzz0=
APP_DEBUG=true
APP_URL=opensketch://

LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

DB_CONNECTION=sqlite
DB_DATABASE=database/open_sketch_test.sqlite

BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DISK=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

MEMCACHED_HOST=127.0.0.1

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=mailpit
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_HOST=
PUSHER_PORT=443
PUSHER_SCHEME=https
PUSHER_APP_CLUSTER=mt1

VITE_APP_NAME="${APP_NAME}"
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
VITE_PUSHER_HOST="${PUSHER_HOST}"
VITE_PUSHER_PORT="${PUSHER_PORT}"
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

NATIVEPHP_APP_ID="OpenSketch"
NATIVEPHP_APP_VERSION="0.5.0"
NATIVEPHP_DEEPLINK_SCHEME=opensketch
NATIVEPHP_DOCUMENTS_PATH="/home/${USER}/Documents"

GITHUB_REPO=open-sketch
GITHUB_OWNER=kpicaza
GITHUB_TOKEN=
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@ provides the tools you need.

* [x] Open New Sketch Books
* [x] Open Existing Sketch Books
* [x] Portable Sketch Book format

### Simple Paint

* [x] Static size painting canvas
* [x] Default "Pen" Brush
* [x] Brush Color
* [x] Brush Size

### Drawing Palette

Expand Down
4 changes: 4 additions & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

class Kernel extends ConsoleKernel
{
protected $commands = [
\Native\Laravel\Commands\LoadStartupConfigurationCommand::class,
];

/**
* Define the application's command schedule.
*/
Expand Down
37 changes: 26 additions & 11 deletions app/Listeners/OpenDocumentWindow.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,51 @@
use Illuminate\Support\Facades\Storage;
use Native\Laravel\Dialog;
use Native\Laravel\Facades\Window;
use OpenSketch\SketchBook\Domain\Command\ResetSketchBookLocationCommand;
use OpenSketch\SketchBook\Domain\Handler\ResetSketchBookLocation;

class OpenDocumentWindow
{
public function __construct(
private ResetSketchBookLocation $resetSketchBookLocation
) {
}

public function handle(DocumentOpened $event): void
{
$storagePath = Storage::disk('user_documents')->path('OpenSketch');
/** @var \Native\Laravel\Windows\WindowManager $window */
$window = Window::getFacadeRoot();
$path = Dialog::new()
->title('Open Sketch Book')
->asSheet()
->asSheet('welcome')
->defaultPath($storagePath)
->open();

if (null === $path) {
return;
}

$sketchBookData = json_decode(
Storage::get(str_replace(
storage_path('app'),
'',
$path
)),
true
);
$command = ResetSketchBookLocationCommand::withIdAndPath(
$sketchBookData['id'],
$path
);

$sketchBookId = $this->resetSketchBookLocation->handle($command);

/** @var \Native\Laravel\Windows\WindowManager $window */
$window = Window::getFacadeRoot();
Window::open('welcome');
Window::close('sketch-book');
Window::open('sketch-book')
->hideMenu(false)
->route('sketch-book', json_decode(
Storage::get(str_replace(
storage_path('app'),
'',
$path
)),
true
))
->route('sketch-book', ['id' => $sketchBookId])
;
$window->maximize('sketch-book');

Expand Down
25 changes: 15 additions & 10 deletions app/Listeners/StoreDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,47 @@
use Illuminate\Support\Facades\Storage;
use Native\Laravel\Dialog;
use Native\Laravel\Facades\Window;
use OpenSketch\SketchBook\Domain\Command\CreateNewSketchBookCommand;
use OpenSketch\SketchBook\Domain\Handler\CreateNewSketchBook;
use OpenSketch\SketchBook\Domain\SketchBookRepository;
use Ramsey\Uuid\Uuid;

class StoreDocument
{
public function __construct()
{
public function __construct(
private CreateNewSketchBook $createNewSketchBook
) {
}

public function handle(DocumentSaved $event): void
{
$storagePath = Storage::disk('user_documents')->path('OpenSketch');
$path = Dialog::new()
->title('Save Sketch Book')
->asSheet()
->asSheet('welcome')
->defaultPath($storagePath)
->save();

if (null === $path) {
return;
}

$id = Uuid::uuid4();
$routeParams = [
'id' => $id->toString(),
];
$command = CreateNewSketchBookCommand::withIdAndPath(
Uuid::uuid4()->toString(),
$path
);

Storage::put($path . '.json', json_encode($routeParams, JSON_THROW_ON_ERROR));
$this->createNewSketchBook->handle($command);

/** @var \Native\Laravel\Windows\WindowManager $window */
$window = Window::getFacadeRoot();

Window::open('welcome');
Window::close('sketch-book');
Window::open('sketch-book')
->hideMenu(false)
->route('sketch-book', $routeParams)
->route('sketch-book', [
'id' => $command->sketchBookId,
])
;
$window->maximize('sketch-book');

Expand Down
19 changes: 19 additions & 0 deletions app/Models/SketchBookReference.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class SketchBookReference extends Model
{
use HasFactory, HasUuids;
public $timestamps = false;
protected $table = 'sketch_books_reference';
protected $primaryKey = 'id';
protected $fillable = [
'id',
'storage_path'
];
}
18 changes: 5 additions & 13 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

use Illuminate\Contracts\Foundation\Application;
use Illuminate\Support\ServiceProvider;
use OpenSketch\SketchBook\Domain\Handler\SaveSketchBook;
use OpenSketch\SketchBook\Domain\SketchBookRepository;
use OpenSketch\SketchBook\Infrastructure\Http\GetSketchBook;
use OpenSketch\SketchBook\Infrastructure\Http\PutSketchBook;
use OpenSketch\SketchBook\Infrastructure\Persistence\EloquentSketchBookRepository;
use OpenSketch\SketchBook\Infrastructure\Persistence\FileSystemSketchBookRepository;

class AppServiceProvider extends ServiceProvider
{
Expand All @@ -18,21 +20,11 @@ public function register(): void
{
$this->app->bind(
SketchBookRepository::class,
EloquentSketchBookRepository::class
FileSystemSketchBookRepository::class
);

$this->app->bind(
PutSketchBook::class,
fn(Application $app) => new PutSketchBook(
$this->app->make(SketchBookRepository::class)
)
);
$this->app->bind(
GetSketchBook::class,
fn(Application $app) => new GetSketchBook(
$this->app->make(SketchBookRepository::class)
)
);
$this->app->bind(PutSketchBook::class);
$this->app->bind(GetSketchBook::class);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"laravel/sail": "^1.18",
"mockery/mockery": "^1.4.4",
"nunomaduro/collision": "^7.0",
"phpunit/phpunit": "^10.1",
"phpunit/phpunit": "^10.4",
"spatie/laravel-ignition": "^2.0"
},
"autoload": {
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion config/nativephp.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
'NATIVEPHP_APPLE_ID',
'NATIVEPHP_APPLE_ID_PASS',
'NATIVEPHP_APPLE_TEAM_ID',
],
'GITHUB_*',
],

/**
* The NativePHP updater configuration.
Expand All @@ -71,6 +72,16 @@
'default' => env('NATIVEPHP_UPDATER_PROVIDER', 'spaces'),

'providers' => [
'github' => [
'driver' => 'github',
'repo' => env('GITHUB_REPO'),
'owner' => env('GITHUB_OWNER'),
'token' => env('GITHUB_TOKEN'),
'vPrefixedTagName' => env('GITHUB_V_PREFIXED_TAG_NAME', true),
'private' => env('GITHUB_PRIVATE', false),
'channel' => env('GITHUB_CHANNEL', 'latest'),
'releaseType' => env('GITHUB_RELEASE_TYPE', 'draft'),
],
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('sketch_books_reference', function (Blueprint $table) {
$table->uuid('id');
$table->string('storage_path');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('sketch_books_reference');
}
};
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<env name="BCRYPT_ROUNDS" value="4"/>
<env name="CACHE_DRIVER" value="array"/>
<!-- <env name="DB_CONNECTION" value="sqlite"/> -->
<!-- <env name="DB_DATABASE" value=":memory:"/> -->
<env name="DB_DATABASE" value=":memory:"/>
<env name="MAIL_MAILER" value="array"/>
<env name="QUEUE_CONNECTION" value="sync"/>
<env name="SESSION_DRIVER" value="array"/>
Expand Down
19 changes: 19 additions & 0 deletions src/SketchBook/Domain/Command/CreateNewSketchBookCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace OpenSketch\SketchBook\Domain\Command;

final readonly class CreateNewSketchBookCommand
{
private function __construct(
public string $sketchBookId,
public string $storagePath
) {
}

public static function withIdAndPath(string $sketchBookId, string $storagePath): self
{
return new self($sketchBookId, $storagePath);
}
}
19 changes: 19 additions & 0 deletions src/SketchBook/Domain/Command/ResetSketchBookLocationCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace OpenSketch\SketchBook\Domain\Command;

final readonly class ResetSketchBookLocationCommand
{
private function __construct(
public string $sketchBookId,
public string $storagePath
) {
}

public static function withIdAndPath(string $sketchBookId, string $storagePath): self
{
return new self($sketchBookId, $storagePath);
}
}
Loading

0 comments on commit 7c7a080

Please sign in to comment.