Skip to content

Commit

Permalink
added new info location
Browse files Browse the repository at this point in the history
  • Loading branch information
Severino committed Jul 24, 2024
1 parent 690fe4c commit 31c3742
Show file tree
Hide file tree
Showing 6 changed files with 207 additions and 135 deletions.
81 changes: 53 additions & 28 deletions app/PluginResources/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ public function __construct($attributes = []) {
$this->presets = [
RolePresetPlugin::class,
];

$this->permissions = [

];
}

public static function isInstalled($name) {
Expand All @@ -65,10 +61,26 @@ public function publicName($withPath = true) {
}

public static function getInfo($path, $isString = false) {
$xmlString = '';
if(!$isString) {
$infoPath = Str::finish($path, '/') . 'App/info.xml';
if(!File::isFile($infoPath)) return false;
$xmlString = file_get_contents($infoPath);

$manifestLocations = [
'App/info.xml', // Legacy location of the 'info.xml' file
'manifest.xml', // This is the potential new location of the 'info.xml' file
];

while(count($manifestLocations) > 0){
$location = array_shift($manifestLocations);
$infoPath = Str::finish($path, '/') . $location;
if(File::isFile($infoPath)){
$xmlString = file_get_contents($infoPath);
break;
}
}

if($xmlString == ''){
return false;
}
} else {
$xmlString = $path;
}
Expand Down Expand Up @@ -120,6 +132,7 @@ public function getChangelog($since = null) {
public static function updateOrCreateFromInfo(array $info) : Plugin {
$id = $info['name'];
$plugin = self::where('name', $id)->first();

// discovered new Plugin, add it to DB
if(!isset($plugin)) {
$plugin = new self();
Expand Down Expand Up @@ -199,30 +212,29 @@ public function updateUpdateState($fromInfoVersion) {

public function handleAdd(){
Migration::use($this)->migrate();

$this->addPermissions();
$this->installPresets();
$this->installed_at = Carbon::now();
$this->save();
}

public function handleInstallation() {
$this->publishScript();
$this->installPresets();
$this->installed_at = Carbon::now();
$this->save();
}

//TODO:: Reimplement
// public function handleUpdate() {
// $oldVersion = $this->version;
// // TODO is it really the same as install?
// $this->handleInstallation();
//TODO:: Rework
public function handleUpdate() {
$oldVersion = $this->version;
// TODO is it really the same as install?
$this->handleInstallation();


// $info = self::getInfo(base_path("app/Plugins/$this->name"));
// $this->update_available = null;
// $this->version = $info['version'];
// $this->save();
// return $oldVersion;
// }
$info = self::getInfo(base_path("app/Plugins/$this->name"));
$this->update_available = null;
$this->version = $info['version'];
$this->save();
return $oldVersion;
}

public function handleUninstall() {
$this->removeScript();
Expand Down Expand Up @@ -261,17 +273,30 @@ public function getPermissionGroups() {
public function getClassPath(array $parts){
return "App\\Plugins\\$this->name\\" . implode('\\', $parts);
}

public function getProblemsAttribute(){
$problems = [];

if(!$this->hasScript()){
$problems[] = "script_missing";
}

return $problems;
}


private function hasScript(){
return Storage::exists($this->publicName());
}

private function publishScript() {
$name = $this->name;
$scriptPath = base_path("app/Plugins/$name/js/script.js");
if(file_exists($scriptPath)) {
$filehandle = fopen($scriptPath, 'r');
Storage::put(
$this->publicName(),
$filehandle,
);
fclose($filehandle);
$filepath = Storage::path($this->publicName());
File::link($scriptPath, $filepath);
} else {
throw new \Exception("Script file not found at '$scriptPath'");
}
}

Expand Down
2 changes: 2 additions & 0 deletions resources/js/bootstrap/font.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
} from '@fortawesome/free-brands-svg-icons';
import {
faCircle as faCircleReg,
faCircleUp,
faClipboard as faClipboardReg,
faKeyboard,
faLaugh,
Expand Down Expand Up @@ -373,6 +374,7 @@ library.add(
faCircleNotch,
faCirclePlus,
faCircleArrowUp,
faCircleUp,
faO,
faOutdent,
faPalette,
Expand Down
129 changes: 22 additions & 107 deletions resources/js/components/Plugins.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,94 +28,21 @@
:key="plugin.name"
class="col"
>
<div class="card h-100">
<div class="card-body d-flex flex-column">
<header class="d-flex flex-column ">
<div class="d-flex flex-row justify-content-between align-items-center">
<h5 class="card-title mb-1 fw-bold">
{{ plugin.metadata.title }}
</h5>

<span>
v{{ plugin.version }}
</span>
</div>
<div class="d-flex flex-row gap-2">
<span
v-for="(author, i) in plugin.metadata.authors"
:key="i"
class="text-muted"
>
{{ author }}
</span>
</div>
</header>

<md-viewer :source="plugin.metadata.description" />

<!-- <div class="">
<button
v-if="isInstalled(plugin)"
type="button"
class="btn btn-sm btn-outline-warning"
@click="uninstall(plugin)"
>
<i class="fas fa-fw fa-times" />
{{ t('main.plugins.deactivate') }}
</button>
<button
v-else
type="button"
class="btn btn-sm btn-outline-success"
@click="install(plugin)"
>
<i class="fas fa-fw fa-plus" />
{{ t('main.plugins.activate') }}
</button>
<div
v-if="updateAvailable(plugin)"
class="btn-group"
role="group"
>
<button
type="button"
class="btn btn-sm btn-outline-primary ms-2"
@click="update(plugin)"
>
<i class="fas fa-fw fa-download" />
<span v-html="t('main.plugins.update_to', { version: plugin.update_available })" />
</button>
<button
type="button"
class="btn btn-sm btn-outline-primary"
:title="t('main.plugins.changelog_info')"
@click="showChangelog(plugin)"
>
<i class="fas fa-fw fa-file-pen" />
</button>
</div>
<button
type="button"
class="btn btn-sm btn-outline-danger ms-2"
@click="remove(plugin)"
>
<i class="fas fa-fw fa-trash" />
{{ t('main.plugins.remove') }}
</button>
</div>
</div>
</div>
</div>
<alert
v-if="(!state.sortedPlugins || state.sortedPlugins.length == 0)"
:message="t('main.plugins.not_found')"
:type="'info'"
:noicon="false"
/>
</div>-->
</div>
</div>
<PluginCard
:plugin="plugin"
@install="install"
@uninstall="uninstall"
@update="update"
@remove="remove"
@fix="fix"
/>
</div>
<alert
v-if="(!state.sortedPlugins || state.sortedPlugins.length == 0)"
:message="t('main.plugins.not_found')"
:type="'info'"
:noicon="false"
/>
</div>
</div>
</template>
Expand All @@ -126,10 +53,10 @@
reactive,
} from 'vue';
import {useI18n} from 'vue-i18n';
import { useI18n } from 'vue-i18n';
import store from '@/bootstrap/store.js';
import {useToast} from '@/plugins/toast.js';
import { useToast } from '@/plugins/toast.js';
import {
uploadPlugin,
Expand All @@ -143,30 +70,21 @@
can,
} from '@/helpers/helpers.js';
import {
showChangelogModal,
} from '@/helpers/modal.js';
import {
appendScript,
removeScript,
} from '@/helpers/plugins.js';
import PluginCard from './plugins/PluginCard.vue';
export default {
components: {
PluginCard,
},
setup(props) {
const {t} = useI18n();
const { t } = useI18n();
const toast = useToast();
// FUNCTIONS
const isInstalled = plugin => {
return !!plugin.installed_at;
};
const updateAvailable = plugin => {
return !!plugin.update_available;
};
const showChangelog = plugin => {
showChangelogModal(plugin);
};
const install = plugin => {
installPlugin(plugin.id).then(data => {
appendScript(data.install_location);
Expand Down Expand Up @@ -227,9 +145,6 @@
// HELPERS
can,
// LOCAL
isInstalled,
updateAvailable,
showChangelog,
install,
uninstall,
update,
Expand Down
Loading

0 comments on commit 31c3742

Please sign in to comment.