Skip to content

script.js API Reference — OS

Every OS plugin registers itself through script.js. The file assigns a function to plugins["name"]. Inside that function, this exposes all registration methods.

Quick Overview

js
plugins["my-plugin"] = function () {
    this.setFrame({ title: 'Music Player', icon: { type: 'icon', name: 'pi pi-music' } })

    this.setToolbar([
        { icon: 'pi pi-home', to: '/' },
        { icon: 'pi pi-cog', to: '/setting' },
    ])

    this.setMenu([
        { label: 'Tracks',   icon: 'pi pi-music', to: '/' },
        { label: 'Settings', icon: 'pi pi-cog',   to: '/setting' },
    ])

    this.addLanguage('en', 'music', { label: 'Music Player' })

    this.addPage({ name: '/[my-plugin]index.vue',   path: '',         file: ['index.vue']   })
    this.addPage({ name: '/[my-plugin]setting.vue', path: '/setting', file: ['setting.vue'] })
}

Methods

setFrame(options)

Configures the Electron window frame — the title shown in the OS window bar and the window icon.

Parameters:

FieldTypeDescription
titlestringWindow title displayed in the OS taskbar and title bar
iconobjectWindow icon definition
icon.typestringIcon type: 'icon' for PrimeIcons CSS class, 'image' for an image asset path
icon.namestringPrimeIcons class (e.g. 'pi pi-music') or image path (e.g. 'images/logo.jpg')

Example:

js
// Using a PrimeIcon
this.setFrame({
  title: 'Music Player',
  icon: { type: 'icon', name: 'pi pi-music' }
})

// Using an image
this.setFrame({
  title: 'My App',
  icon: { type: 'image', name: 'images/logo.jpg' }
})

setToolbar(items)

Defines the toolbar navigation buttons shown at the top of the plugin window. Each item links to a route within the plugin.

Parameters:

items — array of toolbar button objects:

FieldTypeDescription
iconstringPrimeIcons class for the button icon
tostringRoot-relative route path (e.g. '/', '/setting')

Example:

js
this.setToolbar([
  { icon: 'pi pi-home', to: '/' },
  { icon: 'pi pi-list', to: '/tracks' },
  { icon: 'pi pi-cog', to: '/setting' },
])

Routes in to must match routes registered with addPage().


setMenu(items)

Defines the sidebar or navigation menu items shown inside the plugin window. Complements setToolbar() for plugins that need a richer navigation structure.

Parameters:

items — array of menu item objects:

FieldTypeDescription
labelstringDisplay text for the menu item
iconstringPrimeIcons class for the item icon
tostringRoot-relative route path

Example:

js
this.setMenu([
  { label: 'Tracks',   icon: 'pi pi-music', to: '/' },
  { label: 'Playlists', icon: 'pi pi-list',  to: '/playlists' },
  { label: 'Settings', icon: 'pi pi-cog',   to: '/setting' },
])

addPage(options, to)

Registers a Vue page component as a route in the plugin window.

Parameters:

ParameterTypeDefaultDescription
optionsobjectPage definition
options.namestringInternal route name
options.pathstringRoot-relative route path
options.filestring[]Array containing the .vue component filename, e.g. ["index.vue"]
tostring'app'Mount target — always 'app' for OS plugins

Path formatting:

Unlike SA where paths are relative, OS paths are root-relative. The main view uses an empty string "" for the root route:

Path valueResulting routeUsage
""/Main / home view
"/setting"/settingSettings page
"/detail/:id"/detail/:idDetail page with param

Example:

js
this.addPage({ name: '/[my-plugin]index.vue',    path: '',           file: ['index.vue']   })
this.addPage({ name: '/[my-plugin]setting.vue',  path: '/setting',   file: ['setting.vue'] })
this.addPage({ name: '/[my-plugin]detail.vue',   path: '/detail/:id', file: ['detail.vue']  })

addLanguage(locale, namespace, translations)

Registers translation strings for the plugin.

Parameters:

ParameterTypeDescription
localestringLanguage code: 'en', 'ar', etc.
namespacestringUnique key namespace for the plugin
translationsobjectKey/value translation pairs

Example:

js
this.addLanguage('en', 'music', {
  label:    'Music Player',
  tracks:   'Tracks',
  settings: 'Settings',
})

this.addLanguage('ar', 'music', {
  label:    'مشغل الموسيقى',
  tracks:   'المقاطع',
  settings: 'الإعدادات',
})

In Vue templates, access with $t('music.label').

Method Summary

MethodPurpose
setFrame(options)Set window title and icon
setToolbar(items)Add toolbar navigation buttons
setMenu(items)Define sidebar/navigation menu items
addPage(options, to)Register a Vue route/page
addLanguage(locale, ns, translations)Register i18n strings

Comparison: OS vs SA vs EA

FeatureOSSAEA
Window typeOwn Electron windowEmbedded in SA shellEmbedded in EA shell
Route pathsRoot-relative ("", "/setting")Relative ("setting")Relative
Main view fileindex.vueindex.vueindex.vue
Frame/toolbar configsetFrame + setToolbar + setMenu
Backend (main.js)
WidgetsaddWidget
TasksaddTask
RolesaddRole
Navigation extensionaddToaddTo
Native file dialogsipcRenderer
Local databaseapi.database()api.database()