Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.4 Major: Extension Support + Project Refactoring #648

Merged
merged 11 commits into from
Nov 16, 2022

Conversation

bummoblizard
Copy link
Member

Extension is a modular approach to expand Code App. The below code adds remote execution feature using Judge0 in a self-contained way, without affecting the core codebase:

class RemoteExecutionExtension: CodeAppExtension {
    let storage = CloudCodeExecutionManager()
    
    override func onInitialize(
        app: MainApp,
        contribution: CodeAppExtension.Contribution
    ) {
        let panel = Panel(
            labelId: EXTENSION_ID,
            mainView: AnyView(PanelRemoteExecutionMainView().environmentObject(storage)),
            toolBarView: AnyView(PanelRemoteExecutionToolbarView().environmentObject(storage))
        )
        contribution.panel.registerPanel(panel: panel)

        let toolbarItem = ToolbarItem(
            extenionID: EXTENSION_ID,
            icon: "play",
            onClick: {
                if self.storage.displayMode == .input {
                    self.storage.displayMode = .output
                }
                guard let editor = app.activeEditor else {
                    return
                }
                guard let url = URL(string: editor.url) else {
                    return
                }
                guard let languageCode = compilerCodeForPath(path: editor.url) else {
                    return
                }
                self.storage.runCode(directoryURL: url, source: editor.content, language: languageCode)
            },
            shortCut: .init("r", modifiers: [.command]),
            shouldFocusPanelOnTap: true
        )
        contribution.toolbarItem.registerItem(item: toolbarItem)
    }
}

@bummoblizard bummoblizard merged commit 5607692 into thebaselab:main Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant