Fix plugin-related issues

This commit is contained in:
Pig Fang 2019-03-21 19:45:52 +08:00
parent 3a4844a5dd
commit 0f20e99ac1
4 changed files with 17 additions and 18 deletions

View File

@ -35,6 +35,7 @@ class AppServiceProvider extends ServiceProvider
'base_url' => url('/'),
'site_name' => option_localized('site_name'),
'route' => request()->path(),
'extra' => [],
]);
$event->addContent('<script>var blessing = '.json_encode($blessing).';</script>');

View File

@ -71,12 +71,12 @@ class Hook
// We will determine current locale in the event callback,
// otherwise the locale is not properly detected.
$basepath = plugin($id)->getPath().'/';
$basepath = config('plugins.url') ?: url('plugins').'/'.$id.'/';
$relative = 'lang/'.config('app.locale').'/locale.js';
if (file_exists($basepath.$relative)) {
$event->addContent('<script src="'.plugin_assets($id, $relative).'"></script>');
}
$event->addContent(
'<script src="'.$basepath.$relative.'"></script>'
);
return;
}

View File

@ -89,14 +89,6 @@ class Plugin implements Arrayable, ArrayAccess
return isset($this->{$name}) || $this->packageInfoAttribute(snake_case($name, '-'));
}
/**
* Dot notation getter for composer.json attributes.
*
* @see https://laravel.com/docs/5.1/helpers#arrays
*
* @param $name
* @return mixed
*/
public function packageInfoAttribute($name)
{
return Arr::get($this->packageInfo, $name);
@ -104,9 +96,9 @@ class Plugin implements Arrayable, ArrayAccess
public function assets($relativeUri)
{
$baseUrl = config('plugins.url') ?: url('public/plugins');
$baseUrl = config('plugins.url') ?: url('plugins');
return "$baseUrl/{$this->getDirname()}/$relativeUri";
return "$baseUrl/{$this->getDirname()}/assets/$relativeUri";
}
/**

View File

@ -99,7 +99,7 @@ class PluginManager
// Instantiates an Plugin object using the package path and package.json file.
$plugin = new Plugin($this->getPluginsDir().DIRECTORY_SEPARATOR.$dirname, $package);
// Per default all plugins are installed if they are registered in composer.
// Each default all plugins are installed if they are registered in composer.
$plugin->setDirname($dirname);
$plugin->setInstalled(true);
$plugin->setNameSpace(Arr::get($package, 'namespace'));
@ -164,6 +164,8 @@ class PluginManager
$plugin->setEnabled(true);
$this->copyPluginAssets($plugin);
$this->dispatcher->dispatch(new Events\PluginWasEnabled($plugin));
}
}
@ -414,12 +416,16 @@ class PluginManager
*/
public function copyPluginAssets($plugin)
{
$dir = public_path('plugins/'.$plugin->name.'/assets');
$dir = public_path('plugins/'.$plugin->name);
Storage::deleteDirectory($dir);
return $this->filesystem->copyDirectory(
$this->filesystem->copyDirectory(
$this->getPluginsDir().DIRECTORY_SEPARATOR.$plugin->name.DIRECTORY_SEPARATOR.'assets',
$dir
$dir.'/assets'
);
$this->filesystem->copyDirectory(
$this->getPluginsDir().DIRECTORY_SEPARATOR.$plugin->name.DIRECTORY_SEPARATOR.'lang',
$dir.'/lang'
);
}