| 1 | <script lang="ts" context="module"> |
| 2 | export const _openPopup = writable(false); |
| 3 | const popupProps = writable({}); |
| 4 | const popup = writable(null); |
| 5 | export const fullscreen = writable(false); |
| 6 | |
| 7 | type Button = { |
| 8 | name: string; |
| 9 | action; |
| 10 | disabled?: boolean; |
| 11 | style?: "primary" | "secondary" | "accent" | "danger"; |
| 12 | type?: "button" | "submit" | "reset"; |
| 13 | cancel?: boolean; |
| 14 | }; |
| 15 | |
| 16 | export function openInputModal( |
| 17 | title: string, |
| 18 | description: string, |
| 19 | buttons: Button[], |
| 20 | options = undefined, |
| 21 | path = "" |
| 22 | ) { |
| 23 | popup.set(InputModal); |
| 24 | popupProps.set({ |
| 25 | title: title, |
| 26 | description: description, |
| 27 | buttons: buttons, |
| 28 | options: options, |
| 29 | open: true, |
| 30 | path: path, |
| 31 | }); |
| 32 | _openPopup.set(true); |
| 33 | } |
| 34 | export function openRenameModal( |
| 35 | title: string, |
| 36 | description: string, |
| 37 | buttons: Button[], |
| 38 | path: string |
| 39 | ) { |
| 40 | popup.set(RenameModal); |
| 41 | popupProps.set({ |
| 42 | title: title, |
| 43 | description: description, |
| 44 | buttons: buttons, |
| 45 | open: true, |
| 46 | path: path, |
| 47 | }); |
| 48 | _openPopup.set(true); |
| 49 | } |
| 50 | </script> |
| 51 | |
| 52 | <script lang="ts"> |
| 53 | import Header from "./lib/Header.svelte"; |
| 54 | import Sidebar, { showsidebarview, tool } from "./lib/Sidebar.svelte"; |
| 55 | import { Pane, Splitpanes } from "svelte-splitpanes"; |
| 56 | import SidebarView from "./lib/SidebarView.svelte"; |
| 57 | import Statusbar, { |
| 58 | showBottomPanel, |
| 59 | editortool, |
| 60 | } from "./lib/Statusbar.svelte"; |
| 61 | import EditorTabList, { |
| 62 | hidden, |
| 63 | updateTablistWidth, |
| 64 | } from "./lib/EditorTabList.svelte"; |
| 65 | import { onMount } from "svelte"; |
| 66 | import { appWindow } from "@tauri-apps/api/window"; |
| 67 | import { writable } from "svelte/store"; |
| 68 | import InputModal from "./lib/Modals/InputModal.svelte"; |
| 69 | import RenameModal from "./lib/Modals/RenameModal.svelte"; |
| 70 | import { loadDefaultSettings } from "./config/config"; |
| 71 | import { error } from "tauri-plugin-log-api"; |
| 72 | import ToolView from "./lib/ToolView.svelte"; |
| 73 | import { getExtensions } from "./config/extensionhandler"; |
| 74 | import { fitTerminal } from "./lib/Terminal.svelte"; |
| 75 | import { loadDir } from "./lib/File"; |
| 76 | import NotificationToasts from "./lib/Notifications/NotificationToasts.svelte"; |
| 77 | import { |
| 78 | NotifType, |
| 79 | addNotification, |
| 80 | toasts, |
| 81 | } from "./lib/Notifications/notifications"; |
| 82 | import { shell } from "@tauri-apps/api"; |
| 83 | import { addTab } from "./lib/EditorTabList.svelte"; |
| 84 | import Welcome from "./lib/Welcome.svelte"; |
| 85 | |
| 86 | let resolution = writable(0); |
| 87 | |
| 88 | let minPanelSize = 10; |
| 89 | let panelSize = 15; |
| 90 | let bottomPanelSize = 20; |
| 91 | |
| 92 | onMount(async () => { |
| 93 | await getExtensions(); |
| 94 | await loadDefaultSettings(); |
| 95 | let dir = localStorage.getItem("lastDir"); |
| 96 | if (dir) { |
| 97 | loadDir(dir); |
| 98 | } else { |
| 99 | addTab( |
| 100 | "Welcome", |
| 101 | "Welcome", |
| 102 | new Welcome({ target: document.getElementById("tabview") }) |
| 103 | ); |
| 104 | } |
| 105 | |
| 106 | let size = await appWindow.innerSize(); |
| 107 | resolution.set(size.width); |
| 108 | updateMinPanelSize(); |
| 109 | |
| 110 | addNotification( |
| 111 | NotifType.Message, |
| 112 | "Welcome to Svara", |
| 113 | [ |
| 114 | { |
| 115 | label: "Learn More", |
| 116 | action: () => { |
| 117 | shell.open("https://github.com/setoelkahfi/svara"); |
| 118 | }, |
| 119 | }, |
| 120 | { |
| 121 | label: "Create Issue", |
| 122 | action: () => { |
| 123 | shell.open( |
| 124 | "https://github.com/setoelkahfi/svara/issues/new/choose" |
| 125 | ); |
| 126 | }, |
| 127 | }, |
| 128 | ], |
| 129 | " is in alpha. If there are any bugs present or features you want to add, create an issue below." |
| 130 | ); |
| 131 | |
| 132 | appWindow.onResized((e) => { |
| 133 | resolution.set(e.payload.width); |
| 134 | updateMinPanelSize(); |
| 135 | }); |
| 136 | |
| 137 | window.onunhandledrejection = (e) => { |
| 138 | error(e.reason); |
| 139 | }; |
| 140 | }); |
| 141 | |
| 142 | function updatePanelSize(e) { |
| 143 | if ($showsidebarview) { |
| 144 | panelSize = e.detail[0].size; |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | async function updateMinPanelSize() { |
| 149 | fitTerminal(); |
| 150 | updateTablistWidth(); |
| 151 | if (!(await appWindow.isFocused())) { |
| 152 | return; |
| 153 | } |
| 154 | // TODO: make this better |
| 155 | if ($resolution <= 700) { |
| 156 | minPanelSize = 30; |
| 157 | } else if ($resolution <= 1040) { |
| 158 | minPanelSize = 20; |
| 159 | } else if ($resolution <= 1120) { |
| 160 | minPanelSize = 17; |
| 161 | } else if ($resolution <= 1300) { |
| 162 | minPanelSize = 14; |
| 163 | } else if ($resolution > 1300) { |
| 164 | minPanelSize = 10; |
| 165 | } |
| 166 | |
| 167 | if (panelSize < minPanelSize) { |
| 168 | panelSize = minPanelSize; |
| 169 | } |
| 170 | } |
| 171 | </script> |
| 172 | |
| 173 | <svelte:window on:contextmenu|preventDefault /> |
| 174 | |
| 175 | <div id="_" inert={$_openPopup}> |
| 176 | {#if !$fullscreen} |
| 177 | <Header /> |
| 178 | {/if} |
| 179 | <div id="main" class:fullscreen={$fullscreen}> |
| 180 | <Sidebar /> |
| 181 | <Splitpanes |
| 182 | on:resized={updatePanelSize} |
| 183 | on:resize={updateMinPanelSize} |
| 184 | theme="editor-panes" |
| 185 | > |
| 186 | {#if $showsidebarview} |
| 187 | <Pane |
| 188 | bind:size={panelSize} |
| 189 | bind:minSize={minPanelSize} |
| 190 | maxSize={60} |
| 191 | > |
| 192 | <SidebarView content={$tool.content}></SidebarView> |
| 193 | </Pane> |
| 194 | {/if} |
| 195 | <Pane> |
| 196 | <div class="__"> |
| 197 | <Splitpanes |
| 198 | horizontal |
| 199 | theme="editor-panes" |
| 200 | on:resize={fitTerminal} |
| 201 | class={!$showBottomPanel ? "hidden" : ""} |
| 202 | > |
| 203 | <Pane |
| 204 | size={$showBottomPanel |
| 205 | ? 100 - bottomPanelSize |
| 206 | : 100} |
| 207 | > |
| 208 | <div id="container"> |
| 209 | <EditorTabList /> |
| 210 | <div id="tabview" class:hidden={$hidden}></div> |
| 211 | </div> |
| 212 | </Pane> |
| 213 | {#if $editortool} |
| 214 | <Pane |
| 215 | bind:size={bottomPanelSize} |
| 216 | maxSize={90} |
| 217 | minSize={10} |
| 218 | class="view-bottom-pane" |
| 219 | > |
| 220 | <ToolView |
| 221 | name={$editortool.name} |
| 222 | options={$editortool.options} |
| 223 | buttons={$editortool.buttons} |
| 224 | ></ToolView> |
| 225 | </Pane> |
| 226 | {/if} |
| 227 | </Splitpanes> |
| 228 | </div> |
| 229 | </Pane> |
| 230 | </Splitpanes> |
| 231 | </div> |
| 232 | <Statusbar /> |
| 233 | {#if $toasts.length != 0} |
| 234 | <NotificationToasts /> |
| 235 | {/if} |
| 236 | </div> |
| 237 | |
| 238 | {#if $_openPopup} |
| 239 | <svelte:component this={$popup} {...$popupProps}></svelte:component> |
| 240 | {/if} |
| 241 | |
| 242 | <style lang="scss"> |
| 243 | .__ { |
| 244 | height: 100%; |
| 245 | overflow: hidden; |
| 246 | :global(.hidden) { |
| 247 | :global(.splitpanes__splitter), |
| 248 | :global(.view-bottom-pane) { |
| 249 | display: none; |
| 250 | } |
| 251 | } |
| 252 | } |
| 253 | #main { |
| 254 | display: flex; |
| 255 | } |
| 256 | #container { |
| 257 | height: 100%; |
| 258 | overflow: hidden; |
| 259 | background-image: url("/assets/images/Icon.png"); |
| 260 | background-repeat: no-repeat; |
| 261 | background-position: center; |
| 262 | } |
| 263 | #tabview { |
| 264 | width: -webkit-fill-available; |
| 265 | z-index: 1; |
| 266 | } |
| 267 | .hidden { |
| 268 | visibility: hidden; |
| 269 | } |
| 270 | :global(.view-bottom-pane) { |
| 271 | z-index: 1; |
| 272 | } |
| 273 | </style> |