5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-19 02:19:31 +08:00

[v2] Remove common.js

This commit is contained in:
Lea Anthony 2021-05-31 20:08:11 +10:00
parent d2e4a0b0d2
commit 4738a0e0a8
3 changed files with 60 additions and 66 deletions

View File

@ -13,56 +13,53 @@ The lightweight framework for web-like apps
* Initialises platform specific code * Initialises platform specific code
*/ */
// import * as common from './common';
const common = require('./common');
export const System = { export const System = {
...common, AppType: 'desktop',
Platform: () => "darwin", Platform: () => 'darwin',
} };
export function SendMessage(message) { export function SendMessage(message) {
window.webkit.messageHandlers.external.postMessage(message); window.webkit.messageHandlers.external.postMessage(message);
} }
export function Init() { export function Init() {
// Setup drag handler // Setup drag handler
// Based on code from: https://github.com/patr0nus/DeskGap // Based on code from: https://github.com/patr0nus/DeskGap
window.addEventListener('mousedown', function (e) { window.addEventListener('mousedown', function (e) {
let currentElement = e.target; let currentElement = e.target;
while (currentElement != null) { while (currentElement != null) {
if (currentElement.hasAttribute('data-wails-no-drag')) { if (currentElement.hasAttribute('data-wails-no-drag')) {
break; break;
} else if (currentElement.hasAttribute('data-wails-drag')) { } else if (currentElement.hasAttribute('data-wails-drag')) {
window.webkit.messageHandlers.windowDrag.postMessage(null); window.webkit.messageHandlers.windowDrag.postMessage(null);
break; break;
} }
currentElement = currentElement.parentElement; currentElement = currentElement.parentElement;
} }
}); });
// Setup context menu hook // Setup context menu hook
window.addEventListener('contextmenu', function (e) { window.addEventListener('contextmenu', function (e) {
let currentElement = e.target; let currentElement = e.target;
let contextMenuId; let contextMenuId;
while (currentElement != null) { while (currentElement != null) {
contextMenuId = currentElement.dataset['wails-context-menu-id']; contextMenuId = currentElement.dataset['wails-context-menu-id'];
if (contextMenuId != null) { if (contextMenuId != null) {
break; break;
} }
currentElement = currentElement.parentElement; currentElement = currentElement.parentElement;
} }
if (contextMenuId != null || window.disableWailsDefaultContextMenu) { if (contextMenuId != null || window.disableWailsDefaultContextMenu) {
e.preventDefault(); e.preventDefault();
} }
if( contextMenuId != null ) { if( contextMenuId != null ) {
let contextData = currentElement.dataset['wails-context-menu-data']; let contextData = currentElement.dataset['wails-context-menu-data'];
let message = { let message = {
id: contextMenuId, id: contextMenuId,
data: contextData || "", data: contextData || '',
}; };
window.webkit.messageHandlers.contextMenu.postMessage(JSON.stringify(message)); window.webkit.messageHandlers.contextMenu.postMessage(JSON.stringify(message));
} }
}); });
} }

View File

@ -14,28 +14,28 @@ The lightweight framework for web-like apps
*/ */
export const System = { export const System = {
...common, AppType: 'desktop',
Platform: () => "linux", Platform: () => 'linux',
} };
export function SendMessage(message) { export function SendMessage(message) {
window.webkit.messageHandlers.external.postMessage(message); window.webkit.messageHandlers.external.postMessage(message);
} }
export function Init() { export function Init() {
// Setup drag handler // Setup drag handler
// Based on code from: https://github.com/patr0nus/DeskGap // Based on code from: https://github.com/patr0nus/DeskGap
window.addEventListener('mousedown', function (e) { window.addEventListener('mousedown', function (e) {
let currentElement = e.target; let currentElement = e.target;
while (currentElement != null) { while (currentElement != null) {
if (currentElement.hasAttribute('data-wails-no-drag')) { if (currentElement.hasAttribute('data-wails-no-drag')) {
break; break;
} else if (currentElement.hasAttribute('data-wails-drag')) { } else if (currentElement.hasAttribute('data-wails-drag')) {
window.webkit.messageHandlers.windowDrag.postMessage(null); window.webkit.messageHandlers.windowDrag.postMessage(null);
break; break;
} }
currentElement = currentElement.parentElement; currentElement = currentElement.parentElement;
} }
}); });
} }

View File

@ -13,11 +13,8 @@ The lightweight framework for web-like apps
* Initialises platform specific code * Initialises platform specific code
*/ */
// import * as common from './common';
const common = require('./common');
export const System = { export const System = {
...common, AppType: 'desktop',
Platform: () => 'windows', Platform: () => 'windows',
}; };